I have been struggling with a difficult problem involving 3D rotations. I first came across this problem in a computer science context, but I've attempted to generalize it a bit before posting.
(I apologize for not posting inline images and only being able to post 2/4 of my images, but I don't have enough reputation.)
Suppose you have a system with a unit sphere centered at the origin.
You also have a square "sheet" with marks on it, including a center point.
There is a camera at the origin which can have variable azimuth, pitch, and roll values. An azimuth of 0° corresponds to looking in the -z direction. Pitch is an up/down change, and roll is a tilt left/right.
From these three values, it is possible to determine a point (x,y,z) on the unit sphere that the camera has centered its view on. (Note that the roll value has no effect on the (x,y,z) position!)
What I would like is for the sheet to be centered at this (x,y,z) point, and also rotated properly so that it always appears in its default view (the top edge is still on top, no perspective foreshortening, etc.) when seen through the camera. Here's an example of what that might look like to an outside observer:
The issue is that the sheet has a default orientation - sides parallel to the x- and y-axes, and facing the +z direction. Here's what it looks like in that orientation:
sheet with default orientation
So, if I place the sheet in 3D space such that its center point is coincident with the unit sphere, the only case when the sheet is tangent (as I want) is when the camera is facing directly along the -z-axis (0 azimuth and 0 pitch). However, this is not enough, because the camera can also change in roll. For example, if the camera is facing along -z (0 azimuth) with 0 pitch, but 30° roll clockwise, then the sheet has to be rotated 30° around the z-axis.
Luckily, I can rotate the sheet around its local x, y, and z axes (each axis is parallel to its respective world axis and intersects the sheet's center point).
So the question is, given the (x,y,z) point on the unit sphere where I want the sheet to be centered, as well as the roll value of the camera, how do I rotate the default sheet around its local x-, y-, and z-, axes such that the sheet is tangent with the unit sphere, and properly oriented so that it appears upright with respect to the camera?
I have tried investigating such topics as spherical coordinates, Euler angles, rotation matrices, etc, but I can't fully understand them and/or they appear incomplete with respect to the constraints on this problem.