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.
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:
Point2D
implementationTestRotation
tester code (not a JUnit tester)TestScale
tester code (not a JUnit tester)TestShear
tester code (not a JUnit tester)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
The following are some written questions about inheritance based on the lab; you do not need to submit answers to these questions.
appply
and transform
need to be abstract
in
Transformation
? Explain your answer.
getMatrix
be declared abstract
in
Transformation
?
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.