Mike C Posted November 26, 2013 Share Posted November 26, 2013 I'm trying to point a 3D PIO at another 3D object utilizing the Set3DRot function, by "panning" on it's z-axis, and "tilting" on it's x-axis. The panning angle is easy enough to calculate since it can be figured on just the two-dimensional x-y coordinates of both objects, but I'm having a hell of a time calculating the tilt angle since that throws me into three dimensional vectors. I've messed with Vec2Ang(CrossProduct(vec1,vec2)) and AngBVec(vec1,vec2) and some other M_GetSlope subroutines I've found in the Help section, but they don't appear to give me the result I need. I have basically no trig and calculus education, and my grasp of vectors is weak, so please use small words. Thanks. Quote Link to comment
Miguel Barrera Posted November 27, 2013 Share Posted November 27, 2013 The tilt should be the angle formed by the distance and elevation difference between the objects VAR x1,y1,z1,x2,y2,z2,dist,tilt: REAL; Vxy,Vz: VECTOR; The distance using vector notation in the x-y plane: Vxy.x:= x2-x1; Vxy.y:= y2-y1; Vxy.z:= 0; dist:= Norm(Vxy); And the tilt angle can be calculated from the elevation view: Vz.x:= dist; Vz.y:= z2-z1; Vz.z:= 0; tilt:= Vec2Ang(Vz); Quote Link to comment
Mike C Posted November 27, 2013 Author Share Posted November 27, 2013 Thank you Miguel. I never would have gotten there on my own. Now, I'll try to understand it as well. Quote Link to comment
JBenghiat Posted November 28, 2013 Share Posted November 28, 2013 Also, if you want to dive into trig, this is fairly straight forwards. Here is a decent trig reference: Trig Functions Picture a right triangle, with the plan distance being one leg and the vertical distance being the other. Because we know the values of the two legs, we can use tangent to find the angle. Tan( a ) = opposite / adjacent Tan( a ) = distance / height a = ArcTan( distance / height ) Because VW trig functions deal in radians, you need to convert the result into degrees. a := Rad2Deg( ArcTan ( distance / height ) ); HTH, Josh Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.