Help coderanch get a
new server
by contributing to the fundraiser
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
• Jeanne Boyarsky
• Ron McLeod
• Paul Clapham
• Liutauras Vilda
Sheriffs:
• paul wheaton
• Rob Spoor
• Devaka Cooray
Saloon Keepers:
• Stephan van Hulst
• Tim Holloway
• Carey Brown
• Frits Walraven
• Tim Moores
Bartenders:
• Mikalai Zaikin

# Clock problem

Ranch Hand
Posts: 8945
• Number of slices to send:
Optional 'thank-you' note:
Find formula to compute angle between hour hand and minute hand.

lowercase baba
Posts: 13091
67
• Number of slices to send:
Optional 'thank-you' note:
it's trivial to figure out each hands postion, given the time. you can calculate the angle around from 12:00:00.
if you know each hands postion, the angle between them is the difference.

Ranch Hand
Posts: 8945
• Number of slices to send:
Optional 'thank-you' note:
but how?

Wanderer
Posts: 18671
• Number of slices to send:
Optional 'thank-you' note:

Ranch Hand
Posts: 1907
1
• Number of slices to send:
Optional 'thank-you' note:

but how?

Input is some time ,like 5:37.How much is angular movement of hour hand from position 12? 30*5 = 150 degrees + 15 degrees(bcos of those first 30 minutes) = 165 degrees.
Now hour hand moves by 30 degrees when minutes hand moves by 360 degrees,right? so for 1 minute,30/360-->(1/12) degrees,correct?So for 7 minutes 7/12 degrees.So total angular movement of hour hand is 165+(7/12) degrees.
Now angular movement of minute hand is 180+30+12 = 222 degrees.
I hope now you can make a formula out of it.
Has anybody has used Theodolite for calculating the angle and the distance between the two objects on a surface?
[ November 25, 2003: Message edited by: Capablanca Kepler ]

Greenhorn
Posts: 2
• Number of slices to send:
Optional 'thank-you' note:

Find formula to compute angle between hour hand and minute hand.

angle = 30H - 5.5M
Example, at 2:35, angle = 30*2 - 5.5*35 = 60 - 192.5 = 132.5 degrees (ignore the sign)
[ January 17, 2005: Message edited by: Pravin Mhaske ]

Ranch Hand
Posts: 67
• Number of slices to send:
Optional 'thank-you' note:
I think that what has been posted so far is too complicated. All that is needed is to know that 1 minute should be 6 degrees (360 degrees in 60 minutes, so that follows). So when you have the minutes, to compute the degrees, you simply do:

Hours can be either much easier or a little harder. First the easy way:
Since you know there are 12 hours in 360 degrees, the difference between hours is simple 360/12 = 30 degrees. So the code is:

However, if you wanted to be like a real clock, where the hour hand slowly moves continuously over the hour, then you would have to take into account the amount of minutes that have passed. To do this, I would simply find the decimal between the hours (i.e. 6:30 would be 6.5) and then find the degrees. The code then would be something like:

Now that we have the two degree values, we can subtract their values. This can be done like:

Ranch Hand
Posts: 3061
• Number of slices to send:
Optional 'thank-you' note:
If minutes is an int, then

will not give the correct result as described above. This line of code should be changed to

in order to avoid integer division.

Layne