Find the angle offset from point A to B

Viewed 91

I would like to find the horizontal angle offset from point A to B. For example, if point A was looking directly at Point B, the angle offset would be zero. Directly to the left would be -180, and to the right would be 180. What are some ways I could do this?

Currently, I have something like this:

let yaw = Math.atan2(delta.x, delta.z) * 180/3.14159;

but this code would get the angle relative to the x and z axis.

1 Answers

Using vectors would make your life a bit easier.

  • Find the vector connecting the point, A, and point, B.
  • Find the vector which has point, A, in it and is pointing in the direction, that A is pointing to.
  • Find the angle between them (many ways to do this. easier one is using the dot product)

Direction.js library can help you with the vectors.

Related