sander
sander

Reputation: 11

XYZ rotation to pan and tilt

I am trying to control a moving head camera in a certain direction from my computer. The camera is controlled only by pan (540 degrees) and tilt (280 degrees). The problem is getting the Euler angles to these pan and tilt degrees.

I have a 3d representation of a direction, let's say X Y and Z rotation (Eurler angles).

Now I want to move my (physical!) pan tilt camera in te same direction. But i can't figure out how to translate an xyz vector to pan tilt.

Upvotes: 1

Views: 3497

Answers (1)

Spektre
Spektre

Reputation: 51845

switch to orthogonal homogenous 4x4 transform matrices

  • euler angles suck for complex memoizing movement.
  • M is your 4x4 camera transform matrix

rotation around global world X axis by ang:

double c=cos(ang),s=sin(ang);
double Q[16]=
    {
    1, 0, 0, 0,
    0, c,-s, 0,
    0, s, c, 0,
    0, 0, 0, 1
    };
M=M*Q;

rotation around local camera X axis by ang:

double c=cos(ang),s=sin(ang);
double Q[16]=
    {
    1, 0, 0, 0,
    0, c,-s, 0,
    0, s, c, 0,
    0, 0, 0, 1
    };
M=((M^-1)*Q)^-1;

there are libraries for transform matrices like glm but i prefer my own

  • I know many will disagree but mine is here longer than any of the other public one
  • and i am used to it
  • the idea is to remember both direct and inverse matrix of M at all times
  • have a flag which one is updated and which not
  • and before any operation check if the used matrix is relevant
  • if not then compute it from the other one
  • also add count of operation and after reach a treshold
  • do orthogonality or orthonormality check/corrections

here you can see the differences between homogenous (4x4) and normal (3x3+1x3) 3D transform matrices:

Now the driving of camera

  • I will refer to my image inside that link above of 4x4 transform matrix
  • I usually use Z axis as a movement/viewing direction
  • so at start reset your matrix to unit or set it to its position and orientation as you need
  • when you want to rotate use local rotations
  • when you want to move just add to position x0,y0,z0 the ofset you want to move (in global coordinates)
  • so for move forward if d units do this:

    x0+=d*Zx;
    y0+=d*Zy;
    z0+=d*Zz;
    
  • for side movement use X vector

  • for up/down use Y vector
  • for rotations different then around X axis just use different Q matrix

  • rotation around Y-axis

     c, 0, s, 0,
     0, 1, 0, 0,
    -s, 0, c, 0,
     0, 0, 0, 1;
    
  • rotation around Z-axis

     c,-s, 0, 0,
     s, c, 0, 0,
     0, 0, 1, 0,
     0, 0, 0, 1;
    

Upvotes: 1

Related Questions