0
votes

I am experimenting a little with AR. I have got the angle of the direction I am looking to from a compass in degrees. I know my own position and the position of another object (POI), the position is giving in form of latitude and longitude.

Now I would like to know how I can calculate the angle between the direction I am looking to and the POI.

1

1 Answers

0
votes

Dot Product:

a . b = ||a|| ||b|| cos(t)
t = acos( (a.b)/(||a|| ||b||) )


||vector|| = length of vector (magnitude)
t          = angle between the two vectors

Your probably going to need to do this a couple times for each plane you have. (1x for 2D, 2x for 3D)

Or:

    /|
   / |
h /  | y
 /   |
/____|
  x

t is the lower left corner, which we'll assume is your object, the upper right corner is going to be your other object

x = obj2.x - obj1.x
y = obj2.y - obj1.y
h = sqrt( (x*x) + (y*y) )

sin(t) = y/h
cos(t) = x/h
tan(t) = y/x

t = asin(y/h)
t = acos(x/h)
t = atan(y/x)

What makes the first method better, is that it account's for you're current rotation. The second method (using atan, asin, and acos) doesn't.