Note: I didn't code up the maths, so if you look at it, it'll give you a hint!