Applying a vector to a normal

Started by
16 comments, last by CGameProgrammer 22 years, 1 month ago
See, that''s what I thought as well, but it isn''t as simple as that.

Trust me, this is a really cool and very screwed up problem.

The trick lies in understanding that you''re actually solving for sets of four variables. Before you can generate a final matrix, you have to generate three separate rotation matrices and multiply them together. The reason there isn''t an infinite number of solutions is that we''re not working from basic lines. The vectors normals have to be unit vectors in order to be useable.
Geordi
George D. Filiotis
Advertisement
Fruny, the cross product of the wall''s normal and ground normal is perpendicular to them both, which is wrong. In the example I gave, you would get a vector near (0,0,1). But the actual vector should be close to the wall''s normal, since the flower''s orientation was close to the ground normal.

~CGameProgrammer( );

~CGameProgrammer( );Developer Image Exchange -- New Features: Upload screenshots of your games (size is unlimited) and upload the game itself (up to 10MB). Free. No registration needed.
ok, going to give you guys a taste of what the final solution is going to look like (because I''ve gotten this far, and maybe you can solve it for me from here, and I''ll look stupid if I don''t).

Given two unit vectors in 2D space, both of which are normals to a line.

v=(a, b), u=(c, d)

a rotation about the origin (we assume that these vectors are based at the origin as well) can be described by the following.

u = x*v + y*w

where w is the normal to the vector v {w = (-b, a)}, and x, y are scalar multiples of the two perpendicular vectors.

This is guaranteed to be true, because:

span(v, w) = ALL of 2D space

So, to solve, we know:

x(a, b) + y(-b, a) = (c, d)

which can be represented by this Augmented Matrix

+a, -b| +c
+b, +a| +d

Which, after a few row operations, ends up like this:

a*a*a*b, 0| b*c*(a*a+1)-a*d
0, a*a+b*b| b*c-a*d

from which we can deduce the equations:

y = (b*c-a*d)/(a*a+b*b)
x = (b*c*(a*a+1)-a*d)/(a*a*a*b)

So x, y are your rotation factors, and they create the rotation matrix:

(x, -y)
(y, x)

If you have a way of doing so, please test this hypothesis, if it works, then I can extend it to three dimensions.
Geordi
George D. Filiotis
I made a mistake, the values of x and y have to be normalized for this to work.

So it isn''t perfect, two sqrt() operations are necessary:

// before creating the transformation matrix
x = x / sqrt(x*x + y*y)
y = y / sqrt(x*x + y*y)

but I realitvely sure about the matrix.

George D. Filiotis
Are you in support of the ban of Dihydrogen Monoxide? You should be!
Geordi
George D. Filiotis
An interesting tidbit:

In order to make a rotation in three dimensions, a plane is described by the two vectors given (v & u, we're trying to rotation from v to u).

So in the end, the previous solution would be used for a rotation in a plane, except that that plane would be described in terms of 3-element vectors, so the final transformation is 3x3 (or 3D space to 3D space).

There's another way to do it which is marginally similar, but this method would be particularly useful for object-space to world-space transforms.

Given that the object which is going to be used is represented in object-space with respect to (1, 0, 0) - meaning that it points along the x axis - and our final desired direction in world space is given by two vectors, one to describe the direction the object is pointing, and one more to describe which direction the object orients as up.

Using that information we can do three separate baseic-planar transformations to get the object pointing in the direction we want it to. Again, without the use of trig. functions.

The first rotation is in the plane (y,z) (roll), the base vector is (1, 0). We then take the y and z components of the upward orientation vector of the object, and substitute them for the components of the target planar vector and solve for the rotation matrix (as shown two posts ago).

The resultant matrix:
(m -n)
(n m)

fits into a 3D transform like so:
(1 0 0)
(0 m -n)
(0 n m)

Then we solve for the rotation in the (x,y) plane (pitch), with vectors (1, 0) and the x and y components of the final directional vector. After solving we take our planar rotation matrix:
(a -b)
(b a)

And make a 3D transform:
(a -b 0)
(b a 0)
(0 0 1)

Finally we solve for the rotation in the (x,z) plane, again using (1, 0) as our starting vector and finishing with the x and z components of our target directional vector. Solving, we get:
(p -q)
(q p)

which becomes:
(p 0 -q)
(0 1 0)
(q 0 p)

Then to finalize our transformation matrix, we multiply the three 3x3 matrices we got this far to get a final matrix:

(y-z matrix) * (x-y matrix) * (x-z matrix)
==
-First Row-
p
-b*m*p-n*q
b*n*p-m*q
-Second Row-
b
a*m
-b*n
-Third Row-
a*q
n*p-b*m*q
b*n*q+m*p

So if you pad that with another row and column with a 1 in the bottom right, you can multiply by your scale and transpose matrices, and voila! you have a Object-to-World transformation matrix...

If there's any interest, I could probably re-post all of this in one coherent section

EDIT: dumb mistake

Edited by - symphonic on February 24, 2002 3:15:44 AM
Geordi
George D. Filiotis
quote:Original post by CGameProgrammer
But the actual vector should be close to the wall''s normal, since the flower''s orientation was close to the ground normal.


Read more carefully : what I gave you is the rotation to apply to the original vector (flower on ground) to get the new vector (flower on wall).
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Oh, right, Fruny. My mistake. So you''re suggesting a method in which I find out how to rotate from the ground''s normal to the wall''s normal, and apply that rotation to the flower normal. Makes a lot of sense - for some reason I didn''t think of that. I''m still using my X/Y/Z wall-vector method because it works and I know those vectors anyway, but your way is definitely something I will have to keep in mind.

My attention span is too limited to follow Symphonic''s matrix code, I''m afraid

~CGameProgrammer( );

~CGameProgrammer( );Developer Image Exchange -- New Features: Upload screenshots of your games (size is unlimited) and upload the game itself (up to 10MB). Free. No registration needed.
LOL I''m just posting for my delight then
Geordi
George D. Filiotis

This topic is closed to new replies.

Advertisement