[Math] Formula to find the third point of triangle when two points and all sides are known

euclidean-geometrygeometrytrigonometry

I am writing a program in java. I looking for formula to determine the 3rd point in a triangle if the length of all sides and the coordinates of two points are known.

Best Answer

Consider what you'd do with ruler and compass. Suppose your two known points are $A$ and $B$, then you'd draw a circle around $A$ with radius $AC$ and a circle around $B$ with radius $BC$. These circles would intersect in two points, either of which would qualify as $C$ unless you know the orientation of the triangle. To replicate this in a program, you have to implement (or find a library to compute) the intersection of two circles.

Since your question is tagged trigonometry, have a look at the cosine law. It allows you to compute (the cosine of) an angle given the three lengths of a triangle. So you can know how far along the line $AB$ you have to go, and using the Pythagorean theorem or some altitude formula you can also compute how far you have to go perpendicular to that line, in order to find $C$.

To be more precise, if $D$ is the point on line $AB$ such that both $\triangle ADC$ and $\triangle BDC$ have a right angle at $D$, then the cosine law gives you

\begin{align*} \lvert AD\rvert &= \frac{\lvert AB\rvert^2+\lvert AC\rvert^2-\lvert BC\rvert^2} {2\,\lvert AB\rvert} \\ \lvert BD\rvert &= \frac{\lvert AB\rvert^2+\lvert BC\rvert^2-\lvert AC\rvert^2} {2\,\lvert AB\rvert} \\ \lvert CD\rvert &= \frac{\sqrt{ \left(\lvert AB\rvert + \lvert AC\rvert + \lvert BC\rvert\right) \left(\lvert AB\rvert + \lvert AC\rvert - \lvert BC\rvert\right) \left(\lvert AB\rvert - \lvert AC\rvert + \lvert BC\rvert\right) \left(-\lvert AB\rvert + \lvert AC\rvert + \lvert BC\rvert\right) }}{2\,\lvert AB\rvert} \end{align*}