which formula could be used to get a set of vertices after rotate a triangle?

362 Views Asked by At

there are 3 vertices to define a triangle.

print(x,y)
[1 2 3] [ 2  3 -2]

python could be used to plot this triangle

plt.triplot(x,y)

the output is

enter image description here

I am trying to compute the new vertices after rotate a triangle to have the left vertex move to a point y axis = -2, keep right vertex fixed.

which formula could be used to get the x axis of left vertex and (x,y) of top vertex of the new triangle?

2

There are 2 best solutions below

0
On

Using complex numbers.

Let $z_0$ be the fixed vertex and $z_1$ the vertex that goes to $y=-2$. This is expressed by

$$e^{i\theta}(z_1-z_0)+z_0=x+iy,$$ where $x$ is free.

From this,

$$e^{i\theta}=\frac{x+iy-z_0}{z_1-z_0}.$$

To determine $x$, we express that the modulus of the RHS is one, so that

$$(x-x_0)^2+(y-y_0)^2=|z_1-z_0|^2,$$

or

$$x=x_0\pm\sqrt{|z_1-z_0|^2-(y-y_0)^2}.$$

So there are two solutions in $x$ (which was to be expected, from geometry), and $\theta$ is given by

$$\arctan\frac{x-x_0}{y-y_0}-\arctan\frac{x_1-x_0}{y_1-y_0}.$$

0
On

Call the three vertices $A$, $B$, $C$. The fixed point is $C$, so the transformation can be described as $P\mapsto R(P-C)+C$, where $R$ is an appropriate rotation about the origin. A matrix for this rotation is easily constructed.

Let $\mathbf u$ be the unit vector in the direction of $A-C$ and $\mathbf v = (-u_y,u_x)$, which is $\mathbf u$ rotated 90° counterclockwise. If the $y$-coordinate of the rotated image $A'$ of $A$ is $-2$, this means that a unit vector in the direction of $A'-C$ is $(\pm1,0)$, which rotated 90° clockwise is $(0,\pm1)$. There is a sign ambiguity because there are two possible rotations that satisfy your criteria; $(-1,0)$ results in the minimal rotation. The rotation matrix $R$ is therefore $$\begin{bmatrix}\pm1&0\\0&\pm1\end{bmatrix} \begin{bmatrix}u_x&-u_y\\u_y&u_x\end{bmatrix}^{-1} = \pm\begin{bmatrix} u_x & u_y \\ -u_y & u_x\end{bmatrix}.$$

We got lucky here because the target $y$-coordinate matched that of $C$, making the direction vector $\mathbf u$ easy to compute. More generally, to find $\mathbf u$ you’ll have to find the intersections of a circle of radius $AC$ centered at $C$ with the horizontal line $y=y_{target}$. That’s a straightforward application of the Pythagorean theorem.