How can I rotate this triangle around corner A so the BC side lines up with point X? If I have this triangle shown below, the coordinates of corners $A$ and $C$ are known. As are the coordinates of point $X$.

Assuming the triangle can only rotate around corner $A$, how can I work out the red angle in order to make the $BC$ side line up with $X$? The red angle is between the $AB$ side and a vertical axis.
 A: 
Let's call $R$ the rotation matrix (rotate by the angle $k$) that bring the vector $\vec{AC}=C-A$ to the vector $\vec{AC'}=C'-A$. It means the $R(\vec{AC})=\vec{AC'}$ and
$$R=\begin{pmatrix}
\cos k & \sin k\\
-\sin k& \cos k
\end{pmatrix}$$
In the same way we have $R(\vec{AB})=\vec{AB'}$.
We also can suppose that we know $B$, because we know $A$ and $C$ and $\angle CAB=90°$. Actually we will find two options for $B$. In any case the next step is the same.
Now we have $B'$ and $C'$ as a function of the angle $k$.
Once $B',C',X$ are in the same line then we have:
$$\frac{y_{B'}-y_X}{x_{B'}-x_X}=\frac{y_{C'}-y_X}{x_{C'}-x_X}$$
and using that we can find the angle $k$.
A: Assume that the relative positions of points $A$ and $X$ are as drawn on the picture. Let $A = (u,v)$  and $X = (x,y)$ be the coordinates of the two points. The initial position of point $B$ is the only thing you need to know in order to calculate the distance between $A$ and $B$, which you have denoted by $c$. This data alone is enough to calculate the angle you want.
Assume that after rotating the triangle $ABC$ appropriately around vertex $A$, so that the line $BC$ is passes through point $X$, the new position of triangle $ABC$ is $AB'C'$ as drawn on the picture. You want to calculate angle $\angle \, B'AF = \theta$ from the drawing. 

Then $\theta = \angle \, B'AF = \angle \, B'AX + \angle \, XAF = \theta_1 + \theta_2$ where $$ \angle \, B'AX =\theta_1 \,\, \text{ and } \,\, \angle \, XAF = \theta_2$$ Triangle $AFX$ is right-angled with $FX = |x-u|$ and $AF = |y-v|$. Hence, by Pythagoras' theorem for triangle $AFX$
$$AX = \sqrt{(x-u)^2 + (y-v)^2}$$ Thus 
$$\cos(\theta_2) = \frac{AF}{AX} = \frac{|y-v|}{\sqrt{(x-u)^2 + (y-v)^2}} \, , \,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\, \sin(\theta_2) = \frac{FX}{AX} = \frac{|x-u|}{\sqrt{(x-u)^2 + (y-v)^2}}$$
Analogously, triangle $AB'X$ is right-angled so by Pythagoras' theorem $$B'X = \sqrt{AX^2 - AB'^2} = \sqrt{(x-u)^2 + (y-v)^2 - c^2}$$ and $$\cos(\theta_1) = \frac{AB'}{AX} = \frac{c}{\sqrt{(x-u)^2 + (y-v)^2}} \, , \,\,\,\,\,\,\,\,\,\,\, \sin(\theta_1) = \frac{B'X}{AX} = \frac{\sqrt{(x-u)^2 + (y-v)^2 - c^2}}{\sqrt{(x-u)^2 + (y-v)^2}}$$
By one of the trigonometric identities, 
$$\cos(\theta) = \cos(\theta_1+\theta_2) = \cos(\theta_1)\cos(\theta_2) -  \sin(\theta_1)\sin(\theta_2)$$ so simply substitute the already derived cosines and sines and finally
$$\cos(\theta)= \frac{c\,|y-v| - |x-u| \,\sqrt{(x-u)^2 + (y-v)^2 - c^2}}{{(x-u)^2 + (y-v)^2}}$$ The angle itself can be expressed as
$$\theta = \angle \, B'AX = \text{arccos}\left(\,\frac{c\,|y-v| - |x-u| \,\sqrt{(x-u)^2 + (y-v)^2 - c^2}}{{(x-u)^2 + (y-v)^2}}\,\right)$$ Have in mind that the relative confuguration of $A$ and $X$ may be different, then you may have to take care of some pluses or minuses here and there to adjust the formula. However, if $X$ is in first quadrant, relative to $A$, then this is the formula (or one possible explicit formula). 
