Allison Barlow and David German - Engineering 26 Portfolio

Lab 4: 2D Transformations

In this lab exercise, we further extended the graphics environment developed in Labs 2 and 3. We added a C library that describes a Matrix structure, defines matrix arithmetic operations, and generates two-dimensional transform matrices. A programmer can distort and transform polygons in a virtual world by applying the appropriate transforms. We used these capabilities to generate animation and implement a rudimentary viewing pipeline.

Procedure

Our graphics environment continues to follow Prof. Maxwell's Graphics Environment Specification.

A point is a vector (x, y, z, h), where x, y, and z are the Cartesian dimensions and h is the homogeneous coordinate. Linear transformations of a point can be represented as 4x4 matrices; multiplying a point by a transformation matrix yields the transformed point. A series of transformation matrices can be multiplied together into a single matrix. In a single multiplication with this matrix, a point is transformed by all the constituent matrices in the right-to-left order in which they were concatenated. Any linear transformation expressed in this form can be applied to an object defined by points, such as a line, polyline, or polygon, by transforming each point.

We implemented routines for four two-dimensional transformations: translation, scaling, shear, and rotation about the z-axis. Page 10 of the specification gives the general form of each transformation matrix. Note that the scale and shear transformations assume the object to be transformed has been translated to the origin. Similarly, to rotate objects in place, the center of rotation must be translated to the origin.

Results

Group Images

The following image was generated by Prof. Maxwell's test code. It demonstrates that our translation and rotation operations work as expected.

Maxwell's TNG Enterprise, firing phasers
Image 1. The USS Enterprise, firing her phasers.

We developed a simpler model of the Enterprise by applying transformations to just two polygon objects, the unit square and the unit circle.

Our TNG Enterprise
Image 2. The USS Enterprise, as drawn by us.

We then wrote code to translate each piece of the Enterprise model to an arbitrary model origin. We incorporated it into a program that generates a series of images of the Enterprise translating on a circular orbit around a planet. We compiled these images into the following animation.

The Enterprise in orbital motion
Image 3. Scanning for lifesigns.

Finally, we implemented a simple viewing pipeline. Modifying the previous program, we defined a view transformation matrix, or VTM. It translates an arbitrary region of the virtual world to the origin and scales it to the size of the output image. The program's view window is always the size of the screen, but it initializes with the planet's center in the lower left corner. The window moves gradually to the left and down, yielding the following animation.

Pan across the orbiting enterprise
Image 4. A dramatic pan.

Allison's Portfolio Images

solar system
Image 1. Here comes the sun.

supernova?
Image 2. The ice is slowly meltin'.

David's Portfolio Images

This image demonstrates the shear transformation.

a pinwheel
Image 1. Round and round it goes...

Conclusions and Future Work

Our library routines for matrix arithmetic and polygon transformations work, as the results demonstrate.

Our programs do not have a well-engineered mechanism for handling global transformation matrices. We transformed each piece of our simple figures into place individually. This is tedious and inefficient. Structurally sound ship that she is, the Enterprise could have been encapsulated as a model: the components do not transform relative to each other, so we ought position her by applying a pre-assembled global transformation matrix to each. We did apply view transformation in this fashion, which made arbitrary modification of the view straightforward. We will develop more disciplined GTM management as part of a hierarchical modeling system in Lab 5.

Appendices

Our code is available with AES256 encryption. The passphrase is only available to Dr. Maxwell.

Allison developed the basic model of the Enterprise while David hunted some bugs in the matrix library. Otherwise, the project was pair-programmed. David wrote this writeup.