What's the angle between a clock's hands given the current time?
Here’s kind of a fun and interesting question.
A clock shows the current time as, say, 4:20. What is the angle between the hour and minute hands? What about in general? Is there a nice formula we can use to get this angle given any time? And does this have any applications?
Figure 1: Oh would you look at the time
Worked example
If it’s currently 4:20, then the minute’s hand is
Furthermore, we know the hour hand would be
The angle between the hour and minute hands, therefore, is simply the difference between their individual angles with respect to the top of the clock, i.e.
The general formula
Let
For example, if the current time is 4:20, then
Now, just as before, we will find each respective angle of the hands with respect to the top of the clock. Note that we will continue to work in degrees rather than radians for a couple of reasons:
- The numbers on the clock, 12, and the number of ticks, 60 are both factors of 360, the number of degrees in a full revolution. Continuing to work in degrees will make the math a bit nicer.
- Any computer programming applications of this result will work nicer with a formula involving as little floating point representations of numbers as possible. Numbers like
don’t calculate well with other numbers in the CPU and can potentially lead to slower and less precise results.
Let
The minutes hand
We know there are 60 minutes in a revolution, so
The hours hand
As before, the angle of the hour hand is going to be
Here, a bit is the “fraction” of
Altogether,
The angle between them
Therefore, our general formula for the angle between hands on a clock (in degrees) given
Sanity check
Let’s test our example from before with our general formula. We already know the angle between hands on a clock at 4:20 is just
Let
Applications?
It might be useful if you’re simply wanting to draw an accurate clock for given a time, but our two intermediary results are probably more useful for this:
These two formulas will tell you which angle to draw the lines at (with respect to the top of the clock).
Here’s a quick, interactive demo written in p5.js :
Javascript code...
var width;
var height;
function setup() {
// Work in degrees
angleMode(DEGREES);
let demo = document.getElementById("demo");
width = int(getComputedStyle(demo).width);
height = int(getComputedStyle(demo).height);
createCanvas(400, 400);
// Get sliders
hSlider = document.getElementById("hSlider");
mSlider = document.getElementById("mSlider");
}
function draw() {
radius = 0.95 * min(width, height) / 2;
background(39, 40, 34);
// Draw the clock face
fill(39, 40, 34);
stroke(255);
strokeWeight(2);
// Set the origin to the centre of the canvas
translate(width / 2, height / 2);
// Set the 0 degree mark to the top of the clock
rotate(-90);
circle(0, 0, 2 * radius);
// Draw the minute hand
strokeWeight(3);
let minutes = int(mSlider.value);
let a_m = 6 * minutes;
let x_m = 0.8 * radius * cos(a_m);
let y_m = 0.8 * radius * sin(a_m);
line(0, 0, x_m, y_m);
// Hour hand
strokeWeight(4);
let hours = int(hSlider.value);
let a_h = (60 * hours + minutes) / 2;
let x_h = 0.5 * radius * cos(a_h);
let y_h = 0.5 * radius * sin(a_h);
line(0, 0, x_h, y_h);
}
Exercises
- Is there another way to derive these formulas using rates of change?
- Can you find a formula providing the exact times of day where the hour and minute hands overlapping?
- Can you generalise this idea further by including a seconds hand?
- In your favourite programming language, write a program that takes the number of seconds since January 1st, 1970 (Unix time) and draws an accurate, realtime, clock.