Determine the Angle between the Clock Hands
Problem: You are given the time of day in HH:MM format. You need to write a program to return the angle formed between the hands of an analogue clock displaying the given time.
Solution: This is not all that difficult if you think about it. Lets 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. Here's some simple C# code to show this:
public static void Main()
{
int hour = 2;
int minute = 45;
double degrees = Math.Abs(((hour*30.0 + minute/2.0) - minute*6.0) % 360);
Console.WriteLine( string.Format("Angle between clock hands = {0}",degrees) );
}
22 May 2010 Damien Wintour







