Re: Problems with Affine Transform
Re: Problems with Affine Transform
- Subject: Re: Problems with Affine Transform
- From: Robert Clair <email@hidden>
- Date: Wed, 3 Dec 2003 12:26:51 -0500
Just a few comments -
On the basis of your posts (and this isn't meant in a rude way) you
would probably benefit from reading the section on transformations in a
textbook on graphics. The way this stuff works is not Cocoa specific. I
don't have a current favorite, but there are a number of texts out
there. As an alternative, some professors (more hyper-organized than I
ever was when I was teaching) have put course notes for for their
classes on graphics on line. These can be found with a bit of creative
Googling.
It can be a bit confusing, but there are two things at work here. Image
that you have a coordinate system drawn on the floor, an object and
that you are viewing the object by looking down on it with a camera.
You could change how the picture comes out by either rotating the
camera or rotating the object. They are different operations. This will
become blindingly clear the moment you have two objects and need to
rotate one relative to the other.
NSAffineTransform* xform = [NSAffineTransform transform];
[xform rotateByDegrees: 20];
[xform concat];
will add (concatenate) a rotation of 20 degrees to the view's current
transformation matrix. This is the moral equivalent of rotating the
camera. Everything in the view will appear rotated - just as if you had
rotated the camera.
NSBezierPath* myPathObject; // previously created path
NSAffineTransform* xform = [NSAffineTransform transform];
[xform rotateByDegrees: -20];
[myPathObject transformUsingAffineTransform: xform];
will rotate the _object_ relative to the coordinate system - the
equivalent of holding the camera still and rotating the object. Only
the objects which have the transform applied to them will appear
rotated.
Note that for a single object centered on the origin, rotating the
camera X degrees clockwise gives the same picture as rotating the
object X degrees counterclockwise.
As a further complication, the transformations obtained by
rotateByDegrees:, etc. give transformations that have the origin as
their fixed point (center of rotation for a rotation).
To rotate about a different point (the center of the object or
whatever) you need a transformation that translates the desired fixed
point to the origin, does the rotation and then translates the fixed
point back to the original location. This may be constructed
like this:
NSAffineTransform* xform = [NSAffineTransform transform];
[xform translateXBy: xDistanceFromOrigin yBy: yDistanceFromOrigin];
[xform rotateByDegrees: angleInDegrees];
[xform translateXBy: -xDistanceFromOrigin yBy: -yDistanceFromOrigin];
xDistanceFromOrigin and yDistanceFromOrigin are the coordinates of your
desired center of rotation.
The same applies to stretching and shearing.
.........Bob
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.