这是我的代码的一部分-应该绕原点旋转点,然后将其翻译回去

    angle = angle * M_PI / 180;
point1.x = (point1.x) * cos(angle) - (point1.y) * sin(angle);
point1.y = (point1.x) * sin(angle) + (point1.y) * cos(angle);

此后,对于要“移动”的点的平移,将根据“旋转”之后的象限是哪个点来说明条件-例如,如果它在1,x + = 2 * x和y + = 2 * y。这里的问题是旋转:例如,对于130度的角度,对于点(100,100),这里是新点x:CGFloat-3.09086e-06,y:CGFloat100的坐标。我究竟做错了什么?

最佳答案

计算point1.y时,请使用已翻译的point1.x。像下面的代码一样修复您的代码:

angle = angle * M_PI / 180;
CGPoint result = CGPointZero;
result.x = (point1.x) * cos(angle) - (point1.y) * sin(angle);
result.y = (point1.x) * sin(angle) + (point1.y) * cos(angle);

并在以后的计算中使用result点。

10-02 06:47