edu.neu.ccs.gui
Class TransformFactory

java.lang.Object
  |
  +--edu.neu.ccs.gui.TransformFactory

public class TransformFactory
extends Object

TransformFactory provides a collection of static methods that construct AffineTransform objects for common 2-dimensional transforms.

Angle measurement is in degrees not radians.

A positive angle is in the direction from the positive x-axis towards the positive y-axis.

Class TransformFactory cannot be instantiated.

Since:
2.3
See Also:
AffineTransform

Method Summary
static AffineTransform centeredTransform(double x, double y, double m00, double m10, double m01, double m11, double m02, double m12)
          Returns the affine transform centered at the given point (x, y) whose corresponding 2-by-3 matrix at the origin is the given matrix.
static AffineTransform compose(AffineTransform[] transforms)
          Returns the transform produced by composition of the transforms in the given array of transforms.
static AffineTransform compose(AffineTransform M, AffineTransform N)
          Returns the transform produced by composition of the transforms M and N with M on the left and N on the right.
static AffineTransform glidereflect(double x, double y, double degrees, double distance)
          Returns the transform to glide reflect along the line through (x, y) at the given angle in degrees and the given glide distance.
static AffineTransform randomCenteredTransform(double x, double y, double maxshift)
          Returns a transform that is a perturbation of the identity transform with focus at the given center (x, y).
static AffineTransform randomRotate(double x, double y, double maxangle)
          Returns a random rotation transform about the given center (x, y) whose rotation angle is bounded by the given maxangle in degrees.
static AffineTransform randomScale(double x, double y, double degrees, double maxdelta)
          Returns a random scale with center at (x, y) along the line at the given angle in degrees and with scale factors within maxdelta of 1.
static AffineTransform randomTranslate(double maxshift)
          Returns a random translation transform whose shift in each direction is bounded in absolute value by the given value maxshift.
static AffineTransform randomTranslateRotate(double x, double y, double maxshift, double maxangle)
          Returns a composite transform that combines a random translation with a random rotation about the given center (x, y).
static AffineTransform reflect(double x, double y, double degrees)
          Returns the transform to reflect along the line through (x, y) at the given angle in degrees.
static AffineTransform rotate(double x, double y, double degrees)
          Returns the transform to rotate with center at (x, y) by the given angle in degrees.
static AffineTransform scale(double x, double y, double degrees, double s, double t)
          Returns the transform to scale with center at (x, y), with scale factor s along the line at the given angle in degrees, and with scale factor t along the perpendicular line.
static AffineTransform shear(double x, double y, double degrees, double s)
          Returns the transform to shear with center at (x, y) and with shear factor s along the line at the given angle in degrees.
static AffineTransform transform(double m00, double m10, double m01, double m11, double m02, double m12)
          Returns the affine transform with the given 2-by-3 matrix.
static AffineTransform translate(double tx, double ty)
          Returns the transform to translate by (tx, ty).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

translate

public static AffineTransform translate(double tx,
                                        double ty)
Returns the transform to translate by (tx, ty).

Parameters:
tx - the x-coordinate of the translate
ty - the y-coordinate of the translate
Returns:
the transform to translate by (tx, ty)

rotate

public static AffineTransform rotate(double x,
                                     double y,
                                     double degrees)
Returns the transform to rotate with center at (x, y) by the given angle in degrees.

Parameters:
x - the x-coordinate of the center
y - the y-coordinate of the center
degrees - the rotation angle in degrees
Returns:
the transform to rotate with center at (x, y) by the given angle in degrees

scale

public static AffineTransform scale(double x,
                                    double y,
                                    double degrees,
                                    double s,
                                    double t)
Returns the transform to scale with center at (x, y), with scale factor s along the line at the given angle in degrees, and with scale factor t along the perpendicular line.

Parameters:
x - the x-coordinate of the center
y - the y-coordinate of the center
degrees - the angle in degrees of the main scaling axis
s - the scale factor along the axis at angle degrees
t - the scale factor along the axis at angle degrees+90
Returns:
the transform to scale with center at (x, y), with scale factor s along the line at the given angle in degrees, and with scale factor t along the perpendicular line

shear

public static AffineTransform shear(double x,
                                    double y,
                                    double degrees,
                                    double s)

Returns the transform to shear with center at (x, y) and with shear factor s along the line at the given angle in degrees.

In the special case when x = 0, y = 0, degrees = 0, this mapping produces the transform: (u, v) maps to (u + s * v, v), which fixes the x-axis and shears parallel to that axis.

In the general case, the fixed axis for the shear is the line at the given angle degrees through the point (x, y).

Parameters:
x - the x-coordinate of the center
y - the y-coordinate of the center
degrees - the angle in degrees of the fixed axis for shear
s - determines the amount of shear along lines parallel to the fixed axis for shear
Returns:
the transform to shear with center at (x, y) and with shear factor s along the line at the given angle in degrees

reflect

public static AffineTransform reflect(double x,
                                      double y,
                                      double degrees)
Returns the transform to reflect along the line through (x, y) at the given angle in degrees.

Parameters:
x - the x-coordinate of the center
y - the y-coordinate of the center
degrees - the angle in degrees of the line of reflection
Returns:
the transform to reflect along the line through (x, y) at the given angle in degrees

glidereflect

public static AffineTransform glidereflect(double x,
                                           double y,
                                           double degrees,
                                           double distance)
Returns the transform to glide reflect along the line through (x, y) at the given angle in degrees and the given glide distance.

Parameters:
x - the x-coordinate of the center
y - the y-coordinate of the center
degrees - the angle in degrees of the line of glide reflection
distance - the translation distance along the line of glide reflection
Returns:
the transform to glide reflect along the line through (x, y) at the given angle in degrees and the given glide distance

transform

public static AffineTransform transform(double m00,
                                        double m10,
                                        double m01,
                                        double m11,
                                        double m02,
                                        double m12)

Returns the affine transform with the given 2-by-3 matrix.

The given 2-by-3 matrix has the form:

m00 m01 m02

m10 m11 m12

.

Parameters:
m00 - matrix coefficient for row 0 and column 0
m10 - matrix coefficient for row 1 and column 0
m01 - matrix coefficient for row 0 and column 1
m11 - matrix coefficient for row 1 and column 1
m02 - matrix coefficient for row 0 and column 2
m12 - matrix coefficient for row 1 and column 2
Returns:
the affine transform with the matrix: m00 m10 m01 m11 m02 m12

centeredTransform

public static AffineTransform centeredTransform(double x,
                                                double y,
                                                double m00,
                                                double m10,
                                                double m01,
                                                double m11,
                                                double m02,
                                                double m12)

Returns the affine transform centered at the given point (x, y) whose corresponding 2-by-3 matrix at the origin is the given matrix.

The given 2-by-3 matrix has the form:

m00 m01 m02

m10 m11 m12

.

The affine transform returned is the composite of the following three transforms from left to right:

.

Parameters:
x - the x-coordinate of the center
y - the y-coordinate of the center
m00 - matrix coefficient for row 0 and column 0
m10 - matrix coefficient for row 1 and column 0
m01 - matrix coefficient for row 0 and column 1
m11 - matrix coefficient for row 1 and column 1
m02 - matrix coefficient for row 0 and column 2
m12 - matrix coefficient for row 1 and column 2
Returns:
the centered affine transform

compose

public static AffineTransform compose(AffineTransform[] transforms)

Returns the transform produced by composition of the transforms in the given array of transforms.

The composition process takes place by repeated concatenation on the right of the i-th transform with the composite of the earlier transforms in the array.

If the array is null return the identity transform.

If an individual transform is null then ignore that particular transform in the composition process.

Parameters:
transforms - the array of transforms to compose
Returns:
the transform produced by composition of the transforms

compose

public static AffineTransform compose(AffineTransform M,
                                      AffineTransform N)

Returns the transform produced by composition of the transforms M and N with M on the left and N on the right.

This method is equivalent to:

return compose(new AffineTransform[] { M, N });

Parameters:
M - the transform on the left
N - the transform on the right
Returns:
the transform produced by composition of the transforms

randomTranslate

public static AffineTransform randomTranslate(double maxshift)
Returns a random translation transform whose shift in each direction is bounded in absolute value by the given value maxshift.

Parameters:
maxshift - the bound for the translation along each axis
Returns:
a random translation

randomRotate

public static AffineTransform randomRotate(double x,
                                           double y,
                                           double maxangle)
Returns a random rotation transform about the given center (x, y) whose rotation angle is bounded by the given maxangle in degrees.

Parameters:
x - the x-coordinate of the center
y - the y-coordinate of the center
maxangle - the bound for the rotation angle in degrees
Returns:
a random rotation

randomTranslateRotate

public static AffineTransform randomTranslateRotate(double x,
                                                    double y,
                                                    double maxshift,
                                                    double maxangle)
Returns a composite transform that combines a random translation with a random rotation about the given center (x, y).

Parameters:
x - the x-coordinate of the center
y - the y-coordinate of the center
maxshift - the bound for the translation along each axis
maxangle - the bound for the rotation angle in degrees
Returns:
the composite of a random translation and a random rotation

randomScale

public static AffineTransform randomScale(double x,
                                          double y,
                                          double degrees,
                                          double maxdelta)
Returns a random scale with center at (x, y) along the line at the given angle in degrees and with scale factors within maxdelta of 1.

Parameters:
x - the x-coordinate of the center
y - the y-coordinate of the center
degrees - the angle in degrees of the main scaling axis
maxdelta - the bound relative to 1 of the scale factors
Returns:
a random scale

randomCenteredTransform

public static AffineTransform randomCenteredTransform(double x,
                                                      double y,
                                                      double maxshift)

Returns a transform that is a perturbation of the identity transform with focus at the given center (x, y).

In the special case when x = 0 and y = 0, the transform returned has the form:

m00 m01 m02

m10 m11 m12

where the diagonal elements satisfy:

abs(mii - 1) <= abs(maxshift)

and the off-diagonal elements satisfy:

abs(mij) <= abs(maxshift)

In the general case, there is the same behavior but centered at (x, y).

Parameters:
x - the x-coordinate of the center
y - the y-coordinate of the center
maxshift - the bound on the perturbation coefficients
Returns:
a random transform centered at (x, y)
See Also:
(double, double, double, double, double, double, double, double)