how can i rotate a vector by a certain amount of degrees ?
is it possible or do i have to rotate the vector by a matrix ?

# 3d vector rotation

Started by IStrikerI, Aug 24 2001 05:43 AM

4 replies to this topic

###
#2
Members - Reputation: **122**

Posted 26 August 2001 - 06:39 AM

this was done for a java applet the formula is fine if i could only get the damn kinks out of the rest of the applet

here xa,ya,za is the point of the vertice loades in from a array 1 at a time hope it helps

Xa=Xp[vv][v];

Ya=Yp[vv][v];

Za=Zp[vv][v];

// improvised on the rotation formula because

// all the examples for simultaneous operations were for matrixes only

// this is a simultaneous operation on all 3 axis without a matrix

//System.out.println( "*********x*y*z*rotating on the axis''es" );

// rotate on the z axis

Xb = (int)(Xa * Math.cos(radiansZ) - Ya * Math.sin(radiansZ) );

Yb = (int)(Ya * Math.cos(radiansZ) + Xa * Math.sin(radiansZ) );

// rotate on the x axis

Yb = (int)(Yb * Math.cos(radiansX) - Za * Math.sin(radiansX) );

Zb = (int)(Yb * Math.sin(radiansX) + Za * Math.cos(radiansX) );

// rotate on the y axis

Zb = (int)(Zb * Math.cos(radiansY) - Xb * Math.sin(radiansY) );

Xb = (int)(Zb * Math.sin(radiansY) + Xb * Math.cos(radiansY) );

// place into temp array for drawing manipulation

// add a screen offset so its not spining around coordinates 0,0 x y

Xtemp[v] = Xb+off_set;

Ytemp[v] = Yb+off_set;

Ztemp[v] = Zb;

here xa,ya,za is the point of the vertice loades in from a array 1 at a time hope it helps

Xa=Xp[vv][v];

Ya=Yp[vv][v];

Za=Zp[vv][v];

// improvised on the rotation formula because

// all the examples for simultaneous operations were for matrixes only

// this is a simultaneous operation on all 3 axis without a matrix

//System.out.println( "*********x*y*z*rotating on the axis''es" );

// rotate on the z axis

Xb = (int)(Xa * Math.cos(radiansZ) - Ya * Math.sin(radiansZ) );

Yb = (int)(Ya * Math.cos(radiansZ) + Xa * Math.sin(radiansZ) );

// rotate on the x axis

Yb = (int)(Yb * Math.cos(radiansX) - Za * Math.sin(radiansX) );

Zb = (int)(Yb * Math.sin(radiansX) + Za * Math.cos(radiansX) );

// rotate on the y axis

Zb = (int)(Zb * Math.cos(radiansY) - Xb * Math.sin(radiansY) );

Xb = (int)(Zb * Math.sin(radiansY) + Xb * Math.cos(radiansY) );

// place into temp array for drawing manipulation

// add a screen offset so its not spining around coordinates 0,0 x y

Xtemp[v] = Xb+off_set;

Ytemp[v] = Yb+off_set;

Ztemp[v] = Zb;