Converting triangles to isosceles, equilateral or right???

I've been wrecking my brain with this problem and I really hope you can help me. You see I have a triangle that is either an isosceles or equilateral or right and I have to find a way to: 1)Convert it to a right one by moving one of its vertices, 2)Convert it to an isosceles one by moving one of its vertices, 3)Convert it to an equilateral one by moving two of its vertices. I am trying to write a program in C that will do this but unfortunately I can't figure out the math. Hope you can help. Thank you in advance.


Solution 1:

Perhaps your question can be answered by a standard piece of Finite Element theory. Here comes.

Let's consider the simplest non-trivial finite element shape in two dimensions: the linear triangle. Function behaviour is approximated inside such a triangle by a linear interpolation between the function values at the vertices, also called: nodal points. Let $T$ be such a function, and $(x,y)$ coordinates, then: $$ T = A.x + B.y + C $$ Where the constants A, B, C are to be determined. Substitute $ x=x_k $ and $ y=y_k $ with $ k=1,2,3 $: $$ \left[ \begin{array}{c} T_1 \\ T_2 \\ T_3 \end{array} \right] = \left[ \begin{array}{ccc} 1 & x_1 & y_1 \\ 1 & x_2 & y_2 \\ 1 & x_3 & y_3 \end{array} \right] \left[ \begin{array}{c} C \\ A \\ B \end{array} \right] $$ The first of these equations can already be used to eliminate the constant $C$, once and forever: $$ T_1 = A.x_1 + B.y_1 + C $$ Resulting in: $$ T - T_1 = A.(x - x_1) + B.(y - y_1) $$ Hence the constants $A$ and $B$ are determined by: $$ \begin{array}{ll} T_2 - T_1 = A.(x_2 - x_1) + B.(y_2 - y_1) \\ T_3 - T_1 = A.(x_3 - x_1) + B.(y_3 - y_1) \end{array} $$ Two equations with two unknowns. The solution is found by straightforward elimination, or by applying Cramer's rule: $$ \begin{array}{ll} A = [ (y_3 - y_1).(T_2 - T_1) - (y_2 - y_1).(T_3 - T_1) ] / \Delta \\ B = [ (x_2 - x_1).(T_3 - T_1) - (x_3 - x_1).(T_2 - T_1) ] / \Delta \end{array} $$ There are several forms of the determinant $\Delta$, which should be memorized when it is appropriate: \begin{eqnarray*} && \Delta = (x_2 - x_1).(y_3 - y_1) - (x_3 - x_1).(y_2 - y_1) \\ && \Delta = 2 \times \mbox{ area of triangle } \\ && \Delta = x_1.y_2 + x_2.y_3 + x_3.y_1 - y_1.x_2 - y_2.x_3 - y_3.x_1 \\ && \Delta = x_1.(y_2 - y_3) + x_2.(y_3 - y_1) + x_3.(y_1 - y_2) \\ && \Delta = y_1.(x_3 - x_2) + y_2.(x_1 - x_3) + y_3.(x_2 - x_1) \\ && \Delta = \left\| \begin{array}{ccc} 1 & x_1 & y_1 \\ 1 & x_2 & y_2 \\ 1 & x_3 & y_3 \end{array} \right\| \end{eqnarray*} Anyway, it is concluded that: $$ T - T_1 = \xi.(T_2 - T_1) + \eta.(T_3 - T_1) $$ Where: $$ \begin{array}{ll} \xi = [ (y_3 - y_1).(x - x_1) - (x_3 - x_1).(y - y_1) ] / \Delta \\ \eta = [ (x_2 - x_1).(y - y_1) - (y_2 - y_1).(x - x_1) ] / \Delta \end{array} $$ Or: $$ \left[ \begin{array}{c} \xi \\ \eta \end{array} \right] = \left[ \begin{array}{cc} + (y_3 - y_1) & - (x_3 - x_1) \\ - (y_2 - y_1) & + (x_2 - x_1) \end{array} \right] / \Delta \left[ \begin{array}{c} x - x_1 \\ y - y_1 \end{array} \right] $$ The inverse of the following problem is recognized herein: $$ \left[ \begin{array}{c} x - x_1 \\ y - y_1 \end{array} \right] = \left[ \begin{array}{cc} (x_2 - x_1) & (x_3 - x_1) \\ (y_2 - y_1) & (y_3 - y_1) \end{array} \right] \left[ \begin{array}{c} \xi \\ \eta \end{array} \right] $$ Or: $$ \begin{array}{ll} x - x_1 = \xi .(x_2 - x_1) + \eta.(x_3 - x_1) \\ y - y_1 = \xi .(y_2 - y_1) + \eta.(y_3 - y_1) \end{array} $$ But also: $$ T - T_1 = \xi .(T_2 - T_1) + \eta.(T_3 - T_1) $$ Therefore the same expression holds for the function $T$ as well as for the coordinates $x$ and $y$ . This is precisely what people mean by an isoparametric ("same parameters") transformation, a terminology which is quite common in Finite Element contexts. Now recall the formulas which express $\xi$ and $\eta$ into $x$ and $y$ : $$ \begin{array}{ll} \xi = [ (y_3 - y_1).(x - x_1) - (x_3 - x_1).(y - y_1) ]/\Delta \\ \eta = [ (x_2 - x_1).(y - y_1) - (y_2 - y_1).(x - x_1) ]/\Delta \end{array} $$ Thus $\xi$ can be interpreted as: area of the sub-triangle spanned by the vectors $ (x - x_1 , y - y_1) $ and $ (x_3 - x_1 , y_3 - y_1) $ divided by the whole triangle area. And $\eta$ can be interpreted as: area of the sub-triangle spanned by the vectors $ (x - x_1 , y - y_1) $ and $ (x_2 - x_1 , y_2 - y_1) $ divided by the whole triangle area. This is the reason why $ \xi $ and $ \eta $ are sometimes called area-coordinates; see the figure below, where (two times) the area of the triangle as a whole is denoted as $\Delta$. There exist even three of these coordinates in literature. But the third area-coordinate is, of course, dependent on the other two, being equal to $(1-\xi-\eta)$. Instead of area-coordinates, we prefer to talk about local coordinates $\xi$ and $\eta$ of an element, in contrast to the global coordinates $x$ and $y$. It is possible that local coordinates coincide with the global coordinates. A triangle for which such is the case is called a parent element. The portrait of the parent triangle is also depicted in the same figure: the two sides of it are coincident with the unit vectors in a Cartesian coordinate system.
So far so good about standard FEM. Now about your real problem (I hope).

Suppose you have two triangles, one with coordinates $\left\{ (x_1,y_1), (x_2,y_2), (x_3,y_3) \right\} $ and one with coordinates $\left\{ (x'_1,y'_1), (x'_2,y'_2), (x'_3,y'_3) \right\} $, then it is always possible to transform the first triangle into the second via the parent element. As follows. $$ \left[ \begin{array}{c} x - x'_1 \\ y - y'_1 \end{array} \right] = \left[ \begin{array}{cc} (x'_2 - x'_1) & (x'_3 - x'_1) \\ (y'_2 - y'_1) & (y'_3 - y'_1) \end{array} \right] \left[ \begin{array}{c} \xi \\ \eta \end{array} \right] $$ $$ \left[ \begin{array}{c} \xi \\ \eta \end{array} \right] = \left[ \begin{array}{cc} (x_2 - x_1) & (x_3 - x_1) \\ (y_2 - y_1) & (y_3 - y_1) \end{array} \right]^{-1} \left[ \begin{array}{c} x - x_1 \\ y - y_1 \end{array} \right] $$ The resulting transformation is independent of rotation and scaling of the global coordinates, i.e. it leaves similarities intact at both sides. So if you have two sample triangles that are transformed into each other, then all triangles that are similar to those two are transformed in the same way.enter image description here

Solution 2:

First of all it would be nice to post you thought on the question and what you've already done, this will give everyone a better idea of you knowledge and they can point where is your mistake.

Here are some hint for you questions:

a) If you want to make a right triangle, use some properties of it. Where does circumcentre lies in right triangle? How can this help you?

b) Where does the vertex of the isoscelec triangle opposite from the base lies? Doesn't it lie on the line that bisect the base?

c) In equilaterial triangle all sides are equal. Can you use this property? Further hint use circles with same radii.


Since you want to write code for this I'll give you additional hint.

First of all find the coordinates of the three given vertices. Now we can continue:

a) Find the middle point of the non moving side, opposed to the moving vertex. Draw a circle with radius of the half of the fixed side. The equation for a circle is:

$$(x-x_0)^2 + (y-y_0)^2 = r^2$$

Where $(x_0, y_0)$ are the coordinates of the circumcentre. Now for a point $x$ such thah $(x-x_0)^2 \le r^2$ you'll find a solution for $y$ and a pair of point $(x,y)$ for the third vertex such that we'll have right triangle.

b) Find the equation for the bisector of the fixed side. Because this line has to pass throught the middle point of the fixed side. Find the coordinates of that point. Then use the slope-formula:

$$y-y_0 = m(x-x_0)$$

where $(x_0,y_0)$ are the cooridnates of the middle point. We know that the slope of the bisector is the negative reciprocal of the slope of the line. Find the slope of the fixed side and the rest of the should be easy. Then choose some $x\neq x_0$ and you'll get one point using the equation of the bisector.

c) Find the length of the fixed side, using the distance formula. Then find the intersection of the circles centered on the verteces of the fixed sides with radii of the length of the fixed side. To obtain the equation for the circles, use the same method I showed in a)