• Status: Solved
• Priority: Medium
• Security: Public
• Views: 475

# Vector of Relfection

Hi again,

Right, I have come along way since my last post.  I now fully understand why no answer was given before when I asked "How do I get the resultant angle of an object bouncing off a wall".  Well first of all I asked the wrong question, what I really needed was the vector of reflection.

Second, oh boy, was I not prepared for the complexity of information that was involved lol!  Anyway, I have read and re-read many papers on vectors and vector geometry.  I am really really close to finally pulling off a proper vector reflection but im stuck!

I know how to add vectors together, I know how to use dot products, I know how to multiply a vector by another vectors magnitude (Just a scalar).

But I dont understand whats going on in this formala for the vector of reflection.

Given...
I = Normalised Vector of Incidence (IE, the vector velocity of the ball)
N = The Normalised version of the Perpendicular of the Line that has been collided with
R = The resulting vector of reflection

R = I - 2(I.N)N

Right, now the thing I dont understand the the bit on the end where we multiply (I.N) by N

(I.N)N

I can work out the dot product between I.N, but then I dont know how or WHAT method I should use to multiply that value by the N on the end.

Just as an example, I was doing some working on paper to produce a vector which I know what the answer should be.

I used

I = (1, -1)
Vector of the Line collided with = (2,2)

The perpendicular of the line collided with = (-2,2)

The magnitude of the perpendicular = 2.828427125

The normalised version of the perpendicular = (-0.7071067811, 0.7071067811) = N'

The normalised version of the vector of incidence = (0.7071067812, -0.7071067812) = I'

The Dot Product of I.N

(I.N) = (-0.5, 0.5)

Since R = I - 2 (I.N)N

I multiply the vector (I.N) by the two then I get

R = I - (-1,1)N

So how do I finish this?  How do I multiply (-1,1)N.  If I used the magnitude, which is 1, I get the same answer but the completely wrong answer (I think) after I subtract it from I.

I read several tutorials on this and some seem to have slighty different equations than the one I should shown.

In one tutorial it told me to Normalise "I" before I do the equation R = I - 2(I.N)N

Any advice would be very much welcome.

Thanks again!
0
recruitit
• 11
• 3
• 2
5 Solutions

Author Commented:
Right, I think I have gotten a bit closer.

I noticed that

(I.N)N

is not

(I.N) * |N|

its actually

(I.N)   CROSS PRODUCT  N

And as I understand, the cross product is...

if V = (I.N)

then the cross product is

V x N = |V| |N| sin t "n"

Where the little n is a perpendicular unit vector to the vectors V and N, which just opens another question, how do you get "n" perp vector when we are only working with two dimensions lol

I also assume that |V| and |N| are the magnitudes.

Its a shame, I see so many tutorials online but I cant seem to find any actual physical examples with actual numbers being used.

0

Author Commented:
Uh oh, I made I slight miscalculate, the dot product of I and N should actually be
(-.5,-.5)
Then x2
(-1,-1)

So

R = I - (-1,-1)N

Is not the solution yet! ill report back when I manage to do the cross product.
0

Commented:
Beat me to it...

It's the cross product...

little 'n' is the perpendicular to the surface you're bouncing off of...

Hope this helps...

-john
0

Author Commented:
Hi jgordos,

Thanks for that!  Sorry just need a little bit more info :o)

Sorry for having to be so specific, I take it you mean the un-normalised perp?(In this case (-2, 2))

Right now I have.

V x N = |V| |N| sint t n

V x N =   (1.414213562 * 1)  * ( sin t)  *  The perpendicular (-2,2)

From what I can see on the paper, t is the angle between V and N.

Just give me a sec, I think im almost there, just going to read a bit more.
0

Author Commented:
Oh man, I am getting alot of things wrong.

A dot product results in a scalar, when I did I.N I did a multiplication of the components and put them in x,y.  But since I.N is a scalar, (somenumber)N then I am simply increasing the magnitude of N by somenumber

Im really confused now lol,  I am pretty sure a dot product results in a scalar, let me just rejig the numbers and see if I can get the right answer
0

Author Commented:
sorry I didnt explain myself well enough.  I.N results in a scalar, not a vector
0

Author Commented:
Maybe not, looks like im reading this tutorial wrong.
0

Author Commented:
ok, doh, I was right before,  I.N is a vector.

When I take V.N and then add up the multiplied components I get 0 which reverse cos is 90 degrees.

So I now have

(1.414213562 * 1)  * ( sin 90)  *  The perpendicular (-2,2)

1.264302206 * (-2,2)
(-2.528604412, 2.528604412)
So R = (-0.707106781 --2.528604412, 0.707106781 - 2.528604412)

Finally
Vector of reflection R = (1.821497631, -1.821497631)

That wasnt exactly what I was expecting

0

Author Commented:
If I use the normalised perpendicular for "n" I get another wacky result

R = (1.601103444, -1.60110344)

0

Author Commented:

Since we basically have a ball traveling at (1,-1) and the wall is basically at a 45 degree angle.

To put it simply its the same as a ball traveling (0,1) colliding with a wall at the bottom which will reverse its components (0, -1)

0

Commented:
Okay, now you've confused me...

The ball travelling 0,1... that's a ball moving straight down in your coordinates, yes?

the coordinate space I usually think of is

Y+ going up from the bottom of the screen
X+ going from left to right..

But the perpendicular to the surface (normally called a 'normal') is nearly always a normalized vector.

And the magnitude of the vector for the object is nearly always normalized too.

It shouldn't make any difference, but it makes the math simpler to debug.

And now the magic question... are you doing your math in degrees or radians?

-john
0

Commented:

I = (1, -1)
Vector of the Line collided with = (2,2)

The perpendicular of the line collided with = (-2,2)

The magnitude of the perpendicular = 2.828427125

The normalised version of the perpendicular = (-0.7071067811, 0.7071067811) = N'

The normalised version of the vector of incidence = (0.7071067812, -0.7071067812) = I'

The Dot Product of I.N

(I.N) = (-0.5 +  -0.5) = -1

Since R = I - 2 (-1)N

I multiply the vector (I.N) by the two then I get

R = I + 2N
= (-0.7071067811, 0.7071067811)

0

Commented:
R' = I' + 2(I'.N') N' = (-0.7071067811, 0.7071067811) is the normalized reflection, since you took the dot product of N' with I'
if you take the unnormalized reflection of the unnormalized incident vector,
R = I'+ 2(I.N') N'
that would be
(1, -1) + 2( 1*-0.7071067811 + -1* 0.7071067811) (-0.7071067811, 0.7071067811)
= (1, -1) + 2*(-1.4142135622) * (-0.7071067811, 0.7071067811)
=  (1, -1) + (-2,2)
= (-1,1)

This works regardless of what quadrant you are in and regardless of whether you use degrees or radians
(since no angles were calculated)
0

Commented:
> R = I'+ 2(I.N') N'
should have been
R = I + 2(I.N') N'
0

Author Commented:
Right, I see where I got confused, the tutorial I was looking at was showing how to get a cross product with the formula

V x N = |V| |N| sin t n

As for the quadrant I am using the one from XNA which has the y increasing while you go down the screen and the x increasing as you go to the right of the screen.

Thanks very much for the help.  I havnt been working with vectors for very long lol so I cant make any intuitive guesses since I dont really know whats going on lol.
0

Author Commented:
Ok I just want to add, that I am going to be using the following equation.

Vector of Reflection R = (I' - 2(I'.N')N' )  [I]

Where

I' = Normalised Vector of Incidence I (E.G. The velocity)
N' = Normalised Perpendicular
[I] = The magnitude of the non-normalised I

This equation works perfectly for all values I have tried so far.  Even (0,1) (1,0) example stated above.
0

## Featured Post

• 11
• 3
• 2
Tackle projects and never again get stuck behind a technical roadblock.