Cálculo del rumbo de A(x1,y1) relativo a B(x2,y2) en 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!

preguntado el 28 de agosto de 12 a las 10:08

Do you know how to calculate the slope of a line between 2 points in the Cartesian plane ? -

I don't but I can find out. How does it help to compute the bearing? -

Because the bearing is the slope of the line between your 2 points. In your picture blue bears 065° from red, and, inevitably, red has the reciprocal bearing from blue. -

How do I get the bearing value from the slope? -

The bearing is the slope. The bearing of blue from red is the slope of the line from red to blue. The bearing of red from blue is the slope of the line from blue to red. If you've calculated the slope as, perhaps '4/5' then you have to convert that to an angular measurement. @Axeman's answer tells you how to do that. -

2 Respuestas

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.

Respondido 28 ago 12, 12:08

I have this at the moment: float bearing = RADIANS_TO_DEGREES(atan2f(y2-y1, x2-x1)); How can I map it to 0-360? - Alvin Loh

something like bearing=(atan2f_result >= 0 ? atan2f_result : (2*PI + atan2f_result)) * 360 / (2*PI); should works. - Axeman

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.

Respondido 28 ago 12, 10:08

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.