27 lines
644 B
Python
27 lines
644 B
Python
from dataclasses import dataclass
|
|
from math import cos, asin, sqrt, pi
|
|
from math import radians
|
|
|
|
from typing_extensions import Self
|
|
|
|
|
|
@dataclass(eq=True, frozen=True)
|
|
class GeoLocation:
|
|
lat: float
|
|
lon: float
|
|
|
|
@property
|
|
def ballVector(self) -> tuple[float, float]:
|
|
return radians(self.lat), radians(self.lon)
|
|
|
|
@property
|
|
def vector(self) -> tuple[float, float]:
|
|
return self.lat, self.lon
|
|
|
|
def distance(self, geoLocation: Self) -> float:
|
|
r = 6371000 # m
|
|
p = pi / 180
|
|
|
|
a = 0.5 - cos((geoLocation.lat-self.lat)*p)/2 + cos(self.lat*p) * cos(geoLocation.lat*p) * (1-cos((geoLocation.lon-self.lon)*p))/2
|
|
return 2 * r * asin(sqrt(a))
|