First commit. It works, but the maths is not quite right just yet.