A rotation matrix from a normalized vector

Moach

Crazy dude with a rocket
Addon Developer
Joined
Aug 6, 2008
Messages
1,582
Reaction score
63
Points
63
Location
Vancouver, BC
so, this is one for the math-savvy folks here...

say i have a surface, and a ball to collide against it - this surface is represented as a plane defined by normal vector...

this is all in 2d, and is part of my quad-tree simulation thing....

the surface normal is contained in each quad that has a surface segment going through it... anyways, that's all sorted out, but now - i need to get stuff bumping off of it....


in order to simplify things, i have that "surface normal" vector normalized at a pre-compute step, so i don't have to calculate that in run-time....

and then, my plan is, in order to actually check the colliding of objects against said surface, i'd just "rotate" them into "local space" by building a transform matrix out of the normal vector...


the math sounds coherent - but i can't seem to get this to work for the life of me....

a rotation is (i hope) defined in matrix form like this:
rx = vx* cos(r) + vy*sin(r);
ry = vx*-sin(r) + vy*cos(r);


so i figured that already having the unit-length surface normal vector, i could very well build a matrix around it and use that to rotate other vectors from "world space" into "surface space"...

which kinda makes sense, since the normal vector's x and y values should directly match the cos and sin of the angle between that and the world-space idea of "up"...


so i figured i could just substitute:
rx = vx* nrml.x + vy*nrml.y;
ry = vx*-nrml.y + vy*nrml.x;


and skip a bunch of expensive computation steps - i could almost hear the CPU applauding this idea....

but then, it didn't really work... and i'm not sure exactly WHAT i messed up this time....


i wonder if i should have swapped X and Y somewhere... googling for an answer has proven fruitless for a few days now... so now i ask here

how does one build a rot-matrix around a normalized vector?

and i thank you in advance! :cheers:
 
Shall I post you the formula from my small pocket math book (you should never leave your house with out it)?

[math]M(\delta) = (1-\cos \alpha) \begin{pmatrix}a^2 & ab & ac \\ ab & b^2 & bc \\ ac & bc & c^2 \end{pmatrix} + \cos \alpha \begin{pmatrix}1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{pmatrix} + \sin \alpha \begin{pmatrix}0 & -c & b \\ c & 0 & -a \\ -b & a & 0 \end{pmatrix}[/math]

a, b, c are the components of your rotation vector (normalized)
 
Shall I post you the formula from my small pocket math book (you should never leave your house with out it)?)


What's the name of the book.
 
Back
Top