Vector Reflection
visual representation of how to reflect a vector given only a vector and a plane
A super common scenario is needing to reflect (or bounce) something off a surface.
Think bouncing ball, rubber bullet, pong ball...etc
Find the plane's normal
We're going to assume we are only given a set of vertices which make up the plane, and a vector that passes through the plane


To find the plane's normal simply cross two of the edges (counter-clockwise)
FVector n = AB.Cross(BC).GetSafeNormal(); //normalizing for use later


Find the reflected vector
Right now Vr is just sitting in some mystical location. We don't have a point of intersection (yet) nor do we know the direction it should point.
But what we do know is that by looking at the image below, if we were to translate Vr to a parallel vector from our known point v0 (the ray's starting point) it would intersect our normal at point I

If we can find this point I then we can get the direction vector of our reflection (it will be in the wrong position, but we will deal with that in a second.
Find point I along plane's Normal
First lets project V onto N



Stellar, now we can find Vr via
I = v - 2(Project V onto N)
FVector I = v - (2 * (v.Dot(n)) * n); // V projected onto normalized N is (V â‹… N) * N
FVector Vr = I - V0;

Find the intersection of V and the Plane
Lastly we need to find where Vr should be reflecting out of which simplifies down to a line plane intersection problem. We need to find where V intersects with the plane.
The intersection point will be some point along V scaled by some value k.
k is a value from [0, 1] which represents the fraction of V we need to travel to reach the intersection point.

Here is a great visual representation of the derivation of the below formula's for more details but otherwise the formula is as follows
c = any arbitrary point on the plane
w = c - v0 // construct a vector from the ray's start to the point
k = (w â‹… n) / (v â‹… n) // Projection of W onto N divided by Projection of V onto N (multiplication by N for the projection formula cancels out in the derivation)
I = v0 + kv // intersection point starts at v0, in the direction of v, scaled by k
FVector pointOnPlane = pointB; // any point on plane, i'm using one of the vertices here
FVector w = pointOnPlane - V0; // vector from v to point
float k = w.Dot(n) / v.Dot(n); // scaling factor of v to plane
FVector I = V0 + (k * v); // point is on the ray starting at v0, along the direction of v, and scaled by k

Putting it all together
Now we know where to reflect from, which is simply I + Vr

Last updated