How Do I Calculate The Angle Between The Hour And Minutes Hands?
Solution 1:
Okay. You are trying to find the angle between the two hands. Then this:
minutesdegree=360 / 12 / 60 = 0.5
Is just the number of degrees the hour hand moves per minute. Think about it - the minute hand travels a full 360 each hour. Therefore there are only 60 minutes in a full revolution. 360/60 = 6 degrees per minute for the minute hand.
So, you need to find the difference between the hour and the minute hand. Thus the function now looks like:
def clockangles(hour, minute):
return (hour*30+minute*0.5) - (minute*6)
Now, this is valid, so we could stop here. However I should explain that this can give both answers larger than 180 degrees and negative angles. If you don't want those things (and from your comments it appears that you don't), correct for them.
def clockangles(hour, minute):
returnabs((hour*30+minute*0.5) - (minute*6))
Now, no negative angles.
def clockangles(hour, minute):
ans =abs((hour*30+minute*0.5) - (minute*6))
returnmin(360-ans,ans)
Now, the shorter of the two angles formed by measuring clockwise and counterclockwise.
Solution 2:
In the following solution, the variable m refers to minutes, and the variable h to hours.
Let's separate the problem into its components.
- Find the angle of the minute hand from 12 o'clock.
- Find the angle of the hour hand from 12 o'clock.
- Find the absolute value of their difference.
Now, let's start solving each component.
- The minute hand makes a full cycle every hour, or 60 minutes. Therefore, we can get the completed percentage of the cycle of the minute hand by
(m / 60)
. Since there are 360 degrees, we can get the angle of the minute hand from 12 o'clock by(m / 60) * 360
. The hour hand makes a full cycle every 12 hours. Since there are 24 hours in a day, we need to normalize the hour value to 12 hours. This is accomplished by
(h % 12)
, which returns the remainder of the hour value divided by 12.Now, as the minute hand makes its cycle, the hour hand does not just remain at the exact value of
(h % 12)
. In fact, it moves 30 degrees between(h % 12)
and(h % 12) + 1
. The amount by which the hour hand deviates from(h % 12)
can be calculated by adding to(h % 12)
the completed percentage of the cycle of the minute hand, which is(m / 60)
. Overall, this gives us(h % 12) + (m / 60)
.Now that we have the exact position of the hour hand, we need to get the completed percentage of the cycle of the hour hand, which we can get by
((h % 12) + (m / 60)) / 12
. Since there are 360 degrees, we can get the angle of the hour hand from 12 o'clock by(((h % 12) + (m / 60)) / 12) * 360
.Now that we have both the angle of the minute and hour hand from 12 o'clock, we simply need to find the difference between the two values, and take the absolute value (since the difference can be negative).
So overall, we have
abs(((((h % 12) + (m / 60)) / 12) - (m / 60)) * 360)
.
Below is a python function that calculates this value. It will return whichever value of the angle that is the shortest.
deffind_angle(h, m):
ifabs(((((m/60)+(h%12))/12)-(m/60))*360) > 180:
return360 - abs(((((h % 12) + (m / 60)) / 12) - (m / 60)) * 360)
returnabs(((((h % 12) + (m / 60)) / 12) - (m / 60)) * 360)
Solution 3:
Use the algorithm:
1.Minute angle = 360 * minutes / 60
2.Hour angle = [ 360 * (hour % 12) / 12 ] + [ 360 * (minutes / 60) * (1 / 12) ]
3.Angle between hour and minute = (hour angle - minute angle) % 360
this reduces to 30 * hours - 5.5 * minutes.
Solution 4:
Multiply hours by 60 that is convert it into minutes. hours*60=minutes
Now add the given minutes and converted minutes.
given minutes + converted mintes = total minutes
Now divide the total minutes by 2, that is to find its average. total minutes / 2
Now multiply given minutes by 6. given minutes * 6
Now subtract point 3 from point 4.
By this method you will get the accurate answer.
Solution 5:
Let's consider each hand in isolation first. The minutes hand of the clock rotates 360 degrees in 60 minutes so each minute represents 6 degrees. The hours hand of the clock rotates 360 degrees in 12 hours so we know it moves a total of 30 degrees after each hour, but you need to factor in the advancement of the hours hand between hours. i.e. at 3:30 the minutes hand is on 6 and the hours hand has progressed past 3. We can calculate this advancement simply by (minutes/60) * 30 degrees which is equivalent to minutes/2. So once we know the degrees of each hand we simply find the difference. And formula will be like
degrees = Math.Abs(((hour*30.0+minute/2.0) -minute*6.0) %360)
Post a Comment for "How Do I Calculate The Angle Between The Hour And Minutes Hands?"