Skip to content

Instantly share code, notes, and snippets.

@imparvez
Created December 11, 2017 19:44
Show Gist options
  • Save imparvez/9cbf899b536ec0ca429b6762b1c33072 to your computer and use it in GitHub Desktop.
Save imparvez/9cbf899b536ec0ca429b6762b1c33072 to your computer and use it in GitHub Desktop.
/*
1. calculate angle of hour
2. calculate angle of minutes
# Calculate angle of minutes
1 hour = 60 minutes = 1 full rotation = 360/60 = 6 degree / minute
______________________________
| |
|angle-of-minutes = 6 * minute |
| |
|______________________________|
# Calculate angle of hour
12 hours = 720 minutes = 1 full rotation = 360/720 = 0.5 degree / minute
____________________________________________________
| |
|angle-of-hour = 0.5 * change in minute |
| = 0.5 * (60 * hour + minute) |
|____________________________________________________|
*/
function clockAngle(hour, min){
var h = 0.5 * (60 * hour + min);
var m = 6 * min;
var angle = Math.abs(h - m);
return (angle > 180) ? 360 - angle : angle;
}
console.log(clockAngle(12,16));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment