Find angle between given time

Question : Find Angle between 12:30

We can see that hour hand pointing to 12 h and minute hand to 30 min

 

Related Question : Chef Jump

 

Calculate Minutes Covered by hour hand = 12 * 60 + 30 min
Calculate Minutes Covered by minute hand = 30 min

Important point to note is that

For hour hand 12h  = 360 degree, 1min = 0.5 degree
For minute hand 60 min = 360 degree, 1 min  = 6 degree

Degree covered by hour hand = 750 / 2 = 375
Degree covered by minute hand = 30 * 6 = 180 degree

Therefore angle = 375 - 180 = 195 degree

Most important Note :


For calculating minimum angle we will print min(195,360-195)

 

h = (h * 60 + m) * 0.5;
m = m * 6; 
cout<< min(abs(h-m),360-abs(h-m)) << endl;

Basically we are checking if angle is minimum for
acute angle (Angle) or obtuse angle (360 - Angle)

No comments:

If you have any doubt or suggestion let me know in comment section.

Powered by Blogger.