What does Transform::linear() return in the Eigen library?
Asked Answered
H

2

12

With the Eigen C++ library, I'm having trouble understanding the Transform::linear() function. According to the documentation, it returns the linear part of the transformation. But what does this mean? Surely all matrix transformations are linear?

Furthermore, from seeing some examples elsewhere, it seems that the value it returns is an Eigen::Matrix3d (or can be implicitly converted to this). To me, this suggests that it might be returning just the rotation part of the transformation, which is of length 3 (x, y and z). However, there is also a Transform::rotation() function, which according to the documentation returns the rotation part of the transformation.

So can somebody explain to me what Transform::linear() actually returns?

Harangue answered 15/2, 2016 at 18:49 Comment(0)
I
11

The class Transform represents either an affine or a projective transformation using homogenous calculus. For instance, an affine transformation A is composed of a linear part L and a translation t such that transforming a point p by A is equivalent to:

 p' = L * p + t

Using homogeneous vectors:

 [p'] = [L t] * [p] = A * [p]
 [1 ]   [0 1]   [1]       [1]

with:

 A = [L t]
     [0 1]

So the linear part correspond to the top-left corner of the homogenous matrix representation. It corresponds to a mix of rotation, scaling and shearing.

Investigator answered 15/2, 2016 at 21:5 Comment(1)
Do you mean the top-left corner of the homogenous matrix?Harangue
S
17

Having come across the same question, I would like to add the following information:

As explained by @ggael, Transform::linear() directly returns the linear part in the transformation matrix.

Transform::rotation() returns the rotational component in the linear part. But since the linear part contains not only rotation but also reflection, shear and scaling, extracting the rotation isn't straight forward, and needs to be calculated using a singular value decomposition (SVD).

In the common case where the affine matrix is known to contain only rotation and translation then Transform::linear() can be used to efficiently access the rotation part.

Finally, if you set the Transform's Mode template parameter to Isometry, Eigen will assume only rotations and translations, and optimize calculation of the inverse transform. The latest versions of Eigen will also optimize Transform::rotation() in that case, and directly return the linear part. Note, however, that there isn't a compact version of isometric affine matrices, where the last row isn't stored and assumed to be [0 ... 0 1].

Synovitis answered 3/11, 2019 at 13:31 Comment(2)
As someone uses rotation and translation only I found this answer better. Thanks.Torques
Where can I find documentation on the rotation() automatic optimization? I haven't found anything in Eigen docs or changelog...Prudi
I
11

The class Transform represents either an affine or a projective transformation using homogenous calculus. For instance, an affine transformation A is composed of a linear part L and a translation t such that transforming a point p by A is equivalent to:

 p' = L * p + t

Using homogeneous vectors:

 [p'] = [L t] * [p] = A * [p]
 [1 ]   [0 1]   [1]       [1]

with:

 A = [L t]
     [0 1]

So the linear part correspond to the top-left corner of the homogenous matrix representation. It corresponds to a mix of rotation, scaling and shearing.

Investigator answered 15/2, 2016 at 21:5 Comment(1)
Do you mean the top-left corner of the homogenous matrix?Harangue

© 2022 - 2024 — McMap. All rights reserved.