Finding Angle between clock hands

Photo by Andrew Neel on Unsplash

Finding Angle between clock hands

ยท

1 min read

Given a clock time in hh:mm format, determine, to the nearest degree, the angle between the hour and the minute hands.

As the hour hand, in 1 minute rotates 1/2 degree. So, in โ„Žโ„Ž hour ๐‘š minutes = 60โ„Ž+๐‘š minute it will rotate (60h + m)/2 degrees.

Equals, 30h + m/2.

Similarly, the minutes hand will rotate 6 degrees per minute so it will rotate 6(60h + m) degrees.

Apply mod 360 to it, which equals (360h + 6m)mod(360) = 6m

So, find the difference between (30h + m/2) and 6m. that will be the angle between the hands.

Final Expression: 30h + m/2 - 6m = 30h -11/2m and do (mod)360 since the hours can be very long.

Example with code in Javascript

function findAngle(hour, minute) {
    var angle = Math.abs(30 * hour - 11 / 2 * minute) % 360;
    return angle <= 180 ? angle : 360 - angle;
}
console.log(findAngle(3, 15)); // Output: 7.5
ย