public class Scale extends Transformation
sx
: the scale factor in the horizontal directionsy
: the scale factor in the vertical direction
A positive value of sx
greater than 1
causes the object
to stretch in the horizontal direction.
A positive value of sx
less than 1
causes the object
to shrink in the horizontal direction.
A positive value of sy
greater than 1
causes the object
to stretch in the vertical direction.
A positive value of sy
less than 1
causes the object
to shrink in the vertical direction.
Constructor and Description |
---|
Scale(String name,
double sx,
double sy)
Create a scale transformation that scales in the horizontal
and vertical directions.
|
Modifier and Type | Method and Description |
---|---|
Point2D |
apply(Point2D p)
Apply the scale to a point to produce a new point leaving the
original point unchanged.
|
String |
toString()
Get a string representation of the scale.
|
void |
transform(Point2D p)
Transform a point changing its coordinates.
|
getName
public Scale(String name, double sx, double sy)
name
- the name of the transformationsx
- the scale factor in the horizontal directionsy
- the scale factor in the vertical directionpublic void transform(Point2D p)
sx
and sy
the
coordinates of the point are transformed as follows:
newx = sx * x
newy = sy * y
transform
in class Transformation
Transformation.transform(cse1030.drawing.Point2D)
p
- the point to transformpublic Point2D apply(Point2D p)
apply
in class Transformation
transform(cse1030.drawing.Point2D)
,
Transformation.apply(cse1030.drawing.Point2D)
p
- the point to apply the transformation top
public String toString()
" : scale of factors "
followed by sx
followed by " and " followed by
sy
. For example, a scale of factors sx = 1.55
and sy = 3.008
named
T1
has the following string representation:
"T1 : scale of factors 1.55 and 3.008"
toString
in class Transformation
Transformation.toString()