Created
December 11, 2017 19:44
-
-
Save imparvez/9cbf899b536ec0ca429b6762b1c33072 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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