Find distance from point to line using trigonometry 
I have a scene with center $C$ and outer corners A and B. I have a camera with a fixed focal length that I want to place at a fixed height, at a distance $d$ such that the entire scene is in view, while the camera looks at center point $C$. The situation is described in the picture above. Black labels are fixed, blue labels are variables.
I am trying to use trigonometric relations to find the formula for $d$, but I am failing miserably. I realize that if I find $\theta$ I can easily find $d$, but I'm not sure how to get $\theta$.
Could someone point me in the right direction?
 A: Let's write everything down. Put $X$ in the origin. Let $A(d,y_1)$ and $B(d,-y_2)$ and $C(z,-h)$. Unknowns: $z,d,y_1,y_2$. Constraints: fixed angle CXA, fixed angle CXB. You need two more pieces of information (4 unknowns, 4 equations). One is probably $AB=y_1+y_2$. You need another one (probably $\Delta=z-d$). Why? Because imagine sliding C horizontally to the right. You can keep AB distance and $\alpha$ fixed, by just rotating and moving the camera a little. So there are infinite possibilities until you know precise position of C relative to the AB line.
So... if you have all this information (AB distance + C displacement to the right), you can do it. How? Just write out the trigs:
$$\tan (\alpha-\theta)=\frac{y_1}{d}$$
$$\tan (\alpha+\theta)=\frac{y_2}{d}$$
$$\tan \theta = \frac{h}{z}=\frac{h}{\Delta+d}$$
Add together the first two equations:
$$AB=y_1+y_2=d(\tan(\alpha-\theta)+\tan(\alpha+\theta))$$
Addition formula for tangent is $\tan(\alpha\pm \theta)=\frac{\tan\alpha\pm \tan \theta}{1\mp \tan\alpha\tan\theta}$.
$$AB=y_1+y_2=d\left(\frac{\tan\alpha- \tan \theta}{1+ \tan\alpha\tan\theta}+\frac{\tan\alpha+\tan \theta}{1- \tan\alpha\tan\theta}\right)=$$
$$=2d\tan\alpha\frac{1+\tan^2\theta}{1-\tan^2\alpha\tan^2\theta}$$
Put in the third equation
$$AB(1-\tan^2\alpha\left(\frac{h}{\Delta+d}\right)^2)=2d\tan\alpha(1+\left(\frac{h}{\Delta+d}\right)^2)$$
$$AB((\Delta+d)^2-h^2\tan^2\alpha )=2d\tan\alpha((\Delta+d)^2+h^2)$$
It's not pretty, you have to solve a cubic equation for $d$, but at least you know what to do. You'll need to do it numerically. Iteration seems the simplest way.
A: This is not as complete an answer as I'd like, but it's too much to put in comments.
For any given value of $\alpha$ we can construct two circles, one with arc angle $2\alpha$ from $A$ to $C$, and another with arc angle $2\alpha$ from $B$ to $C$. Then $X$ would be at the second intersection of those circles
(not $C$) if there is one and if it is not on the $2\alpha$ arc of either circle.
Consider the locus of $X$ for $\alpha = 0$ up to $\alpha$ equal to half the field of view of your camera. (If $\alpha$ is larger, you won't see $A$ or $B$ in the picture frame.) This is some curve in the plane. If it intersects the given horizontal line at least once, each intersection is a possible solution. Otherwise there is no solution.
We could solve this numerically by taking the distance of $X$ above the desired line as a function $f(\alpha)$, and solve for $f(\alpha) = 0$.
But maybe there's a way to do this directly that I haven't seen yet.
If the best we can do is a numeric solution, I think it's simpler to find
the subtended angle of $A$ and $C$ (call this $\alpha_1$)
and the subtended angle of $B$ and $C$ (call this $\alpha_2$) both
as functions of the $x$-coordinate of $X$ on the given line.
Then solve for $x$ such that $\alpha_1(x) - \alpha_2(x) = 0$,
if such an $x$ exists.
But if you have a particular fixed value of $\alpha$ in mind, there will
be only two places (if any) where you can put $X$ in the plane.
Unless one of those points happens to be exactly on the line you want,
you have no solution. In other words, for a fixed $\alpha$ I think your
problem is overconstrained.
