I need to mark a point in the map and get the direction of that point (like in a compass) related to the angle that the phone is currently being held in. Any tips would be highly appreciated. Thanks.
Asked
Active
Viewed 128 times
0
-
Take a look at this answer: http://stackoverflow.com/a/2571801/1038204. Should get you started. – Bryan Glazer Dec 10 '12 at 05:21
1 Answers
2
Your vector for the angle of the phone will be: av = (cos(phone_angle), sin(phone_angle))
Your vector for the angle from the phone to the destination will be dv = (x_phone_location - x_dest, y_phone_location - y_dest)
Find the magnitude (length) of each of the two above vectors. Call these magnitudes mag_dv
and mag_av
You can then do the dot product of the destination vector and the phone angle vector.
angle = arccos( ((dv_x * av_x)+(dv_y * av_y)) / (mag_av * mag_dv) )

Bryan Glazer
- 852
- 1
- 10
- 20