[Solved] What is the explanation behind the math to set a clock pointers to desired degrees?


let hr = date.getHours();
let min = date.getMinutes();
let sec = date.getSeconds();

let hrPosition = hr*360/12 + ((min * 360/60)/12) ;
let minPosition = (min * 360/60) + (sec* 360/60)/60;
let secPosition = sec * 360/60;

hrPosition -> full circle has 360 degrees, on clock it’s 12 hours, so 1 hour is 360/12 = 30 degrees, but as minutes are going, hour hand is moving too, so 30 degrees (1 hour) is 60 minutes and then every minute is 0.5 degree

Ex: 2:15 should be 2 * 30deg + 15 * 0.5deg -> 37.5 deg

minPosition -> full circle has 360 degress, on clock it’s 1 hour, so 60 minutes, so 1 minute is 360/60 = 6 deg, but as seconds are going, minute hand is moving too, so 6 deg (1 minute) is 60 seconds and then every second is 0.1 deg

secPosition -> same as minute but without other complementary values, because it’s the smallest value on the clock

EDIT: To be absolutely precise, there should be also counting degress for seconds in hrPosition

solved What is the explanation behind the math to set a clock pointers to desired degrees?