By: nobody ( Nobody/Anonymous )
Rorating Around A Vector
20030519 03:03
I have used the following page:
https://www.euclideanspace.com/maths/algebra/matrix/orthogonal/rotation/index.htm
for the algorythm to enable rotation around a Vector. I am currently aware
that my Matrix maths base functions as I can rotate around each individual axis,
and scale specific axis without issues. However, with the vector rotation, there
seems to be a massive scaling factor, as the object baloons to a rediculous
size.
I am assuming that If i draw the Vertex that I am using as the axis, it will
lie through the origin of the triangle / matrix. My algorythm is as follows
(And I know all the sub methods work).
static public Matrix VectorRotate(Matrix M, Vector V, double A) {
double x,y,z;
x = ((Double)V.get(0)).doubleValue();
y = ((Double)V.get(1)).doubleValue();
z = ((Double)V.get(2)).doubleValue();
Matrix Rotate = new Matrix(new double[]
{ (1+(1Math.cos(A))*(x*x1)), (z*Math.sin(A)+(1Math.cos(A))*x*y), (y*Math.sin(A)+(1Math.cos(A))*x*z),
(z*Math.sin(A)+(1Math.cos(A))*x*y), (1 + (1Math.cos(A))*(y*y1)), (x*Math.sin(A)+(1Math.cos(A))*y*z),
(y*Math.sin(A)+(1Math.cos(A))*x*z), (x*Math.sin(A)+(1Math.cos(A))*y*z), (1
+ (1Math.cos(A))*(z*z1))});
return Multiply(M,Rotate);
}
By: nobody ( Nobody/Anonymous )
RE: Rorating Around A Vector
20030519 03:47
Neatened Version:
(((1Math.cos(A))*(x*x)) + Math.cos(A)),
(((1Math.cos(A))*(x*y))  (z*Math.sin(A))),
(((1Math.cos(A))*(x*z)) + (y*Math.sin(A))),
(((1Math.cos(A))*(x*y)) + (z*Math.sin(A))),
(((1Math.cos(A))*(y*y)) + Math.cos(A)),
(((1Math.cos(A))*(y*z))  (x*Math.sin(A))),
(((1Math.cos(A))*(x*z))  (y*Math.sin(A))),
(((1Math.cos(A))*(y*z)) + (x*Math.sin(A))),
(((1Math.cos(A))*(z*z)) + Math.cos(A))});
I am using a 3x3 matrix for this process.
By: martinbaker ( Martin Baker )
RE: Rorating Around A Vector
20030519 03:47
The algorithm that you are using assumes that Vector V is unit length.
If it is possible that this is not unit length then you should normalise it first.
Martin
By: nobody ( Nobody/Anonymous )
RE: Rorating Around A Vector
20030519 03:54
Neater Version:
(((1Math.cos(A))*(x*x)) + Math.cos(A)),
(((1Math.cos(A))*(x*y))  (z*Math.sin(A))),
(((1Math.cos(A))*(x*z)) + (y*Math.sin(A))),
(((1Math.cos(A))*(x*y)) + (z*Math.sin(A))),
(((1Math.cos(A))*(y*y)) + Math.cos(A)),
(((1Math.cos(A))*(y*z))  (x*Math.sin(A))),
(((1Math.cos(A))*(x*z))  (y*Math.sin(A))),
(((1Math.cos(A))*(y*z)) + (x*Math.sin(A))),
(((1Math.cos(A))*(z*z)) + Math.cos(A))});
I do not understand why this causes scaling..
If i input a vector of 0,0,0. The matrix shrinks slowly. Any value above 1.00X
causes the matrix to explode by a few hundred % per second.
While it does rotate around the desired axis, the scaling is unrequired, and
I don't know why?
Should I be using a 4x4 matrix for this?
By: nobody ( Nobody/Anonymous )
RE: Rorating Around A Vector
20030519 04:32
Normalise the polygon? or the Vector?
Gona experiment with the Vector 1st :)
Cheers
By: martinbaker ( Martin Baker )
RE: Rorating Around A Vector
20030519 09:02
> Normalise the polygon? or the Vector?
> Gona experiment with the Vector 1st
Normalise the vector which is input to this method, ie you could start your method like this:
static public Matrix VectorRotate(Matrix M, Vector V, double A) {
double x,y,z;
x = ((Double)V.get(0)).doubleValue();
y = ((Double)V.get(1)).doubleValue();
z = ((Double)V.get(2)).doubleValue();
double n = Math.sqrt(x*x + y*y + z*z);
x /= n;
y /= n;
z /= n;
The reason I did not do this is that I assumed for axisangle the axis would already be normalised.
Thank you to the person who sent the neatened version, Ill include that on the website if that’s alright?
On the other question, a 4x4 matrix is only required if you want to include a linier translation as well as a rotation (such as when you are rotating about a point other than the origin (see message from Tristan).
Cheers
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. 
Mathematics for 3D game Programming  Includes introduction to Vectors, Matrices, Transforms and Trigonometry. (But no euler angles or quaternions). Also includes ray tracing and some linear & rotational physics also collision detection (but not collision response). 
Terminology and Notation Specific to this page here: 

This site may have errors. Don't use for critical systems.
Copyright (c) 19982023 Martin John Baker  All rights reserved  privacy policy.