For all issues regarding the Forums use, please, refer to the Forum Rules.

Our Solutions

Need professional assistance?
Consider our:

Support Offerings

 

Need to speed up your development?
Have a look at our:

Samples & Tools

 

Need some functionality extending standard OCCT capabilities?
Check out our:

Adv. Components

Related pages

Homography matrix

Adriana Costas's picture
Forums: 

Hello,

I'm taking different views of a TopoDS_Shape created from the reading of a STEP file. To do that, I'm moving the camera around X, Y and Z world axis establishing the look-at point (center view) always at the center of mass of the shape. Now I need to calculate the homogeneous matrix (4x4) that transform points from the View Coordinate system into the camera coordinate system. How can I do that?

Another question, is it possible to change the location of the world coordinate system to the center of mass of the shape and then calculate the homogeneous matrix directly between the world coordinate system and the camera system?

Thanks!

Kirill Gavrilov's picture

The transformations in OCCT are defined by gp_Trsf class, which can be initialized in various ways, including translation and transformation from one coordinated system to another (defined by gp_Ax2/gp_Ax3 classes).
gp_Trsf::GetMat4() method can be used to define a 4x4 matrix (used in visualization), while gp_Trsf stores transformation in decomposed way.

Adriana Costas's picture

Hello,

Now I'm dealing with the opposite problem. How can I define a gp_Trsf from a given matrix 4x4?

Thanks!

Kirill Gavrilov's picture

Arbitrary 4x4 transformation matrix cannot be represented by gp_Trsf - see documentation of this class.
4x3 transformation matrix can be initialized using gp_Trsf::SetValues() method.

Adriana Costas's picture

And then, why does the method GetMat4 exist? If I use the three first columns of this matrix in the function SetValues, should I get the correct result?

Kirill Gavrilov's picture

You should read about transformation matrices (as well as documentation of related OCCT classes).

4x3 matrix is a convenient way for storing 4x4 matrix with one row being (0, 0, 0, 1), e.g. as in identity matrix - and this is what gp_Trsf::GetMat4() will return.
This is enough for a "normal" transformation, where 3x3 matrix within 4x3 stores rotation part (and scale) and the 4th column stores translation part.

Obviously, the arbitrary 4x4 matrix cannot fit into 4x3. For example, perspective projection matrix cannot be defined by gp_Trsf (and is not supposed to).