feat: move stuff to numerics
This commit is contained in:
parent
465ad00f7b
commit
b7fd7046ff
5 changed files with 119 additions and 29 deletions
|
|
@ -64,3 +64,26 @@ func LngLerp(a, b, l float64) float64 {
|
|||
func Lerp(a, b, l float64) float64 {
|
||||
return (1-l)*a + l*b
|
||||
}
|
||||
|
||||
// AddGeo returns the component-wise sum a+b without longitude wrapping. Use it
|
||||
// to combine derivative (rate) vectors — rates accumulate linearly, unlike
|
||||
// positions, which wrap via GeoAdd.
|
||||
func AddGeo(a, b GeoVec) GeoVec {
|
||||
return GeoVec{Lat: a.Lat + b.Lat, Lng: a.Lng + b.Lng, Altitude: a.Altitude + b.Altitude}
|
||||
}
|
||||
|
||||
// EarthRadius is the spherical Earth radius (metres) used for horizontal
|
||||
// motion, matching the reference Tawhiri implementation.
|
||||
const EarthRadius = 6371009.0
|
||||
|
||||
// WindToGeoRate converts eastward (u) and northward (v) wind in m/s at the
|
||||
// given latitude (deg) and altitude (m) into the geographic rate in deg/s on a
|
||||
// spherical Earth. The returned dLng diverges near the poles as cos(lat) → 0.
|
||||
func WindToGeoRate(u, v, lat, alt float64) (dLat, dLng float64) {
|
||||
const degPerRad = 180.0 / math.Pi
|
||||
const piOver180 = math.Pi / 180.0
|
||||
r := EarthRadius + alt
|
||||
dLat = degPerRad * v / r
|
||||
dLng = degPerRad * u / (r * math.Cos(lat*piOver180))
|
||||
return dLat, dLng
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue