Applying a vector to a normal

Started by
16 comments, last by CGameProgrammer 22 years, 1 month ago
Let's say there's a flower on the ground. Its facing mostly straight up, but slightly bent, so let's say its vector is the normalized version of (0.1, 1, 0.2). Now let's say there's a nearby brick wall. Its normal is (1, 0, 0) meaning the wall is facing right. Now if I picked up the flower and stuck it into the brick wall, such that it's sticking out of the wall at the same orientation it was from the ground, then what is the flower's new vector? Its vector relative to the brick wall is still (0.1, 1, 0.2) (normalized of course), but what's its absolute vector? Its vector would be close to (1, 0, 0), and in fact if the flower had been sticking straight up from the ground, that would be its new vector exactly. That's probably the best way I can explain it. So, how would you calculate the new vector of a vector applied to a normal? ~CGameProgrammer( );

Edited by - CGameProgrammer on February 19, 2002 6:04:14 PM

~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.
Advertisement
BTW, in this example I know you can switch the Y with the X and so on, but this is just an example. The actual vectors and normals can be anything and I need to calculate the new vector.

~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.
Your flower is on the ground, and it is facing up, in the direction (0, 1, 0). The wall is (1, 0, 0)... Simply rotate your vector exactly 90 degrees, in this case around the Z axis. Even in your example where the flower isn't exactly (0, 1, 0), rotating it 90 degrees will make it stick out of the wall in the same orientation as it stuck out of the ground. For any other case where you have one vector pointing up relative to some plane and you want to keep it pointing up relative to another plane look up you might try solving the equation linearly. It's been a while but having v*m=v1, where v is your original vector, m is some rotation matrix, and v1 is your new vector, you can find m if you know v and v1.

Now, the question you should be asking yourself is 'should my flower be sticking out of a wall?' ...It's a tough call

------------
- outRider -

Edited by - outRider on February 19, 2002 7:11:55 PM
Idea removed because it was entirely wrong.

Edited by - TerranFury on February 19, 2002 9:36:14 PM
I''ve done some preliminary work on this, there IS a way to solve your problem without using any trigonometric functions, but the linear algebra involved is pretty funky.

I should have a solution by tomorrow, so check back and I''ll let you know.

Incidentally, the solution involves only multiplication and division of vector elements.

George D. Filiotis
Are you in support of the ban of Dihydrogen Monoxide? You should be!
Geordi
George D. Filiotis
Well I solved it, basically. Rotation is not feasible because the normal (orientation of the wall in this example) and vector (of the flower in this example) can be anything. I merely used the wall and flower as an example. Usually, the normal and vector would not be 90 degrees apart, or any amount of degrees apart along a single axis of rotation.

The way I did it was by using not just the normal of the wall but three vectors: The vector along the X-axis of the wall, the vector along the Y axis (which is the normal), and the vector along the Z-axis of it. The new vector would be this:
NewVector = (Wall.XVector * Flower.X) + (Wall.YVector * Flower.Y) + (Wall.ZVector * Flower.Z); 

I had been thinking that it would be simpler than that, but then I realized that given only the wall''s normal and the flower vector, the flower could be applied to that normal but still rotated around it. There would be no way to place it using only those two vectors.

~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.
I'm still very interested in seeing your solution, Symphonic. Technically I shouldn't really need both the X-vector and Z-vectors of the wall, only one would be enough, basically to anchor the flower at a set rotation around the wall's normal. Or even a single scalar would do, I guess... well I'd like someone else's solution to this. It's a simple problem in a way.

~CGameProgrammer( );



Edited by - CGameProgrammer on February 19, 2002 12:38:58 AM

~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.
Take the normal to the ground
Take the normal to the wall
Take the cross product of the two
This is the axis around which you rotated.

Take the normal to the ground
Take the normal to the wall
Take the dot product of the two
This is the cosine of the angle of rotation.
"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
Well, what I'm deriving is a general solution for a transformation matrix as follows.

Given vectors v and u in three dimensional space, there exists a 3x3 matrix A such that:

Av = u

However, if the two vectors given are not unit vectors, then there is a certain amount of scaling. Which is the part I'm trying it factor out. This is a really huge problem though, I spent three hours on it with seemingly no acceptable solution in sight. It's easy if you let yourself use trig functions, or square-root functions, but I'm restricting myself to finding a multiply/divide solution.

Edited by - symphonic on February 20, 2002 3:23:14 AM
Geordi
George D. Filiotis
3 equations (x,y,z), 9 unknowns (Aij), an infinite number of solutions.
"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

This topic is closed to new replies.

Advertisement