COMP 310
Spring 2010

Lec07:  Composition-based Ballworld considerations and even more fun... 

Home  Info  Owlspace  Resources

HW02 will be turned in via Owlspace again.


Composition-based Ballworld considerations:



What happens to all the ABall subclasses?  What happens to ABall?

After all your changes, which do you think had more lines of code, the inheritance-based or composition-based systems?  Which had more capabilities?


More fun stuff:   Fishworld Demo


Affine Transforms

How does Fishworld create fish that are not only the correct size, but are always swimming forward?  

Remember that a fish (ball) knows where it is and which way it is going because it has a position and a velocity.   It has a radius too, so it knows its size as well.   Thus any given ball can take a common representation of an image, e.g. a fish, scale it as per its radius, rotate it as per its velocity and translate it as per its position and end up with an image that is always oriented correctly with respect to its movement.    The mathematical process of scaling, rotating and translating is called an "affine transform".

An affine transform is the mathematical process of scaling (making larger or smaller), rotating (pivoting around the origin) and translating (moving a specified distance and direction) of a point in space.   Remember that a point is really a vector from the origin, so a affine transformation technically transforms vectors, not points.

Affine transforms may seem mathematically daunting, but they are actually quite straightforward.   Plus, Java provides an AffineTransform class that encapsulates the mathematics and makes dealing with affine transformation very easy.

Example of the operations involved in a single Affine transformation, showing the individual steps of rotating, scaling and translating:

Original vector: then Rotated vector:

then Scaled vector and then Translated vector:


Note that the order of operation is important:

Original vector: then Rotated vector:  then Translated vector:

as compared to

Original vector:  then Translated vector:  then Rotated vector:



In fancy mathematical words, we same that rotation and translation are non-commutative.    A net Affine transformation is thus dependent on not only what operations (rotate, scale, translate) are defined, but also in what order those operations are defined.


© 2010 by Stephen Wong