Is there any equation for triangle?

Like there's an equation of a circle, is there any equation of a triangle?


I've been trying to build one and the closest thing I've managed to do is to create an equation of 2 lines and use the $x$ axis as the 3rd side of the triangle.

Here's how I built the two lines equation:

Let $m$ be the slope of the first line, $-m$ is the slope of the second line, and $a$ is the x-value of their intersection point.

The first thing we need to do is to find the y-intercept of the second line. Let's call it $p$. The first line equation is $y=mx$ and the second line equation is $y=-mx+p$

$ma=-ma+p$

$p=2ma$

So we need to build an equation that equals to $y=mx+n$ when $x<a$ and to $y=-mx+2ma$ when $x>a$. First lets handle the slope. It should be $m$ when $x<a$ and $-m$ when $x>a$.

This can be achieved by:

$\dfrac {a-x} {|a-x|} m$

The y-intercept of the final equation should be $0$ when $x<a$ and $2ma$ when $x>a$.

This can be achieved by:

$(\dfrac {x-a} {|a-x|} + 1)*2ma$

So our equation looks like:

$y=\dfrac {a-x} {|a-x|} mx+(\dfrac {x-a} {|a-x|} + 1)*2ma$

Simplified:

$y=\dfrac {-m(x-a)^2} {|a-x|} + ma$

Or:

$y=m(x-a)sgn(a-x)+ma$

Plot $m=2, a=5$:

enter image description here


So is there any way to build an equation for triangle without using the $x$ axis as the 3rd side of the triangle?


Solution 1:

If you really, really want a single equation that defines a triangle, you could make one by a trick such as

$$ \big(|x-a|+|x-b|-|a-b|\big) \big(|x-b|+|x-c|-|b-c|\big) \big(|x-c|+|x-a|-|c-a|\big)=0 $$

where $x$ is the unknown and $a, b, c$ are the corners of the triangle, all being vectors.

However, such an equation won't in particular help you understand the triangle, nor will it be very helpful for reasoning about it or calculating things about it. In just about every conceivable application, a different representation of the triangle than an equation will be more useful.

Solution 2:

Some "closed" expressions for the triangle are quite useful, as is obvious from the following web page: Efficient 2-D & 3-D Point Probes.

The gist of the method is the so-called isoparametric ("same parameters") transformation, where "isoparametric" is a terminology which is quite common in Finite Element contexts. An elaborate explanation of it has been given, as an answer to the following MSE question: Converting triangles to isosceles, equilateral or right???

The formulas which express the local coordinates $\xi$ and $\eta$ into the global coordinates $x$ and $y$ are repeated here for convenience: $$ \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} $$ Here $\Delta$ is the determinant of the inverse transformation.
With the above, the "closed" triangle equation $T(x,y) = 0$ is simply given with: $$ T(x,y) = \min( \xi , \eta , 1 - \xi - \eta )$$ enter image description here
The maximum of the function $T$ is reached for $\xi = \eta = 1 - \xi - \eta = 1/3$ , hence at the midpoint (barycenter) of the triangle. If we draw straight lines from the midpoint towards the vertices, and further, then the whole plane is subdivided into three regions, one where $T(x,y) = \xi$ , one where $T(x,y) = \eta$ and one where $ T(x,y) = 1 - \xi - \eta$ . Our "inside/outside" function $T$ is zero at the triangle sides, positive inside and negative outside. It's shaped like a mountain with top $1/3$ at the midpoint and three sharply edged slopes downhill. The contour lines of this function are triangles, where the contour line with height $0$ is the original triangle itself. ( Quite the same is the case with the equation of e.g. a circle: $C(x,y) = 0$ with $C(x,y) = R^2 - (x-a)^2 - (y-b)^2$. )

A generalization of the linear triangle in 2-D to a linear tetrahedron in 3-D is given in the following answer : Computing a three-dimensional Lebesgue measure of a bounded set .