Let AB = x
In $\triangle DAM$, tan $ (\pi -
heta - \alpha) = \frac{p}{ x - q}$
$\Rightarrow tan (
heta + \alpha ) = \frac{p}{ q - x} $
$\Rightarrow q - x \, p \, cot (
heta + \alpha) $
$\Rightarrow x = q - p \, cot
heta + \alpha) $
= q - p $ \bigg( \frac{ cot \,
heta \, cot \, \alpha - 1}{ cot \, \alpha + cot \,
heta } \bigg) $ $ \hspace25mm$ $ \Bigg [ \because \, cot \, \alpha = \frac{q}{p} \Bigg ] $
= q - p $ \Bigg ( \frac{ \frac{q}{p} cot \,
heta - 1 }{ \frac{q}{p} + cot \,
heta }\Bigg ) = q - p \bigg( \frac{ q \, cot \,
heta - p }{ q + p cot \,
heta } \bigg)$
= q - p $ \bigg ( \frac{ q \, cos \,
heta - p sin \,
heta }{ q \, sin \,
heta + p \, cos \,
heta }\bigg) $
$\Rightarrow x = \frac{ q^2 \, sin \,
heta + pq \, cos \,
heta - pq \, cos \,
heta + p^2 \, sin \,
heta }{ p \, cos \,
heta + q \, sin \,
heta } $
$\Rightarrow AB = \frac{(p^2 + q^2) \, sin \,
heta }{ p \, cos \,
heta + q \, sin \,
heta } $
Alternate Solution
Applying sine rule in $\triangle ABD$,
$\frac{AB}{sin \,
heta } = \frac{ \sqrt{ p^2 + q^2}}{ sin \, \{ \pi - (
heta + \alpha) \}}$
$\Rightarrow \frac{ AB}{ sin \,
heta } = \frac{ \sqrt { p^2 + q^2 }}{ sin \, (
heta + \alpha)} $
$\Rightarrow AB = \frac{ \sqrt{ p^2 + q^2 }}{ sin \,
heta cos \alpha + cos
heta sin \alpha } \bigg [ \because cos \, \alpha = \frac{ q}{ \sqrt{p^2 + q^2}} \bigg ] $
= $\frac{(p^2 + q^2 ) \, sin \, ? }{ p \, cos \, ? + q \, sin \, ?} = \frac{p}{\sqrt{ p^2 + q^2 }} $