CS184 Lecture 8 summary

Finding the object (continued from lecture 7)

Our goal is to place the camera at some arbitrary position v =(vX, vY, vZ), and to rotate the viewpoint so that the origin (where most objects are centered) projects to the center of the screen. That means that the -Z' direction of the viewpoint frame should go through the origin. This gives us the first condition on directing the viewpoint:

1.  If the viewpoint is at v, that means that v and Z' should be parallel.

Furthermore, the "natural" appearance of objects is with their Y-axis up, or orthogonal to the X'-axis. That will happen if

2. The Y' axis and Y should be co-planar (in fact they will intersect).

If the viewpoint corresponds to a coordinate frame X', Y', Z', we can achieve these two conditions by computing the viewpoint axes as follows:

Z' = v/|v| where v is the viewpoint position, to align Z' with the view center v.

X' = Y x v / |Y x v| which ensures that X' is normal to Y and Z' (and therefore normal to Y').

Y' = Z' x X' which ensures that Y' is in the same plane as Y (normal to X').

The rotation R = (X', Y', Z') transforms points represented in viewer coordinates to world coordinates, if the viewer system requires rotation only. To translate points as well, we use the transformation T which is

[ R    v ]
[ 0    1 ]

which maps the origin in the viewer frame to v in the world frame.

Dont forget that this is the transform from viewpoint coordinates to world coordinates. In order to map a point p in world coordinates to p' in viewer coordinates, we apply the inverse T-1 to p which gives

[ p' ]  =  [ RT   -RT v ] [ p ]
[  1 ]  =  [ 0         1    ] [ 1 ]

With the point p' in viewer coordinates, we can apply an orthographic or perspective projection to derive the screen coordinates (x', y').

Example

Suppose we place the viewpoint at (5, 10, 15). Then using the above expressions the viewer frame is defined by

Z' = ( 0.2673   0.5345   0.8018)
X' = ( 0.9487  0             -0.3162)
Y' = (-0.1690  0.8452  -0.5071)

v  = ( 5, 10, 15 )

So the matrix R is (X' Y' Z') which is

[  0.9487   -0.1690   0.2673  ]
[  0.0           0.8452    0.5345  ]
[ -0.3162   -0.5071   0.8018  ]

To represent the matrix R = (X', Y', Z') in axis-angle form, we compute R - RT, which is

[   0.0           -0.1690    0.5835 ]
[  0.1690      0.0           1.0416 ]
[ -0.5835   -1.0416     0.0         ]

From which the anti-symmetric part is s = (-R23, R13, -R12) = (-1.0416, 0.5835, 0.1690). The rotation axis is the normalized vector

a = s/|s| = (-0.8638   0.4839   0.1402),

while the angle is the arcsin of half of |s| (see lecture 4), which is 0.6471.

Thus the VRML rotation is (a q) =

-0.8638   0.4839   0.1402   0.6471

Here is a view of the cube from that perspective.

Warning: Remember that the arcsin function of a positive argument has two valid angles in the range 0 to p. You cannot tell which is the right one knowing only the magnitude of s. Usually for viewpoint setting, the smaller one will be correct. However, if you follow this procedure but still dont see the object, replace the angle q by p - q.

Alternatively, (and more correctly), you can notice that from the formula for R:

R(a,q) = aaT (1 - cosq) + I cosq + (ax) sinq

That the trace of R (the sum of its leading diagonal elements) is:

Tr(R) = 2 cos q + 1

So the sine of q is |s|/2 while the cosine of q is (Tr(R) - 1)/2 and putting those together we find that

q = atan2( |s|, Tr(R) - 1 )

Which gives us an angle with no ambiguity.

Scene graphs and object hierarchies

In most modeling tasks, its natural to build a model as a hierarchy of components. By a hierarchy, we mean a tree structure where the internal nodes of the tree are Group nodes. The group nodes can tie together objects into more and more complicated shapes.

An example of a two-level hierarchy is given here. The VRML constructs DEF and USE allow subparts to be used many times.

Note: DEF and USE do not make copies of objects, and changes made to one object affect all the others.

Transform nodes provide a second way to group shape nodes together, since they allow multiple children. A transform node in a tree represents a transformation that is applied to all the children of the node.

Hierarchies are a natural way to represent articulated (jointed) models, objects resting on each other, or complex objects composed of many subparts (like an automobile model). The adjustable transform at a joint can be easily represented using a transform node.

For example, we can create a stack of blocks by nesting transforms like this. The outer transform acts on all the blocks, the middle transform on the top two blocks etc.