From righanhled
△BCD, we get
BD=√p2+q2
Let ∠ADB=∠BDC=α
then ∠DAB=π−(α+θ)
and tanα=p/q.
Now from △ABD, we have
ABsinθ=BDsin[π−(θ+α)]=BDsin(θ+α)
∴AB=BDsinθsin(θ+α=BD2sinθBDsin(θ+α)
=BD2sinθBDsinθcosα+BDcosθsinα
=(p2+q2)sinθqsinθ+pcosθ
[∵BD2=p2+q2 and BDcosα=q and
BDsinα=p.]