#### Archived

This topic is now archived and is closed to further replies.

# Applying a vector to a normal

This topic is 5991 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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

##### Share on other sites
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( );

##### Share on other sites
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

##### Share on other sites
Idea removed because it was entirely wrong.

Edited by - TerranFury on February 19, 2002 9:36:14 PM

##### Share on other sites
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!

##### Share on other sites
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( );

##### Share on other sites
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

##### Share on other sites
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.

##### Share on other sites
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

##### Share on other sites
3 equations (x,y,z), 9 unknowns (Aij), an infinite number of solutions.

1. 1
2. 2
Rutin
24
3. 3
4. 4
JoeJ
18
5. 5

• 14
• 28
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
631772
• Total Posts
3002260
×