如果我围绕原点旋转,我试图找到坐标的新值。
例如,假设我有点 (1,1)。 如果我将坐标轴绕原点旋转 45 度,则变换后的坐标将为 (0,1.414)
有没有办法在 cocos2d 或 objective-c 中有效地做到这一点? 即使是解释数学运算的答案也会有所帮助。
最佳答案
查看此页面: http://www.siggraph.org/education/materials/HyperGraph/modeling/mod_tran/2drota.htm
这是公式:
x' = x cos f - y sin f
y' = y cos f + x sin f
记住 sin 和 cos 需要弧度,所以你必须这样做:
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);
我没有测试这个,所以可能有拼写错误......;)
关于objective-c - 如何旋转坐标系?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9190149/