posted 5 years ago
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.
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.
tom davies
Ranch Hand
Posts: 168
tom davies
Ranch Hand
Posts: 168
posted 5 years ago
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
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
tom davies
Ranch Hand
Posts: 168
Matthew Brown
Bartender
Posts: 4568
9
tom davies
Ranch Hand
Posts: 168
posted 5 years ago
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.
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.
Matthew Brown
Bartender
Posts: 4568
9
posted 5 years ago
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.
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.
tom davies
Ranch Hand
Posts: 168
Matthew Brown
Bartender
Posts: 4568
9
tom davies
Ranch Hand
Posts: 168
posted 5 years ago
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 12 o clock should be.
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 12 o clock should be.
Let's go to the waterfront with this tiny ad:
The WEB SERVICES and JAXRS Course
https://coderanch.com/t/690789/WEBSERVICESJAXRS
