# Calculating symmetric points

Some months ago I was trying to figure out a way to find the symmetry of a given point using a line as a mirror. I got busy doing other things and all my notes were lost like tears in the rain. I finally got time to complete the research.

I found three simple ways to do so. All three need an origin position and a direction (a unit vector that represents the line itself); it’s needless to say that the origin must be over the line.

### Vector Projection

Let’s label the original point as A and the symmetric partner as P.

Assuming we already have A, we want to find using vector projections. In the figure below, a is Ab is the direction and the point opposite to the arrow’s tip is the origin. P will be analogous to A, but below b.

Using basic linear algebra:

$projA= \mathbf{a_1}= |\mathbf{a}|\cos\theta = \mathbf{a}\cdot\mathbf{\hat b}$

$rejA= \mathbf{a_2}= \mathbf{a}- \mathbf{a}_1$

Here’s the code that applies this principle:

### Perpendicular Vectors

I wanted alternate ways to have the desired points with. For this approach, the initial point A is not needed as input, as both A and B will be generated at the same time.

In this case, the first step will be to create the projection vector of the future points. After that, the rejection vectors will be nothing more than the perpendicular vectors of such projection. The results are three vectors that will be used to create the desired points.

This method provides control over the generation of points, via three variables (randomly set in the code above for the sake of the example). Those variables can be passed as arguments but are used as they are for explanatory purposes.