How to rotate coordinate system?

邮差的信 提交于 2019-12-05 09:46:56

See this page: http://www.siggraph.org/education/materials/HyperGraph/modeling/mod_tran/2drota.htm

This is the formula:

x' = x cos f - y sin f

y' = y cos f + x sin f

Remember that sin and cos takes radians, so you have to do like this:

double x,y;
double newX,newY;
double angle;

//Test values:
x=1;
y=1;
angle = 45;

double rad = angle*M_PI/180;

newX = x * cos(rad) - y * sin(rad);
newY = y * cos(rad) + x * sin(rad);

I didn't test this, so there might be typos... ;)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!