Jump to content
Developer Wiki and Function Reference Links ×

Calculate Pan and Tilt angles based on 3D vectors


Mike C

Recommended Posts

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.

Link to comment

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);

Link to comment

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

Link to comment

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...