Advertisement

Explain like I'm 5: Reflection Algorithm

Started by August 29, 2012 06:51 AM
12 comments, last by tom_mai78101 12 years, 5 months ago
Someone helped me solve a difficult physics problem where it involves balls hitting a circular wall from both sides. It can also be applied to an object hitting an wall with an arbitary angle. In essence, it relies on the collision detection, rather than the response from the object.

Quoted:

To reflect a vector on another + reverting the direction:
N: normal vector you want to use the mirroring line, make sure it is normalized(length = 1)
V: vector you want to reflect with N
R: reflected vector

R = -2*(V dot N)*N + V
[/quote]

I would like for someone to help me explain how they get this formula. I just could not get around it on paper and head. Thanks in advance.
The (V dot N)*N part of the equation is equal to the projection of V on the mirroring line, so if you subtract that from V, you get the part of V which is going parallel to the reflecting surface. If you subtract (V dot N)*N from this new vector, you get a vector that has the same component parallel to the reflecting surface, but an inverted component parallel to the line of reflection. Does this help?
Advertisement
The raw equation like this isn't very insightful, but it helps immensely if you draw a diagram, and then it becomes pretty much obvious what is happening:

2zqd2qq.png

The reason there is a minus sign in the dot vector is because the incident vector is going "towards" the normal, the opposite of the dot product definition. This diagram is of course also applicable to the three-dimensional case, but drawing a diagram is more difficult!

Does this make sense?

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”

To Bacterius:

I did not realize I have to draw them like this. I figured, since it involves reflecting from a circular wall, I went from there. Comparing my drawings with yours, my normalized N vector is too long. The minus sign on the V vector also confuses me. Why would a dot product of (-V) and (N) be on the N vector, instead of towards the dark green arrow (the R vector)? So, I drew differently.

[size=2]The humilation...

To Bacterius:

I did not realize I have to draw them like this. I figured, since it involves reflecting from a circular wall, I went from there. Comparing my drawings with yours, my normalized N vector is too long. The minus sign on the V vector also confuses me. Why would a dot product of (-V) and (N) be on the N vector, instead of towards the dark green arrow (the R vector)? So, I drew differently.

[size=2]The humilation...

My own diagram is far from perfect too, and is not to scale either (having all the vectors the same size just ends up looking awkward in this case, so I didn't mind an extra-long normal vector). It is true that you could have used the positive dot product, which will have required you to subtract V instead of adding it, and then ultimately negate everything to get the R vector in the right direction, which should - hopefully - give the same result. This version just seemed more straightforward to me.

There is no need to be embarrassed, we all make mistakes every now and then :)

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”

Wait a minute, I'm not done... yet...

This is correct?

U7NDX.png
Advertisement
No, the dot product is a scalar, not a vector, so it doesn't make sense to give it an arrow. I gave mine two arrows to indicate it was a length, and only made it a vector by multiplying it by N. What you are looking at in your diagram is the vector A + B.

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”

No, that's A+B. A dot B is a scalar, but if you multiply A dot B by B you get the projection of A on B like so:
G9GmY.png
EDIT: actually not like that, I got the blue arrow the wrong way around somehow so the red vector should be A-(A.B)B. Sorry about that.
[s]@RulerOfNothing Actually you drew (-A) dot B. The two vectors must be "going apart" in the dot product definition![/s] ignore this

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”

R = -2*(V dot N)*N + V = V-2*(V dot N)*N

V dot N ===> Gives you the amount "how much N is in V"

(V dot N)*N ===> Builds a vector in the direction of N with that amount

V-(V dot N)*N ===> Would give you a vector *without* the normal component of the reflecting wall.

V-2*(V dot N)*N ===> Gives you the vector with an inverted normal-component. That's what the law of reflection is about.

This topic is closed to new replies.

Advertisement