Calculate a triangle based on one angle and the lengths on either side of the perpendicular Considering a standard triangle as shown here:

h is perpendicular to c.
I know the lengths p and q, and angle C. It seems to me like that should completely define the triangle. The trouble is I cannot come up with the formulas to calculate the other lengths and angles.
The best solution I came up with so far is an iterative process:
c = p + q
Split angle C in C1 = C * p / c and C2 = C * q / c
Next, calculate: p / tan C1 - q / tan C2
If that is positive, add a small amount to C1 and subtract the same amount from C2. If negative, do the opposite.
Repeat the calculation and reduce the amount applied to the angles until I get "close enough".
But I expect there should be a more direct approach.
A simple example: q = 80, p = 45, and C = 90 degrees (π/2 rad).
Another example: q = 45, p = 32, and C = 64.9423845817 degrees (1.133458435047 rad).
Note: I initially asked this question on stackoverflow.com, but was told that math.stackexchange.com would be a better place for such questions.
 A: There is a closed formula for the remaining sides: 
$$\begin{align}
a&=\sqrt{q^2+h^2}\\
b&=\sqrt{p^2+h^2}
\end{align}$$
Where $h$ is calculated using $r$, in the following way:
$$\begin{align}
r&=\frac{q+p}{2\sin(\gamma)}\\
h&=\sqrt{r^2-\left(\frac{q-p}{2}\right)^2}\mp\sqrt{r^2-\left(\frac{q+p}{2}\right)^2}
\end{align}$$
Where $\gamma\in(0,\pi)$ is the angle at point $C$, and "$\mp$" is resolved as:
$$
\mp=\begin{cases}-,& \text{if }\gamma\ge \pi/2\\+,& \text{if }\gamma\le \pi/2\end{cases}
$$
To see how we can obtain this, read the rest of the answer.


I solved this using the "Inscribed Angle Theorem" mentioned in the comments.

We first observe a triangle with sides $r,q+p,r$ and angle $2\gamma$ above $q+p$.
The Law of Cosines gives fruit (where $q+p=c$): 
$$
r=\frac{q+p}{\sqrt{2-2\cos(2\gamma)}}=\frac{c}{2\sin(\gamma)}
$$
WLOG the point above $q+p$ is $C'=(0,0)$.
Consider a circle with radius $r$ centered at $C'$, which will be given by $x^2+y^2=r^2$.
To get coordinates of $C$, we use Inscribed Angle Theorem  linked by Blue in the comments.
Your point $C=(\frac{q-p}{2},y_c)$ is then the intersection of the circle and the line $x=\frac{q-p}{2}$.
$$
y_c= \pm\sqrt{r^2-\left(\frac{q-p}{2}\right)^2}
$$
WLOG assume the positive solution (that $C$ is above $C'$), hence $\pm\to+$.
The height of $B,A$ points is given by Pythagoras' Theorem on the $C'AB$ triangle.
$$
y_b=y_a=\pm\sqrt{r^2-\frac{c^2}{4}}
$$
Because of our assumption for $y_c$, here for $y_b=y_a$ the $\pm$ will depend on the $\gamma$. That is, if $2\gamma\ge\pi$ then $C'$ is below $\overline{AB}$, and else if $2\gamma\le\pi$ then $C'$ will be above $\overline{AB}$.
Their $x$-coordinates are simply $x_b=x_c-q$ and $x_a=x_c+p$.
Now we can get the sides $a,b$ as distances $a=d(C,B)$ and $b=d(C,A)$.
$$
a=\sqrt{(x_c-x_b)^2+(y_c-y_b)^2}\\
b=\sqrt{(x_c-x_a)^2+(y_c-y_a)^2}
$$
And we have all sides of the triangle now.
A: 
An alternative way using the identity
\begin{align}
\cot(\gamma_1+\gamma_2) 
&= 
\frac{\cot\gamma_1\cot\gamma_2-1}{\cot\gamma_1+\cot\gamma_2}
\tag{1}\label{1}
.
\end{align}
Let $|AB|=c=p+q$,
$|CD|=h$,
$\angle BCA=\gamma$,
$\angle DCA=\gamma_1$,
$\angle BCD=\gamma_2$.
\begin{align}
\triangle ADC:\quad
\cot\gamma_1&=\frac{h}{q}
\tag{2}\label{2}
,\\
\triangle BCD:\quad
\cot\gamma_2&=\frac{h}{p}
\tag{3}\label{3}
.
\end{align}
Using \eqref{1}, we have
\begin{align}
\cot\gamma 
&= 
\frac{\cot\gamma_1\cot\gamma_2-1}{\cot\gamma_1+\cot\gamma_2}
=
\frac{\tfrac{h^2}{pq}-1}{\tfrac hp+\tfrac hq}
=\frac{h^2-pq}{(p+q)h}
=\frac{h^2-pq}{c\,h}
\tag{4}\label{4}
.
\end{align}
\eqref{4} is equivalent to the quadratic equation in $h$:
\begin{align}
h^2-c\,\cot(\gamma)\,h-pq&=0
\tag{5}\label{5}
,
\end{align}
with two solutions
\begin{align}
h_1
&=
\tfrac12\,c\,\cot(\gamma)
+\tfrac12\,\sqrt{c^2\,\cot^2(\gamma)+4pq}
\tag{6}\label{6}
,\\
h_2
&=
\tfrac12\,c\,\cot(\gamma)
-\tfrac12\,\sqrt{c^2\,\cot^2(\gamma)+4pq}
\tag{7}\label{7}
.
\end{align}
Note that 
$|c\,\cot(\gamma)|<\sqrt{c^2\,\cot^2(\gamma)+4pq}$,
so the expression \eqref{7}
would be negative
in both cases,
whether $\gamma$ is obtuse or acute,
that is, 
whether $\cot\gamma$ is positive or negative,
the expression \eqref{7} would be always negative,
and the expression \eqref{6} positive, so the only suitable (positive) 
solution is 
\begin{align}
h
&=
\tfrac12\,c\,\cot(\gamma)
+\tfrac12\,\sqrt{c^2\,\cot^2(\gamma)+4pq}
\tag{8}\label{8}
.
\end{align}
A: 
\begin{align} 
|AB|=c&=p+q
,\\
\end{align} 
By the sine rule, 
\begin{align}
R&=\frac c{2\sin\gamma}
.
\end{align} 
Let $|CE|=h$. Then 
\begin{align}
S_{ABC}&=\tfrac12ch
,\\
S_{ABC}&=\tfrac12\cdot|AC|\cdot|BC|\sin\gamma
\end{align}
$|AC|$ and $|BC|$ in terms of $h$:
\begin{align}
|AC|&=\sqrt{q^2+h^2}
,\\
|BC|&=\sqrt{p^2+h^2}
,
\end{align}
and we have 
\begin{align}
c^2h^2&=(p^2+h^2)(q^2+h^2)\sin^2\gamma
,
\end{align}
which results in
\begin{align}
h^2&=
\tfrac12\,(c^2\,\cot^2\gamma+2pq)
\pm\sqrt{\tfrac14\,(c^2\,\cot^2\gamma+2pq)^2-p^2q^2}
.
\end{align}
Edit
Actually, the last expression can be simplified further,
and we have a neat single expression for $h$
\begin{align}
h&=
\tfrac12\,c\,\cot\gamma
+\tfrac12\,\sqrt{c^2\cot^2\gamma+4pq}
,
\end{align}
which automatically handles acute/obtuse angle $\gamma$,
so the two other side lengths are simply
\begin{align}
a&=c\sqrt{\frac pc
+\tfrac12\cot\gamma\,
\left(\cot\gamma+\sqrt{\cot^2\gamma+4\,\frac {pq}{c^2}}
\right)}
,\\
b&=c\sqrt{\frac qc
+\tfrac12\cot\gamma\,
\left(\cot\gamma+\sqrt{\cot^2\gamma+4\,\frac {pq}{c^2}}
\right)}
.
\end{align}
