Skip to content
This repository has been archived by the owner on Feb 28, 2024. It is now read-only.

Haversine is a Go package that finds the shortest great circle route between two points on a sphere.

License

Notifications You must be signed in to change notification settings

loraxipam/haversine-archived

 
 

Repository files navigation

GoDoc Reference Build Status Go Report Card Coverage Status

Haversine

Package haversine provides the great circle distance between two points on the surface of a sphere, with specific functions for Earth. Points are identified by latitude and longitude, and distance results can be returned in nautical miles, statute miles, or kilometers. An internal angle function returns the radians between two points. Earth great circle

The curvature of the Earth dictates that the shortest distance between two points cannot be a straight line between the points. The Haversine formula provides an approximation for the shortest great circle route over the surface of Earth that connects the two points. In this figure the dotted yellow line is the arc of a great circle. Image courtesy USGS.

Installation

go get github.com/FATHOM5/haversine

Usage

The example below shows how far I'd have to walk in my boots to go visit my co-founder.

package main

import (
    "fmt"
    "math"

    "github.com/FATHOM5/haversine"
)

func main() {
    austin := haversine.Coord{ // Austin, Texas
        Lat: 30.2672,
        Lon: -97.7431,
    }
    paloAlto := haversine.Coord{ // Palo Alto, California
        Lat: 37.4419,
        Lon: -122.1430,
    }

    nm := haversine.DistanceNM(austin, paloAlto)

    fmt.Printf("%.1f miles is a long walk to Silicon Valley.\n", nm)
    fmt.Printf("it's only %.1f miles on the moon, though.\n", haversine.Distance(austin, paloAlto, 937.9))
    fmt.Printf("That's an angle of %.1f degrees\n", 180/math.Pi*haversine.IntAngle(austin, paloAlto))

    // Output: 1286.1 miles is a long walk to Silicon Valley.
    // It's only 350.6 miles on the moon, though.
    // That's an angle of 21.4 degrees

}

Documentation

References

License

See LICENSE for rights and limitations (MIT).

About

Haversine is a Go package that finds the shortest great circle route between two points on a sphere.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%