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

angle difference between two orientations in R³

Tags: None
(comma "," separated)
bennih
Registered Member
Posts
21
Karma
0
OS
Hello!

Currently iam writing my Bachelor Thesis in Electronical Engineering and i had to program with Eigen.
I use Eigen mostly for geometric transformations in R³ space.

I represent a orientation by 2 vectors. A front and a up vector (i think similar to the viewpoint in openGL).
They are normalized, perpendicular and have their coordinate origin at (0,0,0)
Everythink works fine so far.

My Problem is, i had to write a function, which returns the difference between 2 orientations.
The best thing would be a rotations matrix, which transforms the first orientation into the other, but i have really no clue how to get this rotation matrix.

Is there a common algorithm or function i have overseen?

Thanks for any help!

Greetings
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
Form your full basis into 3x3 matrices B1 and B2, and then what your are looking for is simply B2 * B1.transpose().
bennih
Registered Member
Posts
21
Karma
0
OS
Hi,

thats not exactly what i was looking for.
But thank you anyway! good support here.

But I've solved my problem.

Greetings
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
hm, then please post your solution.
bennih
Registered Member
Posts
21
Karma
0
OS
no problem.

I divide the difference between 2 orientation into 2 rotations.

The first rotates the front vector of orientation1 into the front vector of orientation2.
For this I use "AngleAxis". I get the angle from the dot product of the front vectors (change formula to the angle).
And I get the axis to rotate from the cross product of the front vectors.

After the front vectors of orientation1 and orientation2 are in the same position i do the same thing with the upvector.

Finally i multiply the two rotations and i get the transformation to transform orientation1 into orientation2. :D

Sry for my bad english. Iam from germany
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
ok, then I well understood your question and my solution is simpler and faster (no trigo):
Code: Select all
Matrix3f R1, R2, Rdiff;
R1 << up1, front1, up1.cross(front1);
R2 << up2, front2, up2.cross(front2);
Rdiff = R2 * R1.transpose();
bennih
Registered Member
Posts
21
Karma
0
OS
Thank your sir!

Your solution is much better!

could you post a link (wikipedia or something), where I can understand your formula.
I would like to understand why this works.

greetings
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
You have to understand what a basis is an that a unitary (or orthonormal) basis is the same as a rotation matrix. For instance, the matrix R1 stores as column your basis (up,front,left)_1. R1 * p transforms a point p expressed in your basis into the world space Since R1 is orthonormal, you can see it as the rotation that transforms the basis 1,0,0 ; 01,0 ; 0,0,1 to (up,front,left)_1. So to get the rotation difference between your two bases you simply cancel the first one and then apply the second one. Also recall that for a unitary matrix, its inverse is simply its transpose. Hope that helps.
bennih
Registered Member
Posts
21
Karma
0
OS
After reading some articles and watching some youtube videos about it, I understand it well enough to handle it.

Thank for your advice!


Bookmarks



Who is online

Registered users: Baidu [Spider], Bing [Bot], Google [Bot]