Distance now calculates correctly across toroidal surface. The file outputs the average distance to a .csv file.
All files have been tested and work.