Let the horizontal distance from the observation point to the building be d. The chimney on the roof subtends an angle of elevation of 45 degrees, so tan(45 degrees) = (h + chimney_height) / d. Since tan(45 degrees) is 1, the total height to the top of the chimney equals the horizontal distance, meaning d = h + chimney_height. The building itself subtends an angle of x degrees, so tan(x) = h / d. Rearranging this gives d = h divided by tan(x), which can also be written as d = h times cot(x). Substituting this value of d into the total height equation gives h + chimney_height = h times cot(x). Solving for the chimney's height, we subtract h from both sides to get chimney_height = h times cot(x) minus h. Factoring out h yields the final height of the chimney as h times (cot(x) minus 1), which algebraically is equivalent to h times tan(x) minus h.