2
$\begingroup$

(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

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

$\endgroup$
1
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ 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. $\endgroup$ – Antony Riakiotakis Mar 16 '18 at 13:09
  • $\begingroup$ 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 $\endgroup$ – gallickgunner Mar 16 '18 at 15:21
  • 1
    $\begingroup$ 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. $\endgroup$ – Antony Riakiotakis Mar 17 '18 at 17:56
  • $\begingroup$ True. thanks for pointing out I'll add it to the answer. $\endgroup$ – gallickgunner Mar 18 '18 at 6:50
1
$\begingroup$

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

$\endgroup$

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.