Die Haversine-Formel, zu finden unter https://en.wikipedia.org/wiki/Haversine_formula in Python zu übertragen, habe ich versucht. Die zurückgelieferten Ergebnisse sind aber falsch. Warum?
Code: Alles auswählen
from __future__ import print_function, division
import numpy as np
def haversine(phi_1, phi_2, lambda_1, lambda_2):
    """ calculates the distance in kilometers between two geographical points
    """
    leftParenthesis = ((phi_2 - phi_1)/2)
    rightParenthesis = ((lambda_2 - lambda_1)/2)
    allUnderSquareRoot = ((np.sin(leftParenthesis))**2) + np.cos(phi_1)*np.cos(phi_2)*(np.sin(rightParenthesis))**2
    squareRootResult = np.sqrt(allUnderSquareRoot)
    arcSin = np.arcsin(squareRootResult)
    r = 6371
    result = 2 * r * arcSin
    return result
if __name__ == "__main__":
    '''
    westlicher Ort: Position 1
    östlicher Ort: Position 2
    '''
    
    '''
    # Madrid (1) - Budapest (2)
    PHI_1 = 40.4167754
    PHI_2 = 47.497912
    LAMBDA_1 = -3.7037902
    LAMBDA_2 = 19.040235
    '''
    # New York (1) - Aachen (2)
    phi_1 = 40.712784
    phi_2 = 50.7753455
    lambda_1 = -74.005941
    lambda_2 = 6.0838868   
    result = haversine(phi_1, phi_2, lambda_1, lambda_2)
    print(result)





