# Calculate the coordinates of the third vertex of triangle given the other two and the length of edges in the cheapest computational way

I simply have a triangle.. say abc . Given coordinates of a & b. and the length of ac and bc..

I can calculate the length between ab via the distance square rule.

$D = \sqrt{(X_2 - X_1)^2 + (Y_2 - Y_1)^2}$

I have tried to use the distance rule to compute the third vertex, but it has a lot of steps.. I wonder if there is another method.. that yields the two possible solutions for the vertex

• What are the X and Y? I don't quite understand what you're asking here... – The Count Feb 22 '17 at 21:02
• X and Y are just place holders for the coordinates of any point in the Cartesian plane.. and D is the distance between them – Shady Atef Feb 22 '17 at 21:03

Let $A = (x_A, y_A)$ and $B = (x_B,y_B)$ the known vertices of your triangle. Let's call $d_{AB}$, $d_{BC}$ and $d_{CA}$ the lengths of each side.

1. Translate your points subtracting $x_A$ and $y_A$ so that $A$ corresponds with the origin. That is:

$$A' = (0, 0), B' = (x_B-x_A, y_B-y_A ) = (x_B', y_B').$$

1. Rotate $B'$ so that it lies on the $x$-axis. This can be done without knowing the angle, indeed:

$$A'' = (0,0), B'' = (d_{AB}, 0).$$

Anyway, the value of the rotation angle is important for the next steps. In particular it is $$\theta = \arctan2\left(y_B-y_A,x_B-x_A\right),$$

where $\arctan2(\cdot, \cdot)$ is defined in details here.

1. At this point, it is easy to find $C''$. Notice that there are two solutions, since the point $C''$ can be placed above or below the side $AB$.

$$x_C'' = \frac{d_{AB}^2+d_{AC}^2-d_{BC}^2}{2d_{AB}},$$

and

$$y_C'' = \pm\frac{\sqrt{(d_{AB}+d_{AC}+d_{BC})(d_{AB}+d_{AC}-d_{BC})(d_{AB}-d_{AC}+d_{BC})(-d_{AB}+d_{AC}+d_{BC})}}{2d_{AB}}.$$

1. Now, rotate back your point $C''$ using $-\theta$ (see step 2), thus obtaining $C'$.
2. Finally, translate $C'$ by adding $x_A$ and $y_A$ to the components in order to obtain $C$.
• I was astonished .. Thanks – Shady Atef Feb 22 '17 at 22:02
• @ShadyAtef you are welcome – the_candyman Feb 22 '17 at 22:03
• It would be nice if you also provide the way to rotate C'' in step 4. – DDRamone Apr 24 '18 at 13:29
• This was a massive help, thank you. A few post-implementation notes: In step 2, calculate θ = arctan2(B'y, B'x) as it's simpler. Thus calculated, θ is the angle from the x-axis to B', so it is actually the opposite of the triangle's rotation angle as stated. So don't negate θ for step 4. Step 4, to counter-rotate your two C'' points [call them C1'' & C2''] back to C1' and C2' do: C1'x = C''x * cos(θ) - C1''y * sin(θ), C1'y = C''x * sin(θ) + C1''y * cos(0) and C2'x = C''x * cos(θ) - C2''y * sin(θ), C2'y = C''x * sin(θ) + C2''y * cos(0). – par Jul 19 '18 at 5:02

There is much easier solution, which has 3 steps instead of 5 and doesn't require translating or rotating:

$$φ_1 = \arctan2(B_y - A_y, B_x - A_x)$$

$$φ_2 = \arccos\left(\dfrac{l_1^2 + l_3^2 - l_2^2}{2\cdot l_1\cdot l_3}\right)$$

$$C = A + l_1\cdot[\cos(φ_1±φ_2)$$; $$\sin(φ_1±φ_2)]$$

Where $$A_x$$, $$A_y$$, $$B_x$$, $$B_y$$ are your given coordinates and $$l_1$$, $$l_2$$, $$l_3$$ are lengths of $$AC$$, $$BC$$ and $$AB$$ respectively (see the image). Note that there is $$±$$ sign, because you can build 2 triangles which will satisfy your problem.

Problem legend

This answer may be a bit late, but I hope other people who face this problem will find my solution useful.