I have a clock face and i want to be able to specify the hour and minute and the hands will move to the correct location.
I found the equation for finding the points around a circle r*cos(a) where "r" will be the length of the clock hand and a will be the angle.
I came up with this formula for the minute hand. I originally set the minute to 15, and this formula worked fine for that time. When i try a different time though the hand stays in the same position and the output for both calculations remained almost identical.
I did originally have PI/60 instead of PI%60 but that provided completely the wrong time.
You were closer the first time - you definitely need to divide by 60 (% doesn't do what you want). But I think the problem is you're using the angle to the horizontal. If minute is zero then sin(...) = 0, and your hand is pointing to 3. Try swapping sin and cos.
Sorry another question. For the hour hand i would have thought that formula could be modified to the same as below.
The hour hand is working in the same way, just moving 30degrees around the face for every hour. Apparently not, i can get it to appear right for a few times if i put 200+ instead of - for the y co ordinate as well
I swapped them round to see if it made any difference to the result.
Could you explain that last bit again please. What do you mean by "divide the angle that you used before by 12"
I thought dividing by 12 like in the last code block i did would be correct.
Also the last sentence, are you saying the only change to make is replace the 60 with 720?
Sorry for all the questions, the coding is fine but the maths is causing me problems at the moment.
For your minute hand, you were using 2*Math.PI*minute/60 as the angle (in radians).
If you use 2*Math.PI*minute/12 for the hour hand, that's 5 times the angle of the minute hand, which means the hour hand is moving faster than the minute hand. You want it to move twelve times slower. So you need 2*Math.PI*minute/(60*12).
Another way of looking at it would be to use 2*Math.PI*hour/12. That's fine, but you need to translate from minutes to hours.
Ok that makes sense now.
I have this, but it needs very high numbers to move the hand anywhere. For example, putting 900 for the minutes moves it to the 3 position, any normal number between 0-60 means it barely moves from the 12 o clock.
Matthew Brown wrote:Really? If I stick minute = 60 into those formulas in a calculator I get roughly what I'd expect.
Yep, If i use the formulas above, enter 60 for the minutes and use the line below to draw the line, the hour hand points roughly towards where 1-2 o clock should be.
Rototillers convert rich soil into dirt. Please note that this tiny ad is not a rototiller: