Find the desired angle I have a wall mounted camera looking at barcodes on warehouse shelves where all the shelves are a known size. 
In order to calibrate the camera, I have some oversized QR codes that are mounted in specific locations (top-left of shelf, top right, bottom-left and bottom right).
The camera can successfully detect the QR codes and log their locations in pan/tilt coordinates: pan ($-180$ through $180$) and tilt ($-180$ though $180$).
I need to be able to tell the camera to pan to the leftmost portion of a specific shelf (say the 3rd shelf down) and start panning rightwards looking for content. Let's leave the 3-dimensional component out of it for now and focus on the top/bottom component. 
Assuming that the whole shelf is 100" tall and the QR codes are 3" tall each. Assume further that I know the pan angle to the top and bottom of each QR code: topLeftQR-Top (black), topLeftQR-Bottom (green), BottomLeftQR-top (purple) and BottomLeftQR-Bottom (blue). 
How do I find the correct pan angle (red) to target the camera to a specific desired location on the shelf (e.g. 45" up from the bottom).

 A: Try this:


*

*Assume WLOG that your points are $(0,0) (3,0) (97,0), (100,0)$.  Assume your camera is at $(x,y)$.

*Write down expressions for the distance from your camera to each above point, these will be algebraic functions of x and y.  (For example, the first is $sqrt(x^2+ y^2))$.  Call these distances $d_1,d_2,d_3, d_4$.  

*Write down the law of cosines for each of the 3 angles you have observed.

*This should give you 3 equations in 2 unknowns, and you can backsolve for $(x,y)$. 

*Knowing $(x,y)$, use law of cosines again to find angle to arbitrary point $(t,0)$ that you are looking for.


I will note that this sounds very numerically sensitive - imagine in the limit that the QR codes were 1 millimeter wide, or that the camera was quite far off, this would easily fail due to rounding or measurement error.
A: If the rack of shelves is near vertical and you don’t need a lot of precision to get the camera pointed at the correct shelf, then you can get a good result via simple triangulation.  

Let positive tilt angles represent pointing the camera above the horizontal, and let $h$ be the known vertical distance between the upper and lower QR code target points and $d$ the horizontal distance from the camera to the shelf face. Referring to the above illustration, we have $$h={d\over\tan\alpha}+{d\over\tan\beta}$$ which when solved for $d$ gives $$d={\sin\alpha\sin\beta\over\sin(\alpha+\beta)}h.$$ Substituting $\alpha=\frac\pi2-\theta_{\text{top}}$ and $\beta=\frac\pi2+\theta_{\text{bot}}$ and simplifying, we end up with $$d={\cos\theta_{\text{top}}\cos\theta_{\text{bot}}\over\sin(\theta_{\text{top}}-\theta_{\text{bot}})}h.$$ A tilt angle of $0$ thus corresponds to a point at a distance of $d\tan\theta_{\text{top}}$ below the upper target (above if this value is negative, of course) and so the tilt angle for a point at a distance $y\ge0$ below the top satisfies $$\tan\theta={d\tan\theta_{\text{top}}-y\over d}=\tan\theta_{\text{top}}-\frac yd.$$ I’ll leave it to you to work out the corresponding formulas for distances measured from the bottom target instead. Watch out for sign errors!  
If you need more precision than this or the shelves are not near-perpendicular to the camera’s zero-tilt line, then you’ll need to do something more elaborate, such as the calculation described in Oren’s answer, or perhaps involving a homography between the camera image and the shelf-face plane (which isn’t particularly difficult to compute in this case). A potential benefit of the latter is that once you’ve computed the transformation matrix, you can find the world-coordinate ray from the camera to any point on the shelf-face plane.
One way to get a more accurate solution is to observe that the vertex of a triangle with a given angle and opposite side length lies on a circular arc. Let $\Delta\theta_{out}=\theta_{top}-\theta_{bot}$ be the angular difference between the tilt angles for the outer edges of the top and bottom QR codes, with actual distance $h$ between them, and let $\Delta\theta_{in}$ be the tilt angle difference between the inner edges, with distance $h-2q$. If we let the line segment from $(0,-h/2)$ to $(0,h/2)$ represent the shelf face, then the camera lies at the intersection of the circles $(x+c_{out})^2+y^2=r_{out}^2$ and $(x+c_{in})^2+y^2=r_{in}^2$. Subtracting the first equation from the second yields a linear equation for $x$ with solution $$x={(r_{out}^2-r_{in}^2)-(c_{out}^2-c_{in}^2)\over2(c_{out}-c_{in})}.\tag1$$ We also have $$r_{out}={h\over2\sin\Delta\theta_{out}}, c_{out}=r_{out}\cos\Delta\theta_{out} \\ r_{in}={h-2q\over2\sin\Delta\theta_{in}}, c_{in}=r_{in}\cos\Delta\theta_{in}.$$ Substituting these values into (1) and simplifying results in $$x={q(h-q)\over h\cot\Delta\theta_{out}-(h-2q)\cot\Delta\theta_{in}}.\tag2$$ The absolute value of $x$ is the perpendicular distance $d$ to the shelf face. From here, you can compute the $y$-coordinates of the intersections, choose the one that corresponds to the situation that you have, and use that point to compute a tilt angle bias $\delta$ (which is also the angle by which the shelves deviate from being perpendicular to the zero-tilt line). You can then proceed as before, adjusting the resulting tilt angles by $\delta$. This computation might also be necessary if the camera isn’t level, i.e., zero tilt is significantly off the horizontal.  
