Getting rotation on a circle (eg for clock hands)
Hi all,
I'm trying to work out how to position and draw lines around a circle. I have a circle drawn and I wish to put "rays" coming off it, like how you would draw a sun as a child.
I'm having trouble working out how to get the x, y and rotation that I need though. The rays are bitmaps so I need to position and rotate them.
Does anyone know what the algorithm would be for working out the position, where I could specify the degrees? Like if I said I have a circle that is origin 0, 0 and radius of 100, I could say I want the position at 45 degress? So I could get x and y on the circle's edge at 45 degees then? But I need it to work on any specified degree, like I could want 18 or something. It could then get the x and y of 18 on the edge and the rotation to make the image so that the ray comes right out of it in a line?
Any help appreciated.
Re: Getting rotation on a circle (eg for clock hands)
If 0 degrees corresponds to 12 o'clock, and you want to rotate clockwise, use this:
(x, y) = (r sin(theta), r cos(theta))
where theta is your angle, r is your radius. For instance, using r = 100, theta = 18 degrees, the coordinates are
(x, y) = (30.9, 95.1)
A note on calculating trig functions (sin and cos): "degrees" are not the only way to measure the size of angles. 360 degrees to a circle is completely arbitrary; maybe the ancient Babylonians had 400 degrees (I dunno; I'm certain one of those civilizations did). To get around these problems, mathematicians use "radians", which is in some sense a more natural way of expressing angles. The upshot is, when you type sin(theta) on a calculator, the calculator might be expecting theta in degrees, or it might be expecting theta in radians. VB6 expects radians.
To convert, use the following:
360 degrees = 2*pi radians
=>
x degrees = x*pi/180 radians
I assume you're able to rotate your ray images yourself and that you just wanted to know where to center them.