How to you calculate the angle of the MinuteHand and the HourHand of a clock, when you are given the time as the number of seconds since midnight?
Angles in radians would be fine.
Thanks.
EDIT: I don't want the angle between the hands, just the angle individually: say its 3:00am, the minute hand is at 0 radians (0 degrees) and the hour hand is at 1.570796 radians (90 degrees).
Last edited by wossname; Sep 11th, 2004 at 01:06 PM.
How many radians does the hour hand travel through per second?
How many radians does the minute hand travel through per second?
My ropey maths tells me that the minute hand travels through 0.0000290882087 radians per second, and the hour hand 0.0000005076956996 radians per second. Is this right?
Since a second hand does 6 degrees per sec, divide by 60 to get minute hand degrees per second and divide by 60 again to get hour hand, then convert each of those to radians.
If I multiply these figures by the number of seconds since midnight I should be left with the correct angle for each hand. Does this seem logical?
Took 3 expressos to get this finished. I'll finish polishing my Clox0r class and post it up here when all the bugs have been eradicated.
Meanwhile, here's a screenshot...
Graphically, the hands of the clock are accurate to a 10,000,000th of a second. You can even get it to sweep smoothly around the clock (like on Back To The Future )!
The constructor lets you specify the radius of the clockface, the x,y position of the centre of it and the graphics object you want to draw the clock on. (Just had it drawing onto a Button control ).
Clox0r drawing itself onto a Button control's Graphics object via button_Paint(). Clicking the button pops up a message box, meanwhile the clock keeps ticking on the button!
You feed it Timespan Objects and it will go in whatever direction you want, feed it the right times and you can get the hour and minute hands to spin in opposite directions
VB Code:
dim cf as Clox0r = new Clox0r(...)
...
dim temp as Timespan = new Timespan(0)
for i as integer = 0 to 99999
cf.Time = cf.Time.AddMinutes(59)
cf.Draw
Delay()
next i
Last edited by wossname; Sep 13th, 2004 at 03:26 AM.
Originally posted by Darkwraith What algorithm did you use to find the position of the hands?
I wrote a Hand class and as a Constructor argument I pass in the speed of the particular hand in question. Then the class multiplies this value by the ticks property of the time. The speed is expressed as the number of radians that the hand passes through per tick (Pretty microscopic number!). And so this multiplication gives the angle that the hand shoulld be shown at. This is typically several million radians.
The Clox0r class (the whole thing) will be released as part of the Sandpaper library (see the Project Communication forum here)
Source will not be available I'm afraid. And yes, it will be able to run backwards Stay tuned.
If you are interested, the shape of the hands was defined as an array of PointF objects. the .X property of which represented the Angle of the point in radians, and the .Y property was the distance away from the origin. Polar Coordinates in other words.
Then its just a simple job of adding the each .X to the angle of the hand and drawing the resulting polygon. Simple and precise.