<p>If I understand correctly, you want to draw 2 objects mirrored with respect to an arbitrary line. Then when you move 1 object you want the other (reflection) to move with respect to that reflected line. </p>

<p>A more sophisticated way of doing this would be using transformation matrices. That way you wouldn't have to worry about moving the mirrored triangle. You will move the original triangle, apply a transformation matrix to find the position of the mirrored triangle.</p>

<p>Suppose we have an arbitrary line $ax+by+c = 0$ making an arbitrary angle (measured counter clockwise) with the +X axis. We can easily find slope in the form of $ y = mx + c$ and the angle $\theta = tan^-1(m)$.</p>

<p>The mirror transformation with respect to this line can be broken in 3 affine transformation.</p>

<p>1) Rotate the line by  $-\theta$ to coincide it with the X-axis.</p>

<p>$\begin{bmatrix}
cos(-theta) &amp; -sin(-theta) &amp; 0\\
sin(-theta) &amp; cos(-theta)  &amp; 0\\
0           &amp; 0            &amp; 1
\end{bmatrix}$</p>

<p>2) Reflect about the X-axis.</p>

<p>$\begin{bmatrix}
1 &amp; 0  &amp; 0\\
0 &amp; -1 &amp; 0\\
0 &amp; 0 &amp; 1
\end{bmatrix}$</p>

<p>3) Rotate again by $\theta$.</p>

<p>$\begin{bmatrix}
cos(theta) &amp; -sin(theta) &amp; 0\\
sin(theta) &amp; cos(theta)  &amp; 0\\
0           &amp; 0            &amp; 1
\end{bmatrix}$</p>

<p>Now you concatenate all 3 and you get a matrix that reflects about an arbitrary line.</p>

<p>Now we only move 1 triangle and find out the other by applying the matrix.</p>

<p>EDIT:- <strong>As pointed out by Anthony in the comments this is only for lines passing through the origin. For arbitrary lines first translate them to the origin, then perform all these steps, then translate it back.</strong></p>

<p>In order to do this you can find out the x and y intercepts by putting <code>y=0</code> and  <code>x=0</code> respectively then translate the respective coordinate by that amount.</p>

CC BY-SA 3.0
2018-03-16T13:09:59.510Z
I am afraid this answer is actually incorrect. The rotations are around the origin while the line may not cross the origin. You first need to translate so that the line will pass through the origin and of course translate back at the end.
Antony Riakiotakis
CC BY-SA 3.0
2018-03-16T15:21:00.593Z
True but I think we don't need it anyways. Because we are only interested in the slope or the angle the line makes with the axis. So translation doesn't affect the angle. So for example we have a triangle and we want to flip around line `y=x+1` Well that's the same line as `y=x` the only difference being the second one passes through the origin. In both the cases we rotate around by the same angle i.e 45 degrees
gallickgunner
CC BY-SA 3.0
2018-03-17T17:56:36.500Z
You do need it. Let's take an extreme example: line equation x = 2 and point P at {3, 0}. obviously the mirrored point is at {1, 0}. If we try it with your method, the series of operations will yield {0, 3}, then {0, -3}, finally {-3, 0} which is way different than the correct result.
Antony Riakiotakis
CC BY-SA 3.0
2018-03-18T06:50:22.820Z
True. thanks for pointing out I'll add it to the answer.
gallickgunner
CC BY-SA 3.0
2018-03-01T09:31:29.877Z
2018-03-18T06:54:33.687Z
2018-03-18T06:54:33.687Z
gallickgunner
<p>To mirror an object in relation to an arbitrary line, you first have to find the coordinates of that object in the frame of reference of that line. For convenience, we will define a frame of reference where the $X$ axis is colinear with the line itself and the $Y$ axis will be perpendicular to the line. Then, we can flip the Y coordinate in that frame of reference to obtain the mirrored point and finally we will reverse the transform from the line coordinate system and back to the global coordinate system.</p>

<p>To define a coordinate system, we will need to use one point the line passes through as the origin $O$ of that coordinate system. This can be obtained easily by setting $x = 0$ or $y = 0$ in the line equation and we end up with the point $\{-c/a, 0\}$ or $\{0, -c/b\}$. Getting the $X$ and $Y$ axis of the new coordinate system is easy. The $X$ axis vector $\{X_x, X_y\}$ will be computed by normalizing $\{a, b\}$ from the line equation. Then we need a perpendicular vector for the $Y$ axis direction. This is easily obtained by using either $\{-X_y, X_x\}$ or $\{X_y, -X_x\}$ (you can verify that by taking the dot product between $X$ and $Y$ which will be zero).</p>

<p>Now that you have an origin and a coordinate system, let's find a mirrored point of vector P on that system. First we need to express it in the new coordinate system. This can be done by projecting $P-O$ to the basis vectors $X$ and $Y$, so the coordinates in the new system will be $\{\langle(P - O), X\rangle, \langle(P - O), Y\rangle\}$.
To obtain the mirrored point, we simply flip the Y coordinate. To obtain the final vector in the original space, we simply invert the first transform. The final point should be $O + X\cdot\langle(P-O), X\rangle - Y\cdot\langle(P-O), Y\rangle$</p>

<p>A note on notation: $\langle u,v\rangle$ was used for dot product between vectors. $u\cdot k$ was used for product between vector and scalar</p>

CC BY-SA 3.0
2018-02-28T19:41:04.990Z
2018-02-28T20:31:27.667Z
2018-02-28T20:31:27.667Z
Antony Riakiotakis
<p>(sorry for my english)<br>
<strong>The task:</strong><br>
A triangle is specified. To realize its motion on the basis of mirror reflection with respect to an arbitrary line ax + by + c = 0, the coefficients of which are entered by the user.  </p>

<p><strong>Already done:</strong><br>
I read from the fields on the form the coordinates of the three points of the triangle.<br>
Putting them into objects of class <code>Point</code> (<code>left (x, y)</code>, <code>top (x, y)</code>, <code>right (x, y)</code>).<br>
Make an array of <code>points</code> from the points of a triangle:</p>

<pre><code>Point[] points = new Point[3] { left, top, right };
</code></pre>

<p>Draw a coordinate system:</p>

<pre><code>DrawField();
DrawCoordinateSystem();
</code></pre>

<p>Draw a triangle:</p>

<pre><code>graph.FillPolygon(Brushes.ForestGreen, points);
</code></pre>

<p>Make a mirror reflection of the triangle:</p>

<pre><code>Point[] pointsCopy = (Point[]) points.Clone();   
for (int i = 0; i  pointsCopy.Length; i++)
    pointsCopy[i].Y = -pointsCopy[i].Y; 
graph.FillPolygon(Brushes.RoyalBlue, pointsCopy);
</code></pre>

<p>Read the coefficients (<code>a</code>, <code>b</code>, <code>c</code>) from the fields on the form for the equation <code>ax + by + c = 0</code>.  </p>

<p><a href="https://i.sstatic.net/f6tXI.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/f6tXI.png" alt="affine transformations of triangle"></a></p>

<p><strong>Question:</strong><br>
Tell me how to move it further relative to the line <code>ax + by + c = 0</code> ?</p>

<vector-graphics><affine-transformations>
How to make a translation relative to the line ax + by + c = 0, affine transformations
Taras Koval
# How to make a translation relative to the line ax + by + c = 0, affine transformations

(Asked by: username_0 on 2018-02-28)

(sorry for my english)  
**The task:**  
A triangle is specified. To realize its motion on the basis of mirror reflection with respect to an arbitrary line ax + by + c = 0, the coefficients of which are entered by the user.

**Already done:**  
I read from the fields on the form the coordinates of the three points of the triangle.  
Putting them into objects of class `Point` (`left (x, y)`, `top (x, y)`, `right (x, y)`).  
Make an array of `points` from the points of a triangle:

```
Point[] points = new Point[3] { left, top, right };

```

Draw a coordinate system:

```
DrawField();
DrawCoordinateSystem();

```

Draw a triangle:

```
graph.FillPolygon(Brushes.ForestGreen, points);

```

Make a mirror reflection of the triangle:

```
Point[] pointsCopy = (Point[]) points.Clone();   
for (int i = 0; i  pointsCopy.Length; i++)
    pointsCopy[i].Y = -pointsCopy[i].Y; 
graph.FillPolygon(Brushes.RoyalBlue, pointsCopy);

```

Read the coefficients (`a`, `b`, `c`) from the fields on the form for the equation `ax + by + c = 0`.

[![affine transformations of triangle](https://i.sstatic.net/f6tXI.png)](https://i.sstatic.net/f6tXI.png)

**Question:**  
Tell me how to move it further relative to the line `ax + by + c = 0` ?

**Tags:** vector-graphics, affine-transformations


---

## 2 answers

### Answer by username_1 on 2018-03-01. Score: 1 | Accepted answer

If I understand correctly, you want to draw 2 objects mirrored with respect to an arbitrary line. Then when you move 1 object you want the other (reflection) to move with respect to that reflected line.

A more sophisticated way of doing this would be using transformation matrices. That way you wouldn't have to worry about moving the mirrored triangle. You will move the original triangle, apply a transformation matrix to find the position of the mirrored triangle.

Suppose we have an arbitrary line $ax+by+c = 0$ making an arbitrary angle (measured counter clockwise) with the +X axis. We can easily find slope in the form of $ y = mx + c$ and the angle $\theta = tan^-1(m)$.

The mirror transformation with respect to this line can be broken in 3 affine transformation.

1) Rotate the line by $-\theta$ to coincide it with the X-axis.

$\begin{bmatrix}
cos(-theta) & -sin(-theta) & 0\\
sin(-theta) & cos(-theta) & 0\\
0 & 0 & 1
\end{bmatrix}$

2) Reflect about the X-axis.

$\begin{bmatrix}
1 & 0 & 0\\
0 & -1 & 0\\
0 & 0 & 1
\end{bmatrix}$

3) Rotate again by $\theta$.

$\begin{bmatrix}
cos(theta) & -sin(theta) & 0\\
sin(theta) & cos(theta) & 0\\
0 & 0 & 1
\end{bmatrix}$

Now you concatenate all 3 and you get a matrix that reflects about an arbitrary line.

Now we only move 1 triangle and find out the other by applying the matrix.

EDIT:- **As pointed out by Anthony in the comments this is only for lines passing through the origin. For arbitrary lines first translate them to the origin, then perform all these steps, then translate it back.**

In order to do this you can find out the x and y intercepts by putting `y=0` and `x=0` respectively then translate the respective coordinate by that amount.

> **Comments:**
> **username_2**: I am afraid this answer is actually incorrect. The rotations are around the origin while the line may not cross the origin. You first need to translate so that the line will pass through the origin and of course translate back at the end.  
> **username_1**: True but I think we don't need it anyways. Because we are only interested in the slope or the angle the line makes with the axis. So translation doesn't affect the angle. So for example we have a triangle and we want to flip around line `y=x+1` Well that's the same line as `y=x` the only difference being the second one passes through the origin. In both the cases we rotate around by the same angle i.e 45 degrees  
> **username_2**: You do need it. Let's take an extreme example: line equation x = 2 and point P at {3, 0}. obviously the mirrored point is at {1, 0}. If we try it with your method, the series of operations will yield {0, 3}, then {0, -3}, finally {-3, 0} which is way different than the correct result.  
> **username_1**: True. thanks for pointing out I'll add it to the answer.  

---

### Answer by username_2 on 2018-02-28. Score: 1

To mirror an object in relation to an arbitrary line, you first have to find the coordinates of that object in the frame of reference of that line. For convenience, we will define a frame of reference where the $X$ axis is colinear with the line itself and the $Y$ axis will be perpendicular to the line. Then, we can flip the Y coordinate in that frame of reference to obtain the mirrored point and finally we will reverse the transform from the line coordinate system and back to the global coordinate system.

To define a coordinate system, we will need to use one point the line passes through as the origin $O$ of that coordinate system. This can be obtained easily by setting $x = 0$ or $y = 0$ in the line equation and we end up with the point $\{-c/a, 0\}$ or $\{0, -c/b\}$. Getting the $X$ and $Y$ axis of the new coordinate system is easy. The $X$ axis vector $\{X\_x, X\_y\}$ will be computed by normalizing $\{a, b\}$ from the line equation. Then we need a perpendicular vector for the $Y$ axis direction. This is easily obtained by using either $\{-X\_y, X\_x\}$ or $\{X\_y, -X\_x\}$ (you can verify that by taking the dot product between $X$ and $Y$ which will be zero).

Now that you have an origin and a coordinate system, let's find a mirrored point of vector P on that system. First we need to express it in the new coordinate system. This can be done by projecting $P-O$ to the basis vectors $X$ and $Y$, so the coordinates in the new system will be $\{\langle(P - O), X\rangle, \langle(P - O), Y\rangle\}$.
To obtain the mirrored point, we simply flip the Y coordinate. To obtain the final vector in the original space, we simply invert the first transform. The final point should be $O + X\cdot\langle(P-O), X\rangle - Y\cdot\langle(P-O), Y\rangle$

A note on notation: $\langle u,v\rangle$ was used for dot product between vectors. $u\cdot k$ was used for product between vector and scalar


---

