문제

here's a snipped of my code - it is supposed to rotate point around origin and then translate it back

    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);

and after that, for translating point where it should "move", condition will be stated based upon in which quadrant is point after "rotation" - for eg, if it is in 1, x += 2*x and y += 2*y. The problem here is rotation : for example, for angle of 130 degrees, for point (100,100), here are coordinates of new point x:CGFloat-3.09086e-06,y:CGFloat100. What am I doing wrong?

도움이 되었습니까?

해결책

When you calculate point1.y you use already translated point1.x. Fix your code like code below:

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);

And use result point in your future calculations.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top