FROM : Gordon Apple
DATE : Tue Nov 06 06:33:50 2007
Although I found references to rotating a Bezier path, searching for
rotating coordinates at a point wasn't fruitful. In my case, I wanted to
rotate a shape in place about its center, including shading and/or content.
I believe the following is about as simple as you can get and can be used to
rotate about any point.
@implementation NSAffineTransform (RTPTransformAdditions)
- (void)rotate:(float)angle atPoint:(NSPoint)point
{
[self rotateByDegrees:angle];
NSAffineTransform* pointXfrm = [NSAffineTransform transform];
[pointXfrm rotateByDegrees:-angle]; // Needed to get original
point in rotated coordinates.
NSPoint oldPoint = [pointXfrm transformPoint:point];
float x = oldPoint.x - point.x;
float y = oldPoint.y - point.y;
[self translateXBy:x yBy:y]; // Done in the rotated coordinates.
}
DATE : Tue Nov 06 06:33:50 2007
Although I found references to rotating a Bezier path, searching for
rotating coordinates at a point wasn't fruitful. In my case, I wanted to
rotate a shape in place about its center, including shading and/or content.
I believe the following is about as simple as you can get and can be used to
rotate about any point.
@implementation NSAffineTransform (RTPTransformAdditions)
- (void)rotate:(float)angle atPoint:(NSPoint)point
{
[self rotateByDegrees:angle];
NSAffineTransform* pointXfrm = [NSAffineTransform transform];
[pointXfrm rotateByDegrees:-angle]; // Needed to get original
point in rotated coordinates.
NSPoint oldPoint = [pointXfrm transformPoint:point];
float x = oldPoint.x - point.x;
float y = oldPoint.y - point.y;
[self translateXBy:x yBy:y]; // Done in the rotated coordinates.
}
| Related mails | Author | Date |
|---|---|---|
| Gordon Apple | Nov 6, 06:33 | |
| Ron Fleckner | Nov 6, 06:47 |






Cocoa mail archive

