Code Monkey home page Code Monkey logo

swiftygeodesic's Introduction

SwiftyGeodesic

Swift Version Platform GeographicLib Version

Swift wrapper for Charles Karney's C library for geodesics. See Karney's GeographicLib project, the C library for the geodesics contains the direct and inverse solver as part of the Legacy C code folder.

Description

The shortest path between two points (p1 & p2) on the ellipsoid having locations specified by p1 at (lat1, lon1) and p2 at (lat2, lon2) is called the geodesic. Its length between p1 and p2 is s12 and the geodesic from p1 to p2 has forward azimuths az1 and az2 at the two end points.

Traditionally two geodesic problems are considered, direct and inverse.

The Direct Problem

Given lat1, lon1, s12, az1, determine lat2, lon2, and az2. This is solved by the function direct().

Example: Starting at New York JFK airport (lat=40.63972222, lon=-73.77888888), head on an initial bearing of 51.37288858° for a distance on 5,554,344m - compute the location of p2 and final forward azimuth on the WGS84 ellipsoid.

import SwiftyGeodesic
let dirResult = direct(p1: (lat: 40.63972222, lon: -73.77888888), az1: 51.37287886, s12: 5554344.26)
let p2Lat = dirResult.lat2         // 51.477500002 - lat of London Heathrow (LHR) airport
let p2Lon = dirResult.lon2         // -0.461388897 - lon of London Heathrow (LHR) airport
let p2FwdAzimuth = dirResult.az2   // 107.97130748 - forward bering at LHR

The Inverse Problem

Given lat1, lon1, lat2, lon2, determine s12, az1, and az2. This is solved by the function inverse().

Example: Starting at New York JFK airport (lat=40.63972222, lon=-73.77888888) and ending at London Heathrow airport (lat=51.4775, lon=-0.46138888) - compute distance s12 and forward azimuths az1 and az2 on the WGS84 ellipsoid.

import SwiftyGeodesic
let invResult = inverse(p1: (lat: 40.63972222, lon: -73.77888888), p2: (lat: 51.4775, lon: -0.46138888))
let dist = invResult.s12          // 5554344.26   - dist between JFK to LHR
let p1FwdAzimuth = invResult.az1  // 51.37287886  - forward bearing at JFK
let p2FwdAzimuth = invResult.az2  // 107.97130749 - forward bering at LHR

Swift Package Management

dependencies: [
        .package(url: "https://github.com/firecrestHorizon/SwiftyGeodesic.git", from: "1.0.0"),
    ],

WGS as default ellipsoid and overriding WGS84

The package will use WGS84 as the default datum (semi-major axis, a = 6,378,137.0 m; flattening f = 1/298.257223563) Other ellipsoids can be used by overrding the default ellipsoid a & f values.

Example for ETRS89:

let ETRS89 = (a: 6378137.0, f: 1 / 298.257222101)
let dirResult = direct(p1: (lat: 51.21, lon: 3.456), az1: 23.344, s12: 10000, ellipsoid: ETRS89)

swiftygeodesic's People

Contributors

kieranconlon avatar

Stargazers

 avatar  avatar

Watchers

 avatar

swiftygeodesic's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.