• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Drawing over a transparent background
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Drawing over a transparent background


  • Subject: Re: Drawing over a transparent background
  • From: Ron Fleckner <email@hidden>
  • Date: Tue, 25 Aug 2009 12:23:06 +1000


On 25/08/2009, at 10:56 AM, Graham Cox wrote:


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

Thanks, Graham

Your explanation and the 'cos(angle)', 'sin(angle)' bits are a little opaque to me at first reading, but my daughter's doing more advanced maths at school than I ever did, so I've got someone to help me with this. Having those code snippets will make it much easiser, and perhaps useful for me in the future.

Ron

_______________________________________________

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


References: 
 >Drawing over a transparent background (From: Ron Fleckner <email@hidden>)
 >Re: Drawing over a transparent background (From: Rob Keniger <email@hidden>)
 >Re: Drawing over a transparent background (From: Ron Fleckner <email@hidden>)
 >Re: Drawing over a transparent background (From: Steve Christensen <email@hidden>)
 >Re: Drawing over a transparent background (From: Ron Fleckner <email@hidden>)
 >Re: Drawing over a transparent background (From: Graham Cox <email@hidden>)

  • Prev by Date: Help needed with ConvertCocoa64 script
  • Next by Date: Re: Help needed with ConvertCocoa64 script
  • Previous by thread: Re: Drawing over a transparent background
  • Next by thread: Re: Drawing over a transparent background
  • Index(es):
    • Date
    • Thread