This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Modifying the rotation part of an Affine3d transformation

Tags: None
(comma "," separated)
linello
Registered Member
Posts
56
Karma
0
OS
Hi,

I'm trying to overwrite the rotational part of a given Affine3d transformation with a custom Matrix3d.

Here is an example:

Code: Select all
Affine3d transformation=Affine3d::Identity();
transformation.translation() = Vector3d::UnitY(); //Here is everything ok

// but when I try this:
transformation.rotation() = AngleAxis<double>aa(M_PI/6,Vector3d::UnitX());


This doesn't compile, and I understand why, but I'm wondering if in the Affine3d transform is possible to reference directly the Matrix3d part (which is the top left corner of the 4x4 matrix)

I must use a workaround for this code:

Code: Select all
transformation.matrix().topLeftCorner<3,3>()=AngleAxis<double>aa(M_PI/6,Vector3d::UnitX()).toRotationMatrix();


but I think this is very ugly and probably slower...

Is there a simpler way to modify directly the rotational part of the affine transformation? Documentation doesn't say much about this argument...

Thanks in advance, and again compliments for the spectacular library!
Waxwing
Registered Member
Posts
10
Karma
0
OS
The answer is here under the Geometry Tutorial.
http://eigen.tuxfamily.org/dox/TutorialGeometry.html

Just concatenate your affine operations:

Code: Select all
Transform<float,3,Affine> t = Translation3f(p) * AngleAxisf(a,axis) * Scaling3f(s);
linello
Registered Member
Posts
56
Karma
0
OS
Waxwing wrote:The answer is here under the Geometry Tutorial.
http://eigen.tuxfamily.org/dox/TutorialGeometry.html

Just concatenate your affine operations:

Code: Select all
Transform<float,3,Affine> t = Translation3f(p) * AngleAxisf(a,axis) * Scaling3f(s);


Ok, I know this can be a solution but I didn't want to create a temporary here, only overwrite a piece of a matrix with another given matrix..
linello
Registered Member
Posts
56
Karma
0
OS
linello wrote:
Waxwing wrote:The answer is here under the Geometry Tutorial.
http://eigen.tuxfamily.org/dox/TutorialGeometry.html

Just concatenate your affine operations:

Code: Select all
Transform<float,3,Affine> t = Translation3f(p) * AngleAxisf(a,axis) * Scaling3f(s);


Ok, I know this can be a solution but I didn't want to create a temporary here, only overwrite a piece of a matrix with another given matrix..


Ok, I found the solution:

Code: Select all
transformation.linear() = (AngleAxis<double>(M_PI/6,Vector3d::UnitY())*AngleAxis<double>(M_PI/6, Vector3d::UnitX())).toRotationMatrix();


This acts only on the linear part of the transformation, that in the case of an Affine transformation is the rotation
Waxwing
Registered Member
Posts
10
Karma
0
OS
Good.

Btw, you can use AngleAxisd instead of the more cumbersome AngleAxis<double>.

Code: Select all
transformation.linear() = ( AngleAxisd(M_PI / 6, Vector3d::UnitY()) * AngleAxisd(M_PI / 6, Vector3d::UnitX()) ).toRotationMatrix();


Bookmarks



Who is online

Registered users: bartoloni, Bing [Bot], Google [Bot], Yahoo [Bot]