Rotate Point Around Axis

Hi all,
A bit of a maths question, hoping some trig expert can tell me what I'm doing wrong here...!?
I have a normalised point (x,y,z) representing a face normal. I want to rotate this point around the Y axis by n degrees. My maths isn't realy good enough to come up with the equation on my own, but thanks to the wondering of modern search engines I was able to find this equation. I found the same equation at a few other sites, so I'm assuming its correct...

x' = z * (sin n) + x * (cos n);
y' = y;
z' = z * (cos n) - x * (sin n);

My mel equivalent looks something like this -->

// start mel example

float $pos[];
$pos[0] = 1.0; //
$pos[1] = 0.0; // normalised point
$pos[2] = 0.0; //

float $n = 35.0; // degrees the point will be rotated around Y axis

$pos[0] = $pos[2] * (sin($n)) + $pos[0] * (cos($n));
$pos[2] = $pos[2] * (cos($n)) - $pos[0] * (sin($n));

// end mel example

This example does not give me the desired result...the resulting point is nowhere near where I expected it to be! I know i'm doing something terribly wrong here, but i have no idea what it is...Please help!!! My sanity is at stake here!

Cheers,
Grant.

Maya trigonometric functions accept angle argument in radians, not degrees. You need to convert it:

CODE
float $angle_deg = 90;
print sin( deg_to_rad( $angle_deg ) );

Though what you're doing could work but you should learn to do this using transformation matrices because it's more generalized and flexible ( but it may seem complicated at first ).
The procedure is: you build 4x4 transformation matrix and then multiply point coordinate vectors with it to obtain transformed point.
It's a way how 3d transformations are really done in most software.

CODE

// calculate sin and cos
float $angle = 35;
float $sina = sin( deg_to_rad( $angle ) );
float $cosa = cos( deg_to_rad( $angle ) );

// construct a 4x4 rotation matrix for rotation around y axis
float $m[16]= { $cosa, 0, $sina, 0, 0, 1, 0, 0, -$sina, 0, $cosa, 0, 0, 0, 0, 1 };

// rotate point;
float $point[3] = { 1, 0, 0 };
float $transformedPoint[] = pointMatrixMult( $point, $m );
print( $transformedPoint );

Note that if you want to transform normal vector instead of point coordinate vector you actually need to represent it with 4 dimensional vector ( called homogeneous coordinate ) in a form:
vn = { x,y,z,0 }

Since maya's pointMatrixMult handles only 3-dimensional input you can't really transform normal vectors with it.

Alternatively you can use pointMatrixMult node with enabled vectorMultiply attribute to transform vectors correctly but in that case you'll need to make some kind of node graph setup.

Or as an excersize you could write vector-matrix multiplication procedure that handles 4 dimensional vectors. There is plenty of info on this around the web or in any book on linear algebra.

See, that's why is good to go to school - they force you to learn that kind of boring stuff such as matrix multiplication. Bad thing is they mostly don't tell you what it is good for.

also if its not part of a animation chain you can use

rotate -r -pivot 5 0 0 0 15 0 ;

where the first 3 define pivot.

Or you cana llways moive the pivot and pivcpt translate if its a nimation your geraing to.

PS maya defines sin functions for degrees too for convinence its called sind likewise cosd tand and so on...

Great!
Thanks for taking the time to answer this question, it is very much appreciated!!

I'm yet to give this a go, but i'm sure i can work this out now.

You mention that tranforming a point and a normal vector are quite different. I guess this is my inexperience with such culculations, but I would have thought the 3 values representing a point could be transferable to a vector. the only difference between the two being that a vector has direction and a length and a point representing an absolute position in space. So if you move a point from the origin (0,0,0) in the direction of a vector by the distance of that same vector, your point coordinates will be identical to the vector coordinates. and for a normal vector, you would only need to make sure that the point coordinates, once cast into a vector, had an exact length of 1.0. Forgive me if I have this totally wrong, I'm just trying to wrap my head around this so I don't have to ask anymore dumb questions... Also, I don't doubt what your saying, as you obviously know more about this than I do.

Thanks again!

QUOTE(Joojaa @ 11/13/05, 01:16 PM)
PS maya defines sin functions for degrees too for convinence its called sind likewise cosd tand and so on...

I should really start to rtf that reference manual

Transforming normal and point is the same thing but only in limited subset of cases - precisely - when transformation matrix doesn't include translation, non-uniform scaling or skewing. If it does - then normal vector won't be transformed correctly. Read this for brief intro to problem

But if you just rotate the vectors the way you do using trigonometry then it doesn't matter. It's an issue when performing arbitrary normal transformations via matrix multiplication.

Nice one...

You guys have been a huge help, thanks for your time!!