Skip to content

General purpose Go library for working with coordinates on a spherical Earth.

Notifications You must be signed in to change notification settings

stellarsunset/go-spherical

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go Spherical

Test codecov

Math on a spherical Earth.

Quickly compute distances, courses, projections, etc. using locations on the Earth's surface.

import(
    sph "stellarsunset/spherical"
    ll "stellarsunset/spherical/latlong"
    dist "stellarsunset/spherical/distance"
)

// Basic operations against primitives, compute courses, distances, perform projections, etc.
nyc := []float64{40.7128, -74.0060}
tokyo := []float64{35.6764, 139.6500}

nm := sph.DistanceInNm(nyc[0], nyc[1], tokyo[0], tokyo[1])
fmt.Println(nm) // 5856.184170028993

deg := sph.CourseInDegrees(nyc[0], nyc[1], tokyo[0], tokyo[1])
fmt.Println(deg) // 332.98810818766503

// Operations using higher-level, but simple abstractions
nyc, tokyo := ll.NewLatLong(40.7128, -74.0060), ll.NewLatLong(35.6764, 139.6500)

d := nyc.DistanceTo(tokyo)
fmt.Println(d.InNauticalMiles()) // 5856.184170028993
fmt.Println(d.InFeet()) // 3.558285132182971e+07

c := nyc.CourseTo(tokyo)
fmt.Println(c.InDegrees()) // 332.98810818766503
fmt.Println(c.InRadians()) // 5.811738857861843

Much of the functionality in this repository has been ported from MITRE Commons.

About

General purpose Go library for working with coordinates on a spherical Earth.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages