Let OP = y and PQ = x represent the height of the house and the flag staff and the direction of the person is from D to O. Clearly the flag staff PQ subtends the greatest angle at a point A at which a circle through P, Q touches DO.
Hence ∠PAQ=θ and AO = d.
Let ∠OAP=α. Then in the alternate segment,
∠AQP=α so that
2α+θ=90o. ∴θ+α=90o−α ...(1)
As angle between chord AP and tangent at A is the same as the angle subtended by segment AP at any point Q on the circumference. Now,
PQ=OQ−OP=d(tan(α+θ)−tanα)
=d(cotα−tanα) by (1)
=2d(cos2α−sin2α)2sinαcosα
=2dcot2α=2dcot(90o−θ) by (1)
=2dtanθ
and OP=dtanα=dtan(45o−θ/2) by (1)