Determining Rotations Between Disc Axis and Line of Sight

Back to perspective correction page
If you have suggestions, please comment

Fig 1. Circular perspective target on reference scale, photographed obliquely (from the right and above). Superimposed on the photo, the red lines are the major/minor axes of the ellipse image. The major axis is tilted from camera-vertical by the angle ω. The horizontal axis of the disc (superimposed blue line) is at an angle θ with respect to camera-horizontal (superimposed black axis).

A disc photographed at an angle appears in the photo as an ellipse. From the shape and orientation of the ellipse, we can figure out the camera angle and the orientation of the disc.

An ellipse in the photo can be defined by the ratio of its axes and its tilt:

k ≡ 

b

a
 = 

length of minor axis

length of major axis
   (always less than 1)
ω ≡ angle of tilt of the major axis (with respect to vertical in the photo) (0 = vertical, +ve clockwise, -90° > ω ≥ 90°)

For the following analysis, we assume orthographic projection, ie., that the camera is viewing from an infinite distance. From an infinite distance, the center of the ellipse image in the photo will exactly match the center of the disc; in real life, there will be a small offset that depends on the focal length of the lens. Figure 1 is a photo taken with a digital camera with a moderate zoom lens (a focal length of about 105mm, in 35mm terms, and angle of view of 18 degrees); the center of the image ellipse is nearly coincident with the center of the disc.

[A camera at a distance approaching infinity needs a telephoto lens with an angle of view approaching zero. Long telephoto lenses have angles of view of a few degrees, and a 'normal' lens (50mm on a 35mm camera) has an angle of view of about 40 degrees. The angle of view for a lens is given by 2 tan-1 (d / 2f), where d is the width of the image and f is the focal length of the lens (both typically in millimeters). Thus a 200mm lens on a 35mm camera with 36mm-wide film frame has an angle of view of 10 degrees. For a given f, reducing d reduces the angle of view by roughly a proportional amount (so a 50mm lens on a digital SLR that has a sensor 50% the size of a 36mm film frame will have an angle of view ~50% smaller).]

Our goal is to figure out the angle(s) between the camera's view and the face of the disc -- in other words, figure out what rotations would be necessary to make the disc face the camera face-on.

(For the following derivations, Wikipedia's List of Trigonometric Identities is helpful.)

One Rotation

Fig 2. A rectified version of the image from figure 1 of this Angles of rotation web page, created by stretching the image perpendicular to the major axis by a factor of 1/k.

We know that however a disc is positioned, its major axis will always be perpendicular to the camera's line of sight and thus its major axis will always be equal to its diameter (which is why a utility hole cover cannot fall into a utility hole). Thus the semiminor axis (b/2) is the projection of the disc radius (a/2) upon the line of sight vector, giving us the angle γ between the disc axis and the camera line of sight:

sin (π/2 - γ) = 

b

a
 = k

cos γ = k

 γ = ±cos-1

Thus one rotation of the ellipse of γ about the major axis will align the disc axis to our line of sight (and thus we'd see the disc face-on). Similarly, stretching the image perpendicular to the major axis by a factor of 1/k will restore the ellipse to a circular shape (and rectify the surrounding scene if it is planar and parallel to the disc lying upon it) (and, of course, subject to the assumption of orthographic projection, ie., viewed from 'infinity'), for example, figure 2. Compressing the image parallel to the major axis by a factor of k is equivalent.

Aliases

A rotation of -γ will also satisfy cos(γ) = k, because cos(x) = cos(-x). This corresponds to a disc's ellipse being identical when viewed orthographically from an angle or its opposite, eg., from the left or the right, or from above or below.

Three Rotations

We can obtain different information by decomposing the single rotation above into two rotations, one horizontal and one vertical, by using the tilt of the ellipse in the image. These two rotations will be with respect to the frame of reference defined by the camera, and will only match the real world if: 1) the camera was horizontal, and 2) the camera was at the same vertical elevation as the disc.

Furthermore, if we know the disc was aligned with real-world horizontal (eg., the disc in Figure 1 aligned such that its horizontal line is level with the horizon, even if the disc is leaning back) and if the camera was level, then we can learn even more information from the image -- in addition to the real-world horizontal and vertical rotations of the disc, we can find the angle by which the camera was looking down -- all with respect to real-world horizontal.

Let's assume the camera was level but possibly looking down (or up) at an angle δ. Further, let's assume the disc is possibly lying back at an angle β and possibly rotated away from the camera at angle α. In other words:

δAngle of the camera's gaze (optical axis), relative to real-world horizontal plane (0 = camera is looking level; 90 degrees = camera is looking straight down)
βAngle of rotation about the real-world horizontal axis ('lie back') between the disc axis (ie., disc normal vector) and the real world horizontal plane (0 = no rotation, disc plane is vertical; 90 degrees = disc plane is horizontal, facing up)
αAngle of rotation about the real-world vertical axis between the disc axis (ie., disc normal vector) and the horizontal direction of view of the camera (0 = no rotation; 90 degrees = disc viewed left edge-on, disc plane facing right)

Assume orthogonal real-world unit vectors x,y,z, with the disc in the x,y plane (positive values right and up) with its axis aligned with the z axis (positive values in front of the disc, toward the camera located out along +z).

Consider the following rotations:

  1. Rotate the disc about the horizontal axis (x) by β (positive β pushes the top of the disc (+y) back, toward -z)
  2. Then rotate the disc about the vertical axis (y) by α (positive α pushes the right of the disc (+x) back, toward -z)

    The above-two rotations can put the disc into any possible ellipse shape. Now let's consider a final rotation to simulate the camera looking down or up upon the disc:

  3. Rotate the disc about the horizontal axis (x) by δ (positive δ moves the top of the disc (+y) forward, toward +z)

These rotations are given by the following standard transformation matrices for rotation about an axis, with signs adjusted for the rotation directions defined above:

100 cos α0sin α 100
0cos δ-sin δ 010 0cos βsin β
0sin δcos δ -sin α0cos α 0-sin βcos β

Projected onto the camera's 2-dimensional photo plane, the above yields:

cos α-sin α sin β (1)
sin α sin δcos β cos δ + cos α sin β sin δ

Let i,j be axes for the 2-dimensional photo plane; the 2x2 transformation matrix above (1) maps (x,y) of the disc to (i,j) in the photo (recall we assumed the disc is in the x,y plane, so all disc points have z=0), as follows:

i = T x where T is the 2x2 transformation matrix above, at (1)
j y

which yields:

i = x cos α - y sin α sin β(2)
j = x sin α sin δ + y (cos β cos δ + cos α sin β sin δ)(3)

The parametric equation of an ellipse at the origin of the i,j plane with its major axis on the j axis is:

i = k sin t (4) (an unrotated ellipse, major axis aligned with the j axis)
j cos t

('k' is the ellipse ratio defined above; k < 1 for an ellipse, k = 1 for a circle)

This ellipse can be matched to the one in the photo by rotating it by ω (clockwise) using the following rotation transformation:

i′ = cos ω sin ω k sin t (5) (clockwise rotation applied to ellipse aligned with the j axis)
j′ -sin ω cos ω cos t

which yields:

i′ = k cos ω sin t + sin ω cos t

Applying the identity:

a sin t + b cos t = √a2 + b2 sin (t + atan2(x=a, y=b))

= √k2 cos2 ω + sin2 ω sin (t + ...)

(6)

and:

j′ = -k sin ω sin t + cos ω cos t

= √k2 sin2 ω + cos2 ω sin (t + ...)

(7)

This rotated ellipse, in terms of k and ω, matches the photo ellipse. We can also obtain an ellipse matching the photo ellipse, but in terms of α, β, and δ, by applying transformation (1) to a parametric representation of a circle in the x,y plane, as follows:

x = T sin t where T is the 2x2 transformation matrix above, at (1)
y cos t

which yields:

x= cos α sin t - sin α sin β cos t
= √cos2 α + sin2 α sin2 β sin (t + ...)Applying the identity above. (8)
 
y= sin α sin δ sin t + (cos β cos δ + cos α sin β sin δ) cos t
= √sin2 α sin2 δ + (cos β cos δ + cos α sin β sin δ)2 sin (t + ...)Applying the identity above. (9)

Now we have two sets of ellipse equations that match the photo ellipse. The maximum extent of i′ and j′ in ellipse equations (6) and (7) must match the maximum extent of x and y in ellipse equations (8) and (9). Thus:

cos2 α + sin2 α sin2 β = √k2 cos2 ω + sin2 ω(10), from (8) & (6)

and:

sin2 α sin2 δ + (cos β cos δ + cos α sin β sin δ)2 = √k2 sin2 ω + cos2 ω(11), from (9) & (7)

Hanging onto the above relationships, let's try coming at it from a different tack:

Crosshair markings on the disc provide orientation information; let's assume the disc was positioned with the markings aligned with horizontal/vertical, such that the horizontal crosshair line is level (aligned with the real-world horizon).

In the photo to the right, the horizontal crosshair line appears rotated clockwise by θhorizon degrees. We can use this additional information to find the disc rotations. If the disc was oriented with the horizontal crosshair line level, the vertical crosshair line was originally aligned with the y-axis and the horizontal crosshair line was originally aligned with the x-axis.

The disc circumference point in the photo at θhorizon was at (1,0) in the x,y plane that contains the disc before rotations, and it is mapped to photo plane (i, j) by these equations copied from above:

i = x cos α - y sin α sin βCopy of (2)
j = x sin α sin δ + y (cos β cos δ + cos α sin β sin δ)Copy of (3)

For point (x=1, y=0), plugging x=1 and y=0 into (2) and (3), we get:

ihorizon = cos α(12)
jhorizon = sin α sin δ(13)

An ellipse matching the one in the photo plane is given by:

i′ = k cos ω sin t + sin ω cos tCopy of (6)
j′ = -k sin ω sin t + cos ω cos tCopy of (7)

The angle θhorizon is available from the photo; let's find the associated value t = thorizon. tan = y/x, so:

tan -θhorizon = -tan θhorizon

j′horizon

i′horizon
 = 

-k sin ω sin thorizon + cos ω cos thorizon

k cos ω sin thorizon + sin ω cos thorizon

Solving for thorizon:

thorizon = tan-1 

    1

k tan (ω - θhorizon)
( + π when π/2 < |ω - θhorizon| < 3π/2 )

as follows:

-sin θ

cos θ
 = 

-k sin ω sin t + cos ω cos t

k cos ω sin t + sin ω cos t

-k cos ω sin t sin θ - sin ω cos t sin θ = -k sin ω sin t cos θ + cos ω cos t cos θ

k sin t (sin ω cos θ - cos ω sin θ) = cos t (sin ω sin θ + cos ω cos θ)

k sin t sin (ω - θ) = cos t cos (ω - θ)

sin t

cos t
 = 

 cos (ω - θ)

k sin (ω - θ)

which allows (6) and (7) to be solved at t = thorizon, and then obtain α and δ from (12) and (13):

α = cos-1 ihorizon

δ = sign(δ) sin-1 

  jhorizon

  sin α  
 = sign(δ) sin-1 

   jhorizon

√1 - ihorizon2
   with sign(δ) discussed below

β is obtained from (10):

β = sign(β) cos-1 √ 

cos2 ω (1 - k2)

sin2 α
with sign(β) discussed below

as follows:

cos2 α + sin2 α sin2 β = k2 cos2 ω + sin2 ωCopy of (10), squared
1 - sin2 α + sin2 α (1 - cos2 β) = cos2 ω (k2 - 1) + 1Applying cos2 = 1 - sin2, and sin2 = 1 - cos2

sin2 α cos2 β = cos2 ω (1 - k2)

The signs for β and δ were determined by inspection of the results, as follows:

sign(β) = -sign(ivertical)

where ivertical is obtained from (6) at t = tvertical = thorizon - π/2. The vertical crosshair line is π/2 counterclockwise of the horizontal crosshair line in the parametric equation of the ellipse.

sign(δ) is positive if { [(θ - ω) is in 1st or 4th quadrant] exclusive-or [ω is in the 2nd or 3rd quadrant] }, otherwise negative; when negative, add π.

Aliases

Consider the rotation matrix from (1):

cos α-sin α sin β (1)
sin α sin δcos β cos δ + cos α sin β sin δ

Fig 3. An example of four sets of rotations that result in an identical ellipse and markings in orthographic view (viewed here in perspective view).

The following substitutions yield identical matrix values:

[α, β, δ] → [-α, -β, -δ]

sin(-x) = -sin(x), and
cos(-x) = cos(x)

[β, δ] → [π - β, π - δ]sin(π - x) = sin(x), and
cos(π - x) = -cos(x)

Thus the following four sets of rotations:

[α, β, δ][-α, -β, -δ]
[α, π - β, π - δ][-α, β - π, δ - π]

will yield ellipses and markings that are identical when viewed orthographically, ie., from infinity.

However, likely the view will be from somewhat closer than infinity and thus the reference scale and the scene will likely contain some degree of perspective projection, which can assist in choosing between the four aliases. Figure 3 shows an example of the four aliases when viewed up close with perspective projection.

In practice, regarding the reference scale, there will usually be contextual clues as to which alias best describes a situation. The lower pair in figure 3 are unlikely; they correspond to pushing the top of the scale back 130°, which would result in the scale 'facing away' from a unrotated camera except if the camera also is rotated about the same axis enough to bring the scale's face back into view, with the scale and camera now upside down, as in figure 4:

Fig 4. Two rotational aliases, resulting in identical ellipse images, one highly unlikely.

Thus usually it will be a choice between the 'left' and 'right' aliases, eg., aliases in the top row of figure 3.

Two Rotations

The one rotation about the major axis that aligns the disc's axis with the line of sight can be decomposed into two rotations about the two axes (vertical and horizontal) defined by the camera's frame of reference (which may or may not correspond to the real world, depending on whether the camera was level and at the same elevation as the disc). This might be useful if the disc or camera weren't aligned with real-world vertical, or if a disc with no markings were used, etc.

α2Angle of rotation about the camera frame's vertical axis between the disc axis and the horizontal direction of view of the camera (0 = no rotation; 90 degrees = viewed left edge-on, disc facing right)
β2Angle of rotation about the camera frame's horizontal axis ('lie back') between the disc axis and the real world horizontal plane (0 = no rotation, disc is vertical; 90 degrees = disc is flat, facing up)

From the camera's frame of reference, α2 and β2 are relative to the camera and δ2 is always 0. Thus we can obtain the two rotation solution as a special case of the three rotation solution.

When δ2 = 0, equation (11) reduces to:

cos β2 = ±√ k2 sin2 ω + cos2 ω               (14)

Solving (10) and (14) for α and β:

α2 = sin-1 √ 

    cos2 ω (k2 - 1)  

sin2 ω (1 - k2) - 1

β2 = ±sin-1 sin2 ω (1 - k2)      (negative when ω is in quadrant I and IV)

Aliases

The rotation matrix for two rotations is:

cos α2-sin α2 sin β2
0cos β2

The following substitution yields identical matrix values:

2, β2] → [-α2, -β2]

Thus a given ellipse with markings can be generated identically by a pair of two-rotations.

Four Rotations?

Real-world information (eg., the horizon), if available in the photo, could be used in a fourth rotation to compensate for the camera not being level.

Conceivably an elliptical image of a real-world disc could be isolated from a photo using computer vision techniques, thus obtaining information about orientation.