programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Campbell Ritchie
• Tim Cooke
• Devaka Cooray
• Ron McLeod
• Jeanne Boyarsky
Sheriffs:
• Liutauras Vilda
• paul wheaton
• Junilu Lacar
Saloon Keepers:
• Tim Moores
• Stephan van Hulst
• Piet Souris
• Carey Brown
• Tim Holloway
Bartenders:
• Martijn Verburg
• Frits Walraven
• Himai Minh

# Plotting points around circle

Ranch Hand
Posts: 168
• Number of slices to send:
Optional 'thank-you' note:
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.

Bartender
Posts: 4568
9
• Number of slices to send:
Optional 'thank-you' note:
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.

tom davies
Ranch Hand
Posts: 168
• Number of slices to send:
Optional 'thank-you' note:
Ahh, works perfectly now with sin and cos swapped around! Thank you

tom davies
Ranch Hand
Posts: 168
• Number of slices to send:
Optional 'thank-you' note:
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

tom davies
Ranch Hand
Posts: 168
• Number of slices to send:
Optional 'thank-you' note:
Could anyone help with working out the hour hand please?
I am still a bit stuck on this
Thank you

Matthew Brown
Bartender
Posts: 4568
9
• Number of slices to send:
Optional 'thank-you' note:
Haven't you still got sin/cos the wrong way round in that example?

I'd take the formula that worked before, then divide the angle that you used before by 12. So you replace the 60 in the initial formula with 720.

tom davies
Ranch Hand
Posts: 168
• Number of slices to send:
Optional 'thank-you' note:
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.

Matthew Brown
Bartender
Posts: 4568
9
• Number of slices to send:
Optional 'thank-you' note:
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.

tom davies
Ranch Hand
Posts: 168
• Number of slices to send:
Optional 'thank-you' note:
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
Bartender
Posts: 4568
9
• Number of slices to send:
Optional 'thank-you' note:
Really? If I stick minute = 60 into those formulas in a calculator I get roughly what I'd expect.

tom davies
Ranch Hand
Posts: 168
• Number of slices to send:
Optional 'thank-you' note:

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: the value of filler advertising in 2021 https://coderanch.com/t/730886/filler-advertising