Re: Transform not quite right
Re: Transform not quite right
- Subject: Re: Transform not quite right
- From: Henry McGilton <email@hidden>
- Date: Sat, 30 Jun 2007 11:56:54 -0700
On Jun 30, 2007, at 11:44 AM, R. Matthew Emerson wrote:
Unfortunately, when I plot the sine wave in the NSVIew, it
starts at (0,0).
So, you can see that there is something fundamentally wrong with
my thinking.
Think of transformations as operations that move the coordinate
axes. This way, the transformations happen in the order you make
them.
If you want to think of transformations as operations that move
your modelled objects, then the transformation declared last
applies first.
float xmin = 0.0;
float xmax = 2*pi;
float ymin = -2.0;
float ymax = 2.0;
NSAffineTransform *xForm = [NSAffineTransform transform];
[xForm translateXBy:-xmin yBy:-ymin];
The above line moves your origin up 2 (screen) points. This isn't
what you want: you're translating in terms of the view's default
units (points).
[xForm scaleXBy:(bRect.size.width/(xmax-xmin)) yBy:
(bRect.size.height/(ymax-ymin))];
This is correct. Now, with this scaling performed, do your
translation:
[xForm translateXBy:-xmin yBy:-ymin];
Also (unless you *really* want to plot curves 'by hand ---
maybe for pedagogical purposes), you might consider letting
the underlying graphics system do the work by defining your
curves in terms of Cubic Bezier curves. Here is a useful
reference:
<http://www.tinaja.com/glib/bezsine.pdf>
Cheers,
........ Henry
===============================+============================
Henry McGilton, Boulevardier | Trilithon Software
Objective-C/Java Composer | Seroia Research
-------------------------------+----------------------------
mailto:email@hidden | http://www.trilithon.com
|
===============================+============================
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden