On 25/08/2009, at 8:36 AM, Ron Fleckner wrote:

I think you are right to suggest drawing it all in one view. That would probably avoid the problem. The reason I don't is I'm too much of a maths dolt to be able to work out the point co-ordinates for each of the hand positions.

Hi Ron,

Others have addressed different ways to handle this using NSAffineTransform, which is a good idea.

But the maths isn't hard, it's just a polar to Cartesian conversion:

endPoint.x = centrePoint.x + cos( angle ) * lengthOfHand;
endPoint.y = centrePoint.y + sin( angle ) * lengthOfHand;

If you visualise the hand as forming a right-angled triangle where the hypotenuse is the hand itself, the x axis goes through the centre and the y axis is a vertical line drawn from the tip if the hand to cut the x axis, this bit of trigonometry should be fairly obvious. This is what NSAffineTransform does internally. The advantage of using a transform is that you can apply it to a complete path of arbitrary shape, which is much more useful than just calculating where the end point would be. But I think it's useful to know a bit of the maths behind it so that it doesn't seem like "magic".

In code, the angle needs to be in radians. If you calculate in degrees (simpler for a clock probably) degrees to radians is:

#define DEGREES_TO_RADIANS( d )         ((d) * 0.0174532925199432958)





--Graham


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to