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
Version:
2.4.0
`AffineTransform`

 Constructor Summary `private ` `TransformFactory()`           Private constructor to prevent instantiation.

 Method Summary `static AffineTransform` ```centeredTransform(double x, double y, AffineTransform t)```           Returns the affine transform centered at the given point (x, y) constructed by translating the given transform. `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` ```glide(double degrees, double distance)```           Returns the transform to glide (translate) along the line at the given angle in degrees and the given glide distance. `static AffineTransform` ```glidereflect(double x, double y, double degrees, double distance)```           Returns the transform to glide and 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` ```reflectAtOrigin(double dx, double dy)```           Returns a reflection through the line joining the origin and the point dx,dy. `static AffineTransform` ```reflectThroughLine(double x1, double y1, double x2, double y2)```           Returns a reflection through the line joining x1,y1 to x2,y2. `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` ```rotateAtOrigin(double dx, double dy)```           Returns a rotation with center at the origin and angle of rotation equal to the angle from the origin to dx,dy. `static AffineTransform` ```rotateAtOrigin(double x1, double y1, double x2, double y2)```           Returns a rotation with center at the origin and angle of rotation equal to the angle from x1,y1 to x2,y2. `static AffineTransform` ```rotateAtX1Y1(double x1, double y1, double x2, double y2)```           Returns a rotation with center at x1,y1 and angle of rotation equal to the angle from x1,y1 to x2,y2. `static AffineTransform` ```rotateAtX2Y2(double x1, double y1, double x2, double y2)```           Returns a rotation with center at x2,y2 and angle of rotation equal to the angle from x1,y1 to x2,y2. `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`

 Constructor Detail

TransformFactory

`private TransformFactory()`
Private constructor to prevent instantiation.

 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

glide

```public static AffineTransform glide(double degrees,
double distance)```

Returns the transform to glide (translate) along the line at the given angle in degrees and the given glide distance.

Equivalent to specifing a translation via polar coordinates with the angle in degrees specified first and the distance specified second.

Parameters:
`degrees` - the angle in degrees of the line of glide
`distance` - the translation distance along the line of glide
Returns:
the transform to glide along a line at the given angle in degrees and the given glide distance

glidereflect

```public static AffineTransform glidereflect(double x,
double y,
double degrees,
double distance)```
Returns the transform to glide and 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,
AffineTransform t)```

Returns the affine transform centered at the given point (x, y) constructed by translating the given transform.

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

• translate(+x, +y)
• the-given-transform
• translate(-x, -y)
.

If the given transform is `null`, returns the identity transform.

Parameters:
`x` - the x-coordinate of the center
`y` - the y-coordinate of the center
`t` - the given affine transform
Returns:
the centered affine transform

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:

• translate(+x, +y)
• transform(m00, m10, m01, m11, m02, m12)
• translate(-x, -y)
.

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

rotateAtOrigin

```public static AffineTransform rotateAtOrigin(double dx,
double dy)```

Returns a rotation with center at the origin and angle of rotation equal to the angle from the origin to dx,dy.

This rotation is computed directly from the coordinates without the use of trigonometric functions.

Returns the identity transform if dx,dy equals 0,0.

Parameters:
`dx` - x-coordinate of a point
`dy` - y-coordinate of a point

rotateAtOrigin

```public static AffineTransform rotateAtOrigin(double x1,
double y1,
double x2,
double y2)```

Returns a rotation with center at the origin and angle of rotation equal to the angle from x1,y1 to x2,y2.

This rotation is computed directly from the coordinates without the use of trigonometric functions.

Returns the identity transform if x1,y1 equals x2,y2.

Parameters:
`x1` - x-coordinate of point 1
`y1` - y-coordinate of point 1
`x2` - x-coordinate of point 2
`y2` - y-coordinate of point 2

rotateAtX1Y1

```public static AffineTransform rotateAtX1Y1(double x1,
double y1,
double x2,
double y2)```

Returns a rotation with center at x1,y1 and angle of rotation equal to the angle from x1,y1 to x2,y2.

This rotation is computed directly from the coordinates without the use of trigonometric functions.

Returns the identity transform if x1,y1 equals x2,y2.

Parameters:
`x1` - x-coordinate of point 1
`y1` - y-coordinate of point 1
`x2` - x-coordinate of point 2
`y2` - y-coordinate of point 2

rotateAtX2Y2

```public static AffineTransform rotateAtX2Y2(double x1,
double y1,
double x2,
double y2)```

Returns a rotation with center at x2,y2 and angle of rotation equal to the angle from x1,y1 to x2,y2.

This rotation is computed directly from the coordinates without the use of trigonometric functions.

Returns the identity transform if x1,y1 equals x2,y2.

Parameters:
`x1` - x-coordinate of point 1
`y1` - y-coordinate of point 1
`x2` - x-coordinate of point 2
`y2` - y-coordinate of point 2

reflectAtOrigin

```public static AffineTransform reflectAtOrigin(double dx,
double dy)```

Returns a reflection through the line joining the origin and the point dx,dy.

This reflection is computed directly from the coordinates without the use of trigonometric functions.

Returns the reflection through the x-axis if dx,dy equals 0,0.

Parameters:
`dx` - x-coordinate of a point
`dy` - y-coordinate of a point

reflectThroughLine

```public static AffineTransform reflectThroughLine(double x1,
double y1,
double x2,
double y2)```

Returns a reflection through the line joining x1,y1 to x2,y2.

This reflection is computed directly from the coordinates without the use of trigonometric functions.

Returns the horizontal reflection through the common point if x1,y1, equals x2, y2.

Parameters:
`x1` - x-coordinate of point 1
`y1` - y-coordinate of point 1
`x2` - x-coordinate of point 2
`y2` - y-coordinate of point 2

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)
`(double, double, double, double, double, double, double, double)`