Calculate the angle between hour hand and minute hand | GeeksforGeeks
This problem is know as Clock angle problem where we need to find angle between hands of an analog clock at .
http://javagtu.blogspot.com/2014/07/calculate-angle-between-hour-hand-and.html
https://sites.google.com/site/mymathclassroom/trigonometry/clock-angle-problems/clock-hands-form-into-a-straight-line
The formula for finding the clock angle θ is
Read full article from Calculate the angle between hour hand and minute hand | GeeksforGeeks
This problem is know as Clock angle problem where we need to find angle between hands of an analog clock at .
The minute hand moves 360 degree in 60 minute(or 6 degree in one minute) and hour hand moves 360 degree in 12 hours(or 0.5 degree in 1 minute). In h hours and m minutes, the minute hand would move (h*60 + m)*6 and hour hand would move (h*60 + m)*0.5.
http://algorithms.tutorialhorizon.com/clock-angle-problem/- At 12:00 both hand meet, take it as reference.
- Angle between hand and minute = angle of hour hand ~ angle of minute hand.
- return minimum(angle, 360-angle)
- hour hand moves 360 in 12 hours => 360/12 = 30 degree in one hour or 0.5 degree in 1 min
- Minute hand moves 360 in 60 mins => 360/60 = 6 degree in one min
- So if given time is h hours and m mins, hour hand will move (h*60+m)*0.5 and minute hand will move 6*m
public
static
double
angle(
int
hour,
int
minute) {
if
(hour <
0
|| minute <
0
) {
return
-
1
;
}
if
(hour ==
12
) {
hour =
0
;
}
if
(minute ==
60
) {
minute =
0
;
hour +=
1
;
}
double
hourAngle = (hour *
60
+ minute) *
0.5
;
double
minAngle = minute *
6
;
double
bwAngle = Math.abs(hourAngle - minAngle);
return
Math.min(
360
- bwAngle, bwAngle);
}
int calcAngle( double h, double m) { // validate the input if (h <0 || m < 0 || h >12 || m > 60) printf ( "Wrong input" ); if (h == 12) h = 0; if (m == 60) m = 0; // Calculate the angles moved by hour and minute hands // with reference to 12:00 int hour_angle = 0.5 * (h*60 + m); int minute_angle = 6*m; // Find the difference between two angles int angle = abs (hour_angle - minute_angle); // Return the smaller angle of two possible angles angle = min(360-angle, angle); return angle; } |
https://sites.google.com/site/mymathclassroom/trigonometry/clock-angle-problems/clock-hands-form-into-a-straight-line
The formula for finding the clock angle θ is
Read full article from Calculate the angle between hour hand and minute hand | GeeksforGeeks