1
$\begingroup$

I want to get the difference between the orientation of my robot and a target point. The orientation is expressed as an angle as shown in the pictue below. The point is expressed as (x, z) in a cartesian space that has origin in the robot position. The x and z axis are always fixed.

This image explains how the angle and the axis are intended.

enter image description here

I need the angle between the orientation and the target, and I need it to be positive/negative when the target is left/right.

$\endgroup$
2
  • $\begingroup$ ok, you described what you need ... however, you did not ask any questions ... i can think of two different questions off the top of my head ... what question is yours? $\endgroup$
    – jsotola
    Commented Jul 26, 2020 at 18:59
  • $\begingroup$ I have answered a similar question here, I think it might help. gamedev.stackexchange.com/questions/22133/… $\endgroup$ Commented Dec 24, 2020 at 12:22

1 Answer 1

1
$\begingroup$

Assuming you know the heading of your own vehicle, you then need to find the absolute bearing of your target so you can find the relative bearing between your vehicle and the target.

The best way to do this, if you have the x/z position of the target, is with the atan2 function, where:

atan2(y, x) returns a single value θ such that −π < θ ≤ π

If you just use atan then you wind up with an ambiguous result and you need to check/offset the answer by checking the signs of y and x. The atan2 function does this automatically.

$\endgroup$
1
  • $\begingroup$ It might be good to add that the two angles can just be subtracted and the result normalized. $\endgroup$
    – SteveO
    Commented Dec 24, 2020 at 14:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.