# Calculate the coordinates of the third vertex of triangle given the other two and the length of edges

Using the solution from the_candyman

the_candyman (https://math.stackexchange.com/users/51370/the-candyman), Calculate the coordinates of the third vertex of triangle given the other two and the length of edges in the cheapest computational way, URL (version: 2017-02-22): https://math.stackexchange.com/q/2156910

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$.

My question is:

How can I perform step 4 and five?