[Swlug] Math Calculations

Rhys Sage rhys_sage at yahoo.com
Tue Jul 19 17:01:48 UTC 2022


I've been working on some maths problems. I can honestly say I detest maths when it gets complicated and usually end up relying upon easy solutions found online.

I found the solution to calculating compass headings online and it seems pretty  believable. The distance however, I'm not sure I have right. I've calculated it on diameter of the earth over 90. I had it over 360 originally but since it's 450km from the Arc de Triomphe to the Tower of London the small figure of 77 miles didn't seem right. Thus I tried 180 and that wasn't right either. 90 is a more believable figure but even so I think it's likely wrong. Does anybody have any navigational expertise to throw in here?

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Jul 19 12:04:26 2022


@author: rhys
"""
import math
DiameterOfEarth = 7917.5


#Assumung two fixed point - just for the sake of making life easy...
#North = positive values. South = negative values
#West = Positive values, East = negative values
LocationOneV = 51.5081
LocationOneH = 0.0759
#Tower of London


LocationTwoV = 48.8738
LocationTwoH = -2.2950
#Arc de Triomph


X = math.cos(LocationTwoV)*math.sin(LocationOneH-LocationTwoH)
Y = (math.cos(LocationOneV)*math.sin(LocationTwoV)-math.sin(LocationOneV)*
    math.cos(LocationTwoV)*math.cos(LocationOneH-LocationTwoH))


Z = math.atan2(X,Y)  #radians

#Compass heading in degrees
Degrees = math.degrees(Z)
print (Z)


#Distance calculation
DistanceV = (LocationOneV - LocationTwoV)
DistanceH = (LocationOneH - LocationTwoH)
DistanceCalc = (DistanceV*DistanceV)+(DistanceH*DistanceH)
ActualDistance = math.sqrt(DistanceCalc)*(DiameterOfEarth / 90)

#Distance to go in miles
print(ActualDistance)



Rhys Sage



More information about the Swlug mailing list