I have 2 points origins(P1 and P2) and a third point(P3) that is at distance N from P2. Now what i want to make is to rotate P3 around P2 at X angles. Made a lot of researches and searches but didn't understand so much because of my lack of maths ;s if anyone around knows an answer then thank you.
Some useful info?
http://ami.ektf.hu/uploads/papers/fi...om175to186.pdf
Seems like i need rotation matrix / Rodrigues fomula, but i can't find any c/c++ translated functions and practical example to make this work.
Here i have some code that i've found but it doesn't appear to work as intended...
Spoiler
PHP Code:
float vec [ 3 ]; SubtractVectors ( P1 , P2 , vec ); //don't know exactly what vector to subtract? >.> float newp [ 3 ]; //origin after rotation float rotation [ 4 ][ 4 ]; SetupMatrix ( 90.0 , vec , rotation ); MultiplyMatrix ( nright , rotation , newp ); stock void MultiplyMatrix ( float input [ 3 ], float rotation [ 4 ][ 4 ], float output [ 3 ]) { float input2 [ 4 ]; input2 [ 0 ] = input [ 0 ]; input2 [ 1 ] = input [ 1 ]; input2 [ 2 ] = input [ 2 ]; input2 [ 3 ] = 1.0 ; float output2 [ 4 ]; for( int i = 0 ; i < 4 ; i ++) { for( int j = 0 ; j < 4 ; j ++) { output2 [ i ] += rotation [ i ][ j ] * input2 [ j ]; } } output [ 0 ] = output2 [ 0 ]; output [ 1 ] = output2 [ 1 ]; output [ 2 ] = output2 [ 2 ]; } stock void SetupMatrix ( float angle , float vector [ 3 ], float rotation [ 4 ][ 4 ]) { float L = ( vector [ 0 ] * vector [ 0 ] + vector [ 1 ] * vector [ 1 ] + vector [ 2 ] * vector [ 2 ]); angle = angle * M_PI / 180.0 ; //degrees? float u2 = vector [ 0 ] * vector [ 0 ]; float v2 = vector [ 1 ] * vector [ 1 ]; float w2 = vector [ 2 ] * vector [ 2 ]; rotation [ 0 ][ 0 ] = ( u2 + ( v2 + w2 ) * Cosine ( angle )) / L ; rotation [ 0 ][ 1 ] = ( vector [ 0 ] * vector [ 1 ] * ( 1 - Cosine ( angle )) - vector [ 2 ] * SquareRoot ( L ) * Sine ( angle )) / L ; rotation [ 0 ][ 2 ] = ( vector [ 0 ] * vector [ 2 ] * ( 1 - Cosine ( angle )) + vector [ 1 ] * SquareRoot ( L ) * Sine ( angle )) / L ; rotation [ 0 ][ 3 ] = 0.0 ; rotation [ 1 ][ 0 ] = ( vector [ 0 ] * vector [ 1 ] * ( 1 - Cosine ( angle )) + vector [ 2 ] * SquareRoot ( L ) * Sine ( angle )) / L ; rotation [ 1 ][ 1 ] = ( v2 + ( u2 + w2 ) * Cosine ( angle )) / L ; rotation [ 1 ][ 2 ] = ( vector [ 1 ] * vector [ 2 ] * ( 1 - Cosine ( angle )) - vector [ 0 ] * SquareRoot ( L ) * Sine ( angle )) / L ; rotation [ 1 ][ 3 ] = 0.0 ; rotation [ 2 ][ 0 ] = ( vector [ 0 ] * vector [ 2 ] * ( 1 - Cosine ( angle )) - vector [ 1 ] * SquareRoot ( L ) * Sine ( angle )) / L ; rotation [ 2 ][ 1 ] = ( vector [ 1 ] * vector [ 2 ] * ( 1 - Cosine ( angle )) + vector [ 0 ] * SquareRoot ( L ) * Sine ( angle )) / L ; rotation [ 2 ][ 2 ] = ( w2 + ( u2 + v2 ) * Cosine ( angle )) / L ; rotation [ 2 ][ 3 ] = 0.0 ; rotation [ 3 ][ 0 ] = 0.0 ; rotation [ 3 ][ 1 ] = 0.0 ; rotation [ 3 ][ 2 ] = 0.0 ; rotation [ 3 ][ 3 ] = 1.0 ; }
EDIT: A more simple version?
http://www.engr.uvic.ca/~mech410/lec...RotateArbi.pdf