## what is the matrix ?

### what is the matrix ?

Dear all,

What is the matrix form of rotation about a vector ?
For example, I would like to rotate A degree about vector (x,y,z) , what

is the matrix to do this ?
I do know the matrix form for rotate about x, y or z axis, but I

had done my best to think and find the above one, and failed. I think it

Thanks ,
Raymond Pang

### what is the matrix ?

> Dear all,

>         What is the matrix form of rotation about a vector ?
> For example, I would like to rotate A degree about vector (x,y,z) , what

> is the matrix to do this ?
>         I do know the matrix form for rotate about x, y or z axis, but I

> had done my best to think and find the above one, and failed. I think it

with opengl I think you can use glRotate(angle,x,y,z)
where angle is the rotation angle and x,y,z your vector.
--
~
Luca 'Sore' Marchetti
ICQ  52464923

### what is the matrix ?

Not sure if this is what you're after, since it seems a bit of a hack,
but there's notes about arbitrary axis rotation at:

http://www.maths.bath.ac.uk/~pjw/NOTES/graphics/node60.html

Howard Kistler

Quote:>Dear all,

>        What is the matrix form of rotation about a vector ?
>For example, I would like to rotate A degree about vector (x,y,z) , what

>is the matrix to do this ?
>        I do know the matrix form for rotate about x, y or z axis, but I

>had done my best to think and find the above one, and failed. I think it

>Thanks ,
>Raymond Pang

### what is the matrix ?

> Dear all,

>         What is the matrix form of rotation about a vector ?
> For example, I would like to rotate A degree about vector (x,y,z) , what

> is the matrix to do this ?
>         I do know the matrix form for rotate about x, y or z axis, but I

> had done my best to think and find the above one, and failed. I think it

Find the source code for mesa OpenGL...

--
<\___/>
/ O O \
\_____/  FTB.

### what is the matrix ?

Unfortunately, nobody can be told what the matrix is. However, if you eat
this pill I can show you...

### what is the matrix ?

> > Dear all,

> >         What is the matrix form of rotation about a vector ?
> > For example, I would like to rotate A degree about vector (x,y,z) , what

> > is the matrix to do this ?
> >         I do know the matrix form for rotate about x, y or z axis, but I

> > had done my best to think and find the above one, and failed. I think it

> with opengl I think you can use glRotate(angle,x,y,z)
> where angle is the rotation angle and x,y,z your vector.
> --

this will rotate all objects around a vector (line) from the origin
(0,0,0) to the point x,y,z. in the case a rotation around a vector
(line) from x1,y1,z1 to x2,y2,z2 first translate then rotate:

glTranslate(x1,y1,z1)
glRotate(angle,x2,y2,z2)

### what is the matrix ?

somebody had to say it ... hehe

Shane
db_wolf

### what is the matrix ?

I belive that the original question was how to construct the rotationmatrix
for it, not how to use an API-call.
Actually, I would like to know that to! :-)

/Johannes

### what is the matrix ?

> I belive that the original question was how to construct the rotationmatrix
> for it, not how to use an API-call.
> Actually, I would like to know that to! :-)

> /Johannes

I think this should work to create a rotation transformation that
carries a point a given angle around a given vector.  In this case a
vector named ptline.  Also check the handedness of your coordinate
system which will affect the plus and minus signs used.  The code below
was modified for a left-handed setup.  It's been a while since I wrote
this, so hopefully I got a good rev of the code:

/* Calculate angle theta. */
a = ((double)angle)*(PI/180.0);
sina = sinf(a);
cosa = cosf(a);

l =
sqrt(ptLine*ptLine+ptLine*ptLine+ptLine*ptLine);
if (l==0.0)
return 1;
u1 = ptLine[X]/l;
u2 = ptLine[Y]/l;
u3 = ptLine[Z]/l;

/* Should combine some multiplications in the code below. */
matTrans = u1*u1+cosa*(1-u1*u1);
matTrans = u1*u2*(1-cosa)+u3*sina;/* Note [FAUX79] had -sina.
*/
matTrans = u3*u1*(1-cosa)-u2*sina;/* Note [FAUX79] had +sina.
*/

matTrans = u1*u2*(1-cosa)-u3*sina;/* Note [FAUX79] had +sina.
*/
matTrans = u2*u2+cosa*(1-u2*u2);
matTrans = u2*u3*(1-cosa)+u1*sina;/* Note [FAUX79] had -sina.
*/

matTrans = u3*u1*(1-cosa)+u2*sina;/* Note [FAUX79] had -sina.
*/
matTrans = u2*u3*(1-cosa)-u1*sina;/* Note [FAUX79] had +sina.
*/
matTrans = u3*u3+cosa*(1-u3*u3);

matTrans = 0.0;
matTrans = 0.0;
matTrans = 0.0;

matTrans = 0.0;
matTrans = 0.0;
matTrans = 0.0;
matTrans = 1.0;

### what is the matrix ?

Quote:> Unfortunately, nobody can be told what the matrix is. However, if you eat
> this pill I can show you...

Darn... You beat me to it :)

--
----
-----------------------------------------------------------------------
[Insert joke here.]                                                       ----
--

### what is the matrix ?

> I belive that the original question was how to construct the rotationmatrix
> for it, not how to use an API-call.
> Actually, I would like to know that to! :-)

--
<\___/>
/ O O \
\_____/  FTB.

### what is the matrix ?

Quote:> Unfortunately, nobody can be told what the matrix is. However, if you eat
> this pill I can show you...

Or, unfortunately, no one can be told what the matrix is. You have to RTFM
yourself. =^)

-jukka

### what is the matrix ?

> Dear all,

>         What is the matrix form of rotation about a vector ?
> For example, I would like to rotate A degree about vector (x,y,z) , what

> is the matrix to do this ?
>         I do know the matrix form for rotate about x, y or z axis, but I

> had done my best to think and find the above one, and failed. I think it

> Thanks ,
> Raymond Pang

hi,

http://www.flipcode.com/documents/matrfaq.html

__
/ /    __  _  _  _  _ __  __
/ /__  / / / \// //_// \ \/ /           -o)
/____/ /_/ /_/\/ /___/  /_/\_\           /\\
...for IQs GREATER than 98...          _\_v-

### what is the matrix ?

Sorry, can't find the original thread, but I thought I could help.

> >         What is the matrix form of rotation about a vector ?

Firstly, let's understand that to rotate about a vector, you are actually
rotating along the surface of the plane perpendicular to that vector.  And
you are implicitly rotating about the origin.  The vector can only specify
direction, not position.  If you wish to rotate about any arbitrary point,
obviously you need to transform before and after the rotation about the
origin. But in any case this problem is : Rotate about the origin
within the plane perpendicular to (x,y,z).  I'm assuming that the point is
actually within that plane.  If it's not, then you should find the
simultaneous equation of the plane and the point's projection onto that
plane, to make it so.

Quote:> > For example, I would like to rotate A degree about vector (x,y,z) , what

> > is the matrix to do this ?
> >         I do know the matrix form for rotate about x, y or z axis, but I

> > had done my best to think and find the above one, and failed. I think it

There is a matrix to do this, and I don't have it to hand.  But it is
derived from the common-sense method -

The vector defines the normal to a plane.  You are rotating on the surface
of that plane.  So you should transform your point from normal coordinates
into coordinates which transform the (x,y,z) plane into the xy plane (ie
z=0).

Now you have a new two-dimensional coordinate system where the z-axis is
perpendicular to the plane about which you rotate.  Note that the
z-dimension of your point must be zero (remember your point is on the
plane about which you are rotating - and if it's not then you need to
handle it separately, or else do the transform outside the rotate as I
suggested.

You then rotate about the z-axis using the conventional 2x2 matrix, then
transform the x and y coordinates back to the original coordinate system
again.  Separately, transform your z-coordinate back into normal
coordinates if your point wasn't on the original plane.

I don't know how to optimize this, but I'm sure it would be delightful
fun.  When you transform the points, you would shear rather than
calculate the plane equation.  All of your calculations would be linear
except for one trig look-up (for the rotation matrix)

This would work in all cases except where the vector about which you want
to rotate is in the xy plane (ie the point is on the z-axis).  In that
case, you would map the point onto the yz plane instead.

This sounds rather complex to me, but it's an exercise in visualisation.
Anytime you need to do tricky rotations, just transform until your
coordinate system is much simpler, then rotate, then transform back.

OpenGL would be able to do all of this automatically, of course, with a
series of modelview calls, so you don't need to know the actual matrix
formula - or you can do it yourself on paper if you can understand this
rant.

Richard.

--
Check that new website bout' MATRIX!!!!!!!!!!!!!!!!!!!!