Algorithms for calculating space stuff