package cse1030.drawing;
/**
* A horizontal shear transformation. A shear transformation transforms
* a rectangle into a parallelogram. The amount of shear is controlled
* by a scalar parameter called the shear factor.
*
* @author CSE1030Z
*
*/
public class Shear extends Transformation {
private double h;
/**
* Create a shear transformation given a name and the shear factor
* h
.
*
* @param name the name of the transformation
* @param h the shear factor
*/
public Shear(String name, double h) {
super(name);
this.h = h;
}
/**
* Transform a point changing its coordinates. For a shear of
* of factor h
the x
and y
* coordinates of the point are transformed as follows:
*
*
* x = x + h * y
* y = y
(i.e., the y coordinate is unchanged)
*
* @see cse1030.drawing.Transformation#transform(cse1030.drawing.Point2D)
*
* @param p the point to transform
*/
@Override
public void transform(Point2D p) {
p.setX(p.getX() + this.h * p.getY());
}
/**
* Apply the shear to a point to produce a new point leaving the
* original point unchanged.
*
* @see cse1030.drawing.Shear#transform(cse1030.drawing.Point2D)
*
* @see cse1030.drawing.Transformation#apply(cse1030.drawing.Point2D)
*
* @param p the point to apply the transformation to
* @return a new point equal to shearing the input point p
*/
@Override
public Point2D apply(Point2D p) {
Point2D q = new Point2D(p);
this.transform(q);
return q;
}
/**
* Get a string representation of the shear. The returned string is the
* name of the shear followed by the string " : shear of factor "
* followed by the shear factor. For example, a shear of factor 1.876435632
named
* T1
has the following string representation:
*
*
* "T1 : shear of factor 1.876435632"
*
* @see cse1030.drawing.Transformation#toString()
*
* @return the string representation of the shear
*/
@Override
public String toString() {
return super.toString() + " : shear of factor " + this.h;
}
}