CGPoint rotation changes the distance from the source

I want to rotate CGPoint (red rectangle) around another CGPoint (blue rectangle), but it changes the distance from the origin (blue rectangle) ... when I give 270 in the corner, it creates a point right above the start, but when I give 90 in as the value of the angle, it goes down the origin, BUT CHANGE THE DISTANCE ALSO is almost three times as much .... I want the distance to be the same and I need to rotate CGPoint around another. Please guide any approach to cgpoints rotation ...

distance = 100;
angle = 270*M_PI/180;    
rotatedPoint.x = initialPoint.x+distance*cos(angle);
rotatedPoint.y = initialPoint.y+distance*sin(angle);
    //rotatedPoint.x = initialPoint.x+tan(angle);

[test setCenter:rotatedPoint];   
[test setBackgroundColor:[UIColor redColor]];

thank

+3
source share
1 answer

CGAffineTransform - , , . , , , .

, :

CGPoint pointToRotate = CGPointMake(30, 30);
float angleInRadians = DEGREES_TO_RADIANS(90);
CGPoint distanceFromOrigin = CGPointMake(0 - pointToRotate.x, 0 - pointToRotate.y);

CGAffineTransform translateToOrigin = CGAffineTransformMakeTranslation(distanceFromOrigin.x, distanceFromOrigin.y);
CGAffineTransform rotationTransform = CGAffineTransformMakeRotation(angleInRadians);
CGAffineTransform translateBackFromOrigin = CGAffineTransformInvert(translateToOrigin);

CGAffineTransform totalTransform = CGAffineTransformConcat(translateToOrigin, rotationTransform);
totalTransform = CGAffineTransformConcat(totalTransform, translateBackFromOrigin);

pointToRotate = CGPointApplyAffineTransform(pointToRotate, totalTransform);

CGAffineTransform, : http://developer.apple.com/library/mac/#documentation/GraphicsImaging/Reference/CGAffineTransform/Reference/reference.html

, , - , !

+2

All Articles