Flip and rotate matrix

25 views (last 30 days)
Diego Hens
Diego Hens on 10 Nov 2020
Commented: Bjorn Gustavsson on 10 Nov 2020
Hello,
this is a mathematical question, probably very easy for some people, but I want to make sure my solution is correct.
I have a matrix of points P with three columns (for x, y and z coordinates) and tons of rows, let's say one thousand ,but the number really doesn't matter.
I have to flip this matrix P and rotate it with given flipping (let's call it F) and rotation (let's call it R) matrices. A flip of the x-coordinates wo be a matrix as in [-1 0 0; 0 1 0; 0 0 1], for example. The roation matrix is also a 3x3 matrix, but not so simple as that (but it's given).
I would like to unite these two matrices in one for future calculations and I'm not sure if the multiplication of the two would be correct, as in:
flip_and_rotate = R * F %R is for the Rotation and F for the flipping
I'm aware that when rotating the order of rotations is important. It's not the same to rotate first in x and then in y as the other way around. Does this matter here?
Thank you.
Edit:
I'll add an example:
P = [ 1 1 0] % This is my point, just one instead of 1000
F = [-1 0 0; 0 1 0; 0 0 1]
T = [0.9999,-0.0097,-0.001;0.0095,0.9998,-0.0160;0.0101,0.01593,0.9998]
First comes the flipping, then the rotation:
Flipping = F * transpose(P)
Rotation = ]The result is [-1.009600000000000;0.990300000000000;0.005830000000000]
  2 Comments
Bjorn Gustavsson
Bjorn Gustavsson on 10 Nov 2020
Yes, that looks right. As Walter illustrated what I suggested, the operations do not commute, as long as you remember which order they are done you'll be fine. (memory is of crucial importance here, in my experience, if this is something you'll do over and over again wrap it into a function that you write a very clear help-section for. Before I did that the rotation-function was something I had to redo on a semi-yearly basis...).
Diego Hens
Diego Hens on 10 Nov 2020
Edited: Diego Hens on 10 Nov 2020
It seems that my question window is bugged and I cannot write in it without it getting crazy. I'm sorry for the inconvenience.
I postet my sy solution, but now I don't remember what it is and I of course did not save it...
Thank you for the answers though :)

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 10 Nov 2020
format short g
F = [-1 0 0; 0 1 0; 0 0 1]
F = 3×3
-1 0 0 0 1 0 0 0 1
R4 = makehgtform('zrotate', -pi/4); %counter-clockwise 45 degrees
R3 = R4(1:3,1:3);
P = [1, 1, 1]; %[X Y Z]
P*R3 % / ends up ^
ans = 1×3
1.1102e-16 1.4142 1
P*F %flip, / ends up \
ans = 1×3
-1 1 1
P*F*R3 %flip then rotate, / becomes \ then rotates to <-
ans = 1×3
-1.4142 1.1102e-16 1
P*R3*F %rotate then flip, / rotates to ^ then flips to v
ans = 1×3
-1.1102e-16 1.4142 1
  5 Comments
Bruno Luong
Bruno Luong on 10 Nov 2020
Edited: Bruno Luong on 10 Nov 2020
Don't know since I don't read the question entirely. Simply answer
"It is then not possible to get the same result as in P*F*R3 with just one matrix?"
Note that all rotation matrix has determinant 1, flip has determinant -1. So one cannot represent a flip by a rotation. The group SO(3) is not O(3). R3 is in SO(3), F is not. Bothe are in O(3).
Bjorn Gustavsson
Bjorn Gustavsson on 10 Nov 2020
@Bruno, I refered to Walter's answer.

Sign in to comment.

More Answers (1)

Bjorn Gustavsson
Bjorn Gustavsson on 10 Nov 2020
In my experience, it is best to test whether the flipping and rotation operations commute with a small enough example - do it with pen (or pencil) and paper. Take for example a point [1 1 0] and rotate it around [0 0 1] by pi/3 before and after flipping the x-component.
That test will give you the answer.
HTH

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!