Re: Dead Reckoning
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