SimpleVector - Interactive examples

back

Reflect methods

On the first screen you can drag the input vector v1 the input vector. This is the vector we are calling .reflect() on.

You can also drag the normal vector. This is the argument we pass to v1.reflect(normal). It represent the normal vector of the surface that v1 will be reflected on. This surface is rendered as the black line on the second screen.

And you can observe how the reflected vector evolves.

The second screen is another representation to help visualize how .reflect works. It shows:

  • v1 as pointing toward the surface it will be reflected on. (The surface is the black line).
  • normal pointing out of the surface at the point where v1 intersects the surface.
  • And reflected as going out from this impact point.

Note how when v1 and normal are perpendicular, ie. when the vector is parallel to the surface to reflect on, reflected keeps the same direction. In a physical simulation that's an edge case to handle before (or after) calling .reflect().

Note the magnitude of the normal vector doesn't impact the result of .reflect() (Because the method normalize it before doing its computation)

Input

v1
x:3, y:3
normal
x:0, y:1
v1.reflect(normal)
x:3, y:-3