Maths - Rotation about any point - Open forum discussion

By: nobody ( Nobody/Anonymous )
Clarification
2003-05-19 05:09
https://www.euclideanspace.com/maths/geometry/affine/matrix4x4/index.htm

On this site, I am having trouble understanding what sort of values the R(0) matrix will contain?
What is it representing? Is it the matrix to be rotated? or the rotation values?
Why is the rotation a set of triplet values?
I get the impression that the whole process is the generation of the Transformation matrix, that will be combined with the Matrix to be transformed?

Please clarify.

Regards

Tristan


By: martinbaker ( Martin Baker )
RE: Clarification
2003-05-19 09:03
Tristan

Yes I did not make it very clear; I’ll try to clarify in the hope that I don’t make it even more confusing!

R0 is the rotation about the origin, padded out with zeroes and a one as shown.
A 3x3 matrix, as described on the other pages, can define any rotation about the origin.

Whatever point we rotate around makes no difference to this rotation matrix, the only effect of rotating about some other point is that the object will be translated to a different position.

So for example if I rotate an object 30 about the z axis then this could be represented by the following matrix.

0.866 0.5 0
-0.5 0.866 0
0 0 1

If I now want to rotate an object by the same amount but around a point offset from the origin, then the rotation will be the same but we need to include a linier translation (or offset) like this:

0.866 0.5 0 translationX
-0.5 0.866 0 translationY
0 0 1 translationZ
0 0 0 1

So it is this linier translation we are trying to calculate.

Does this make it any clearer? I’m not sure I’m describing it very well, if its still not clear I’ll try to add some diagrams to the web page, I prefer to describe things in pictures rather than words.

Thanks for letting me know the page needs clarifying,

Martin


By: nobody ( Nobody/Anonymous )
RE: Clarification
2003-05-19 17:46
Just checking if I understand this...
there is a seperate matrix format for each X, Y, Z rotation matrix?
much like the rotation Matrix's using the
cos, sin, 0
-cos, sin, 0
0,0,1

and such?

i get from this that a rotation around the Z axis is applied to the X and Y coordinates, Y is affected by X and Z, and X is Z and Y?

First line represents the X Translation / Rotation
2nd line the Y
3rd, the Z?

the
1, 0, 0, x
0, 1, 0, y
0, 0, 1, z
0, 0, 0, 1

is the new origin to be rotated around?

Cheers for help.
Great site..



By: nobody ( Nobody/Anonymous )
RE: Clarification
2003-05-19 17:59
Do you teach at Toynbee Secondary School in hampshire by any chance? I had a maths teacher there called Martin Baker...
Just wondering if this could be a freakish coincidence.

Tristan



By: tristanrhodes ( Tristan Rhodes )
RE: Clarification
2003-05-19 19:11
Ok, I have produced the following algorythm:

static public Matrix RotatePoint(Matrix M, Matrix R, double x, double y, double z) {

Matrix newM = new Matrix(M.size());
//Construct Rotation Matrix
Matrix Inverse = new Matrix(new double[]
{ 1, 0, 0, -x,
0, 1, 0, -y,
0, 0, 1, -z,
0, 0, 0, 1});

//Construct Reverse Matrix
Matrix Reverse = new Matrix(new double[]
{ 1, 0, 0, x,
0, 1, 0, y,
0, 0, 1, z,
0, 0, 0, 1});

// Construct Hybrid Matrix
newM = Multiply(R,Inverse); //Multiply Rotation by Inverse
newM = Multiply(M,newM); //Multiply M by NewM
newM = Multiply(newM,Reverse); //Multiply Reverse by NewM

return newM;
}



By: tristanrhodes ( Tristan Rhodes )
RE: Clarification
2003-05-19 19:13
Where M is the matrix to be manipulated, and R is the rotation Matrix. X, Y Z are the offsets.

However, the offsets have no effect, the object always spins on the origin... this is frustrating.. any ideas why?



By: martinbaker ( Martin Baker )
RE: Clarification
2003-05-19 21:47
I have reworked the webpage and added a couple of diagrams, I hope it makes it clearer?

> the
> 1, 0, 0, x
> 0, 1, 0, y
> 0, 0, 1, z
> 0, 0, 0, 1
>
> is the new origin to be rotated around?

No, x,y and z in this matrix represents the linier translation applied to the object. This will depend on both the centre of rotation and the amount of rotation as given on the webpage.

> Do you teach at Toynbee Secondary School in hampshire by any chance? I had a
> maths teacher there called Martin Baker...

no not me.

> newM = Multiply(R,Inverse); //Multiply Rotation by Inverse
> newM = Multiply(M,newM); //Multiply M by NewM
> newM = Multiply(newM,Reverse); //Multiply Reverse by NewM

This should work, but I assume matrix multiply of 4x4 matrix is quite expensive in terms of CPU time it might be more eficient to use the equivalent single matrix derived on the webpage?

> However, the offsets have no effect, the object always spins on the origin...
> this is frustrating.. any ideas why?

Well the only difference will be the linier translation, ie the components in the 4th column of the matrix (x,y,z in the matrix above). Does you program use these values?
Also are all the matricies that you are using 4x4, could anything be zeroing the translation terms?

Martin



By: nobody ( Nobody/Anonymous )
RE: Clarification
2003-05-20 00:55
Do you have Textpad? I can send you my whole code if you like with the core bit listed. I'm not sure what effect some of the changes are supposed to make...

By: martinbaker ( Martin Baker )
RE: Clarification
2003-05-20 06:43
Tristan

> Do you have Textpad?
No, could I use an ASCII text editor?

>I can send you my whole code if you like
Yes, I would be most grateful for any code that could be included on the website, provided that you could confirm that it does not contain any copyright code, or anything that would get me into trouble if I publish it.

Cheers,

Martin



By: tristanrhodes ( Tristan Rhodes )
RE: Clarification
2003-05-20 11:55
What's your have an e-mail?
My program is in modules... as I'm trying to get my head round OO, but i know most of it works.
It's the rotation around a point that does not seem to work.


By: tristanrhodes ( Tristan Rhodes )
RE: Clarification
2003-05-20 12:14
newM = R;
newM.set (X,3,(((newM.get(X,X) * x) + (newM.get(X,Y) * y) + (newM.get(X,Z) * z)) - x));
newM.set (Y,3,(((newM.get(Y,X) * x) + (newM.get(Y,Y) * y) + (newM.get(Y,Z) * z)) - y));
newM.set (Z,3,(((newM.get(Z,X) * x) + (newM.get(Z,Y) * y) + (newM.get(Z,Z) * z)) - z));

R is the Rotation Matrix, and newM is the new manipulation Matrix. The relevant values in newM (X,3), (Y,3), (Z,3) Where X = 0, Y = 1, Z = 2.

However, this only applies the rotation matrix without the point.



By: martinbaker ( Martin Baker )
RE: Clarification
2003-05-20 15:01
> newM = R;
> newM.set (X,3,(((newM.get(X,X) * x) + (newM.get(X,Y) * y) +
> (newM.get(X,Z)* z)) - x));
> newM.set (Y,3,(((newM.get(Y,X) * x) + (newM.get(Y,Y) * y) +
> (newM.get(Y,Z)* z)) - y));
> newM.set (Z,3,(((newM.get(Z,X) * x) + (newM.get(Z,Y) * y) +
> (newM.get(Z,Z)* z)) - z));
>
> R is the Rotation Matrix, and newM is the new manipulation Matrix.
> The relevant values in newM (X,3), (Y,3), (Z,3) Where X = 0,
> Y = 1, Z = 2.

Looks OK to me, I assume lower case (x,y,z) has already been set to the point you are rotating around.

Martin



By: martinbaker ( Martin Baker )
RE: Clarification
2003-05-20 15:09
> newM = R;
> newM.set (X,3,(((newM.get(X,X) * x) + (newM.get(X,Y) * y) +
> (newM.get(X,Z)* z)) - x));
> newM.set (Y,3,(((newM.get(Y,X) * x) + (newM.get(Y,Y) * y) +
> (newM.get(Y,Z)* z)) - y));
> newM.set (Z,3,(((newM.get(Z,X) * x) + (newM.get(Z,Y) * y) +
> (newM.get(Z,Z)* z)) - z));
>
> R is the Rotation Matrix, and newM is the new manipulation Matrix.
> The relevant values in newM (X,3), (Y,3), (Z,3) Where X = 0,
> Y = 1, Z = 2.

Looks OK to me, I assume lower case (x,y,z) has already been set to the point you are rotating around.
Is R a 3x3 matrix or a 4x4 matrix. If it is 3x3 will newM = R convert correctly between 3x3 and 4x4?

Martin



By: tristanrhodes ( Tristan Rhodes )
RE: Clarification
2003-05-20 19:10
Here are the results of my matrix process to 4dp:

x: 100
y: 100
z: 100

f(x): -10.4829
f(y): 9.4837
f(z): 0.0

MULTIPLY
Base Matrix
26.8198 -13.4422 00.0000 -1662.2308
-40.2621 -13.3776 00.0000 -5363.9799
-13.3776 40.2621 00.0000 8688.4416
00.000 00.0000 00.0000 01.0000

Translation Matrix
00.9950 -00.0998 00.0000 -10.4829 (f(x))
00.0998 -00.9950 00.0000 09.4837 (f(y))
00.0000 00.0000 01.0000 00.0000 (f(z))
00.0000 00.0000 00.0000 01.0000

RESULT
25.3439 -16.0525 00.0000 -2070.8645
-41.3965 -09.2913 00.0000 -5068.7861
-09.2913 41.3965 00.0000 9210.5151
00.0000 00.0000 00.0000 01.0000

Any clues as to what is wrong? I know the x,y,z values are there, but they have no effect, and I know that the matrix multiplication works...


By: tristanrhodes ( Tristan Rhodes )
RE: Clarification
2003-05-20 23:43
From this... i am can say that the x,y,z values have absoloutley no effect on the resultant polygon.

only the 9 values in the top left 3x3 matrix are drawn, and the x,y,z values are not multiplied by any of them. The three values only effect the far right column, which in turn affects nothing, and is not drawn, so they are simply surplus values. Where should they be applied to? Or is the multiplication wrong? (the multiplication algorythm is abstract, and based on the size of the inputted matrixes)... so i don't get it. I know it spins, just without origin change... I'm really quite poor at maths, i just know it doesn't work right mechanicaly...



By: martinbaker ( Martin Baker )
RE: Clarification
2003-05-21 09:47
Tristan,

Normally when we transform a vertex by multiplying its vector by the transform matrix:

v_out0 = [r00 r01 r02 t0][v_in0]
v_out1 [r10 r11 r12 t1][v_in1]
v_out2 [r20 r21 r22 t2][v_in2]
0 [ 0 0 0 1 ][ 0 ]

when we multiply these out gives:

v_out0 = r00*v_in0 + r01*v_in1 + r02*v_in2 + t0
v_out1 = r10*v_in0 + r11*v_in1 + r12*v_in2 + t1
v_out2 = r20*v_in0 + r21*v_in1 + r22*v_in2 + t2

as you can see this adds on the linier translation factor (t0,t1,t2)

What you seem to be doing is representing 3 vectors in a matrix and then multiplying the vectors as follows:

[v_out0a v_out1a v_out2a 0] = [r00 r01 r02 t0][v_in0a v_in0b v_in0c 0]
[v_out0b v_out1b v_out2b 0] [r10 r11 r12 t1][v_in1a v_in1b v_in1c 0]
[v_out0c v_out1c v_out2c 0] [r20 r21 r22 t2][v_in2a v_in2b v_in2c 0]
[0 0 0 1] [ 0 0 0 1 ][0 0 0 1]


when we mulipy this out we get:

v_out0a = r00*v_in0a + r01*v_in1a + r02*v_in2a + t0*0;
v_out0b = r00*v_in0b + r01*v_in1b + r02*v_in2b + t0*0;
v_out0c = r00*v_in0c + r01*v_in1c + r02*v_in2c + t0*0;

v_out1a = r10*v_in0a + r11*v_in1a + r12*v_in2a + t1*0;
v_out1b = r10*v_in0b + r11*v_in1b + r12*v_in2b + t1*0;
v_out1c = r10*v_in0c + r11*v_in1c + r12*v_in2c + t1*0;

v_out2a = r20*v_in0a + r21*v_in1a + r22*v_in2a + t2*0;
v_out2b = r20*v_in0b + r21*v_in1b + r22*v_in2b + t2*0;
v_out2c = r20*v_in0c + r21*v_in1c + r22*v_in2c + t2*0;

This does not seem to produce the same result because the translation factors (t0,t1,t2) all seem to get multiplied by zero but they will get inluded in the elements that do not contain vectors an should be padded out with zeroes.

This is what I am seeing in the printout.

So both the theory and practice seem to be suggesting that it is not valid to represent 3 vectors in one matrix. Therefore I think you need to hold the veticies as seperate vectors and transform them by multiplying the vector by the translation matrix.

Martin


metadata block
see also:

 

Correspondence about this page

Book Shop - Further reading.

Where I can, I have put links to Amazon for books that are relevant to the subject, click on the appropriate country flag to get more details of the book or to buy it from them.

cover 3D Math Primer - Aimed at complete beginners to vector and matrix algebra.

Other Math Books

This site may have errors. Don't use for critical systems.

Copyright (c) 1998-2017 Martin John Baker - All rights reserved - privacy policy.