• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Dead Reckoning
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Dead Reckoning


  • Subject: Re: Dead Reckoning
  • From: Michael de Haan  <email@hidden>
  • Date: Fri, 09 Oct 2015 07:58:56 -0700

>
> I am trying to derive a DR fix from an initialized CLLocation.
>
> Like this. (Playground)
>
> let fixTime = NSDate(timeInterval: (1.00 * 60.00 * 60.00  * -1.00), sinceDate: NSDate()) // one hour ago
> let fixLocation = CLLocation(coordinate: CLLocationCoordinate2DMake(boatLocation.coordinate.latitude, boatLocation.coordinate.longitude), altitude: 0.00, horizontalAccuracy: 0.00, verticalAccuracy: 0.00,course: heading, speed: knots * 0.51444445,  timestamp: fixTime)  // location one hour ago
>
>
> I am sure there must be something like…..
>
>

For those ever needing this, here is what I came up with. (Heavy credit to SO for drLat, drLong and conversation  formulae)


let knotsToMeters =  1852.00
let earthRadius = 6372797.6

func degrees2radians(coordinate:CLLocationDegrees) -> Double {

    return (M_PI * coordinate ) / 180.00
}

func radians2degrees(coordinate:CLLocationDegrees) -> Double {

    return (180.00 * coordinate ) / M_PI
}


func deadReckonedLocationFrom(fix: CLLocationCoordinate2D, bearing:CLLocationDirection, knots:CLLocationSpeed, timeSinceReport:NSTimeInterval) -> CLLocationCoordinate2D {


    let rBearing = degrees2radians(bearing)
    let rFixLat = degrees2radians(fix.latitude)
    let rFixLong = degrees2radians(fix.longitude)
    let rDistance = (knots * timeSinceReport * knotsToMeters) / earthRadius

    let drLat =  asin(sin(rFixLat) * cos(rDistance) + cos(rFixLat) * sin(rDistance) * cos(rBearing))
    let drLong = rFixLong + atan2(sin(rBearing) * sin(rDistance) * cos(rFixLat), cos(rDistance) - sin(rFixLat) * sin(drLat))
    return CLLocationCoordinate2D(latitude: radians2degrees(drLat), longitude: radians2degrees(drLong))
}


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


  • Follow-Ups:
    • Re: Dead Reckoning
      • From: Graham Cox <email@hidden>
References: 
 >Dead Reckoning (From: Michael de Haan  <email@hidden>)

  • Prev by Date: NSButton with NSTexturedRoundedBezelStyle outside of NSToolbar
  • Next by Date: Re: NSButton with NSTexturedRoundedBezelStyle outside of NSToolbar
  • Previous by thread: Dead Reckoning
  • Next by thread: Re: Dead Reckoning
  • Index(es):
    • Date
    • Thread