Reflection? How do I do it?

2019-02-10 18:19发布

问题:

This is over my head, can someone explain it to me better? http://mathworld.wolfram.com/Reflection.html

I'm making a 2d breakout fighting game, so I need the ball to be able to reflect when it hits a wall, paddle, or enemy (or a enemy hits it).

all their formula's are like: x_1^'-x_0=v-2(v·n^^)n^^.

And I can't fallow that. (What does ' mean or x_0? or ^^?)

回答1:

The formula for reflection is easier to understand if you think to the geometric meaning of the operation of "dot product".

The dot product between two 3d vectors is mathematically defined as

<a, b> = ax*bx + ay*by + az*bz

but it has a nice geometric interpretation

The dot product between a and b is the length of the projection of a over b taken with a negative sign if the two vectors are pointing in opposite directions, multiplied by the length of b.

Something that is immediately obvious using this definition and that it's not evident if you only look at the formula is for example that the dot product of two vectors doesn't change if the coordinate system is rotated, that the dot product of two perpendicular vectors is 0 (the length of the projection is clearly zero in this case) or that the dot product of a vector by itself is the square of its length.

Something that is instead less obvious using the geometric interpretation is that the dot product is commutative, i.e. that <a, b> = <b, a> (fact that is clear considering the formula).

An important point to consider is also that if the length of b is 1 then the dot product <a, b> is simply the length of the projection of a over b (taken with the proper sign).

Given this interpretation the formula for computing the reflection over a plane is quite easy to understand:

To compute the reflected vector r, given a vector a and a plane with normal n you just need to use the formula:

r = a - 2<a, n> n

the height h in the figure is in this case just <a, n> (note that n is assumed to be of unit length) and so it should be clear that you need to move twice that height in the direction of the normal.

If you consider the proper dot product signs you should see that the formula applies also when the incident vector a and the plane normal n are facing in the same direction.



回答2:

The prime (') indicates the second form of a number/point/structure. In this case, x₁' refers to the reflected form of x₁.

The subscript (0) shows various states of the same. In this case, x₀ is the point of reflection.

The caret notation (^) shows that something is a vector. In this case, n̂ is the normal vector.



回答3:

Is this just about the equation formatting? Because I see nicely formatted equations, not the LaTeX-style markup appearing in your question. So step 1: try viewing the page in a different web browser and see if it looks clearer.

More substantively, I'd recommend a different kind of resource. Fundamentally, you're looking at collisions, which are normally better treated in a physics text than a math text. Any introductory physics textbook will have a chapter on collisions, which should be directly applicable to your game.