Alvin Loh
Alvin Loh

Reputation: 63

Calculating the Bearing of A(x1,y1) Relative to B(x2,y2) in iOS

enter image description here

May I know how I should calculate the bearing of one point relative to another? All the formulas I'm seeing on the Internet are for lat/lon coordinates. I'm working with the Cartesian coordinate system here and am unable to find a solution. Please help!

Upvotes: 1

Views: 1431

Answers (2)

Axeman
Axeman

Reputation: 174

Use atan2 function (IIRC your objective-c should have it). It gives you a result between -PI and PI. You have to map it to 0-360 if you need it.

Upvotes: 3

SomaMan
SomaMan

Reputation: 4164

Not really an answer to your question, but if you're getting your points using CLLocationManager, each CLLocation has a course property, which gives you the bearing of your journey for the given point. For the actual math, see Axeman's answer.

Upvotes: 1

Related Questions