2
$\begingroup$

In the world coordinate system, there are objects with rotation values rx1,ry1,rz1 and position values px1,py1,pz1.

Similarly, there is a camera in the world coordinate system with rotation values rx2,ry2,rz2 and position values px2,py2,pz2.

What formula can be used to convert rx1,ry1,rz1,px1,py1,pz1 to the camera coordinate system?

The up vector of the camera is the Y-axis, always oriented toward the object near the world origin.

The camera and the model are supposed to move within the range as shown in the following gif image. enter image description here

I would like to calculate this with Python, but any answers, including mathematical statements, are welcome.

$\endgroup$

1 Answer 1

2
$\begingroup$

Generally the values $\vec{rx1},\vec{ry1},\vec{rz1}$ are themselves vectors. Each with an $(x,y,z,w)$ take special note of the $w$ value. The position values would also have $(x,y,z,w)$ values. The $w$ value for the vectors would be $0$ and it would be $1$ for the position. Together they make up an affine transformation which is a 4x4 matrix.

It sounds like you have the camera matrix already, sometimes called the view matrix. After being set up it generally transforms objects from world space into camera space. Affine transformations are invertible, once inverted they transform in the opposite direction. For example a 4x4 affine transformation matrix that transforms from world space to camera space can be inverted to transform from camera space to world space.

So the transformation formula is simply:

worldtocamera = inverse(cameratoworld)

Also, this transformation generalizes very nicely. For example the transformation from model to world combined with world to camera is:

modeltocamera = modeltoworld * worldtocamera

And the reverse is again simply:

cameratomodel = inverse(modeltocamera)
$\endgroup$
1
  • $\begingroup$ An alternative is, to use quaternions for orientation. $\endgroup$
    – Thomas
    Jan 7 at 18:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.