Lab 5

Tue Oct 22 and Thu Oct 24
Due: Mon Oct 28 before 11:59PM


The purpose of this lab is to implement a group of related classes that represent geometric transformations of shapes. All of the transformations extend a common base class.

Question: Implement classes that extend an abstract base class

A two-dimensional geometric transformation transforms a 2D point to a 2D point. For example, translation moves a 2D point in a straight line to a new 2D point. There are many other types of transformations, so it is convenient to create an abstract base class Transformation that defines all of the fields and methods common to transformations.

A shear transformation transforms a rectangle into a parallelogram. The amount of shear is controlled by a scalar parameter, h, called the shear factor. An example of a shear is shown in the figure below:

A rotation transformation moves a point along a circular arc. The amount of rotation is controlled by a scalar parameter called the rotation angle in radians (or degrees). An example of a rotation is shown in the figure below:

A scale transformation enlarges or shrinks an object in both the horizontal and vertical directions independently. The amount of scale is controlled by two scalar parameters called the scale factors. An example of a scale transformation that shrinks horizontally and enlarges vertically is shown in the figure below:

Implement the parent class Transformation and the child classes Rotation, Scale, and Shear, so that they provide the following API:

You will need to refer to the Point2D API (the mutable form of IPoint2D):

Some code to start your solution can be found here:

You can see what the testers should do by running the following programs in the CSE Prism lab:

java -jar /eecs/dept/www/www.eecs.yorku.ca/course_archive/2013-14/F/classpath/1030/TestRotation.jar
java -jar /eecs/dept/www/www.eecs.yorku.ca/course_archive/2013-14/F/classpath/1030/TestScale.jar
java -jar /eecs/dept/www/www.eecs.yorku.ca/course_archive/2013-14/F/classpath/1030/TestShear.jar

Submit your solution:

submit 1030 L5 Rotation.java Scale.java Shear.java Transformation.java

Written Questions

The following are some written questions about inheritance based on the lab; you do not need to submit answers to these questions.

  1. Do both appply and transform need to be abstract in Transformation? Explain your answer.
  2. All of the transformations discussed in this lab including translation can be represented using a real 3x3 matrix. The matrix representation is convenient because a series of transformations applied one after another can be computed using matrix multiplication. Suppose that you wanted to add a field to represent the matrix for a transformation; in which class should the field be defined?
  3. Should the method getMatrix be declared abstract in Transformation?
  4. The transformations that can be represented using a 3x3 matrix (where the third row of the matrix is 0 0 1) are called affine transformations. There are many other transformations that are not affine transformations, but still support the API provided by Transformation. Suppose that you want to design an inheritance hierarchy that represents affine transformations and all other transformations that support the Transformation API. Draw the UML diagram showing your inheritance hierarchy.