8 posts
Posted 03 July 2013 - 01:46 PM
how do i find my bearing to a point, when i know my position and my angle.
my position is vec(100,100,50) and my angle is ang(90,45,60) and the point's position is vec(10,20,30)
375 posts
Location
USA
Posted 03 July 2013 - 02:53 PM
This is similar to something I was talking about yesterday. To get the angle from one point to another on the yaw axis (x, y), you can use the math.atan2 function. To apply your own angle, just subtract your current yaw from the result. math.atan2 returns the angle (in radians) between (0, 0) and the parameters you give it. For example, math.atan2(1, 1)/math.pi*180 == 45. Since it doesn't allow you to supply both points, you need to get the other point relative to your own position. You can do this by subtracting your position from the other point. Now that you have a relative vector, you can put it into math.atan2 and get the angle.
Example:
v1 = vec(100, 100, 50)
v2 = vec(10, 20, 30)
ang = ang(90, 45, 60)
rel = v2 - v1
bearing = math.atan2(rel.x, rel.y)/math.pi*180
finalYaw = bearing - ang.yaw
If you want to get change in elevation, you do the same as done here but for the pitch axis (y, z).
8 posts
Posted 03 July 2013 - 02:58 PM
Thank you :D/>