Module org.dyn4j

## Class Transform

• All Implemented Interfaces:
`Copyable<Transform>`, `Rotatable`, `Transformable`, `Translatable`

```public class Transform
extends Object
implements Transformable, Copyable<Transform>```
Represents a transformation matrix.

Supported operations are rotation and translation.

Since:
1.0.0
Version:
4.1.0
Author:
William Bittle
• ### Field Summary

Fields
Modifier and Type Field Description
`protected double` `cost`
the cosine of the rotation angle
`protected double` `sint`
the sine of the rotation angle
`protected double` `x`
The x translation
`protected double` `y`
The y translation
• ### Constructor Summary

Constructors
Constructor Description
`Transform()`
Default public constructor
`Transform​(Transform transform)`
Public copy constructor constructor
• ### Method Summary

All Methods
Modifier and Type Method Description
`Transform` `copy()`
Returns a deep copy of this object.
`double` `getCost()`
Returns the cosine of the angle of rotation of this transform.
`Vector2` `getInverseTransformed​(Vector2 vector)`
Inverse transforms the given `Vector2` and returns a new `Vector2` containing the result.
`void` ```getInverseTransformed​(Vector2 vector, Vector2 destination)```
Inverse transforms the given `Vector2` and returns the result in the destination `Vector2`.
`Vector2` `getInverseTransformedR​(Vector2 vector)`
Inverse transforms the given `Vector2` only by the rotation and returns a new `Vector2` containing the result.
`void` ```getInverseTransformedR​(Vector2 vector, Vector2 destination)```
Transforms the given `Vector2` only by the rotation and returns the result in the destination `Vector2`.
`Rotation` `getRotation()`
`double` `getRotationAngle()`
Returns the rotation.
`Transform` `getRotationTransform()`
Returns a new `Transform` including only the rotation of this `Transform`.
`double` `getSint()`
Returns the sine of the angle of rotation of this transform.
`Vector2` `getTransformed​(Vector2 vector)`
Transforms the given `Vector2` and returns a new `Vector2` containing the result.
`void` ```getTransformed​(Vector2 vector, Vector2 destination)```
Transforms the given `Vector2` and returns the result in dest.
`Vector2` `getTransformedR​(Vector2 vector)`
Transforms the given `Vector2` only by the rotation and returns a new `Vector2` containing the result.
`void` ```getTransformedR​(Vector2 vector, Vector2 destination)```
Transforms the given `Vector2` only by the rotation and returns the result in the destination `Vector2`.
`double` `getTransformedX​(Vector2 vector)`
Transforms only the x coordinate of the given `Vector2` and returns the result.
`double` `getTransformedY​(Vector2 vector)`
Transforms only the y coordinate of the given `Vector2` and returns the result.
`Vector2` `getTranslation()`
Returns the translation `Vector2`.
`Transform` `getTranslationTransform()`
Returns a new `Transform` including only the translation of this `Transform`.
`double` `getTranslationX()`
Returns the x translation.
`double` `getTranslationY()`
Returns the x translation.
`double[]` `getValues()`
Returns the values stored in this transform.
`void` `identity()`
Sets this `Transform` to the identity.
`void` `inverseTransform​(Vector2 vector)`
Inverse transforms the given `Vector2` and places the result in the given `Vector2`.
`void` `inverseTransformR​(Vector2 vector)`
Transforms the given `Vector2` only by the rotation and returns the result in the given `Vector2`.
`boolean` `isIdentity()`
Returns true if this `Transform` is an identity transform.
`void` ```lerp​(Transform end, double alpha)```
Interpolates this transform linearly by alpha towards the given end transform.
`void` ```lerp​(Transform end, double alpha, Transform result)```
Interpolates linearly by alpha towards the given end transform placing the result in the given transform.
`void` ```lerp​(Vector2 dp, double da, double alpha)```
Interpolates this transform linearly, by alpha, given the change in position (Δp) and the change in angle (Δa).
`void` ```lerp​(Vector2 dp, double da, double alpha, Transform result)```
Interpolates this transform linearly, by alpha, given the change in position (Δp) and the change in angle (Δa) and places it into result.
`Transform` ```lerped​(Transform end, double alpha)```
Interpolates linearly by alpha towards the given end transform returning a new transform containing the result.
`Transform` ```lerped​(Vector2 dp, double da, double alpha)```
Interpolates this transform linearly, by alpha, given the change in position (Δp) and the change in angle (Δa) and returns the result.
`void` `rotate​(double theta)`
Rotates the object about the origin.
`void` ```rotate​(double theta, double x, double y)```
Rotates the object about the given coordinates.
`void` ```rotate​(double theta, Vector2 point)```
Rotates the object about the given point.
`void` `rotate​(Rotation rotation)`
Rotates the object about the origin.
`void` ```rotate​(Rotation rotation, double x, double y)```
Rotates the object about the given point.
`void` ```rotate​(Rotation rotation, Vector2 point)```
Rotates the object about the given point.
`void` `set​(Transform transform)`
Sets this transform to the given transform.
`double` `setRotation​(double theta)`
Sets the rotation and returns the previous rotation.
`Rotation` `setRotation​(Rotation rotation)`
Sets the rotation and returns the previous rotation.
`void` ```setTranslation​(double x, double y)```
Sets the translation.
`void` `setTranslation​(Vector2 translation)`
Sets the translation.
`void` `setTranslationX​(double x)`
Sets the translation along the x axis.
`void` `setTranslationY​(double y)`
Sets the translation along the y axis.
`String` `toString()`
`void` `transform​(Vector2 vector)`
Transforms the given `Vector2` and places the result in the given `Vector2`.
`void` `transformR​(Vector2 vector)`
Transforms the given `Vector2` only by the rotation and returns the result in the given `Vector2`.
`void` `transformX​(Vector2 vector)`
Transforms only the x coordinate of the given `Vector2` and places the result in the x field of the given `Vector2`.
`void` `transformY​(Vector2 vector)`
Transforms only the y coordinate of the given `Vector2` and places the result in the y field of the given `Vector2`.
`void` ```translate​(double x, double y)```
Translates the object the given amounts in the respective directions.
`void` `translate​(Vector2 vector)`
Translates the object along the given vector.
• ### Methods inherited from class Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`
• ### Field Detail

• #### cost

`protected double cost`
the cosine of the rotation angle
• #### sint

`protected double sint`
the sine of the rotation angle
• #### x

`protected double x`
The x translation
• #### y

`protected double y`
The y translation
• ### Constructor Detail

• #### Transform

`public Transform()`
Default public constructor
• #### Transform

`public Transform​(Transform transform)`
Public copy constructor constructor
Parameters:
`transform` - the transform to copy
Since:
3.4.0
• ### Method Detail

• #### toString

`public String toString()`
Overrides:
`toString` in class `Object`
• #### rotate

`public void rotate​(double theta)`
Description copied from interface: `Rotatable`
Rotates the object about the origin.
Specified by:
`rotate` in interface `Rotatable`
Parameters:
`theta` - the angle of rotation in radians
• #### rotate

`public void rotate​(Rotation rotation)`
Description copied from interface: `Rotatable`
Rotates the object about the origin.
Specified by:
`rotate` in interface `Rotatable`
Parameters:
`rotation` - the `Rotation` representing the rotation amount
• #### rotate

```public void rotate​(double theta,
double x,
double y)```
Description copied from interface: `Rotatable`
Rotates the object about the given coordinates.
Specified by:
`rotate` in interface `Rotatable`
Parameters:
`theta` - the angle of rotation in radians
`x` - the x coordinate to rotate about
`y` - the y coordinate to rotate about
• #### rotate

```public void rotate​(Rotation rotation,
double x,
double y)```
Description copied from interface: `Rotatable`
Rotates the object about the given point.
Specified by:
`rotate` in interface `Rotatable`
Parameters:
`rotation` - the `Rotation` representing the rotation amount
`x` - the x coordinate to rotate about
`y` - the y coordinate to rotate about
• #### rotate

```public void rotate​(double theta,
Vector2 point)```
Description copied from interface: `Rotatable`
Rotates the object about the given point.
Specified by:
`rotate` in interface `Rotatable`
Parameters:
`theta` - the angle of rotation in radians
`point` - the point to rotate about
• #### rotate

```public void rotate​(Rotation rotation,
Vector2 point)```
Description copied from interface: `Rotatable`
Rotates the object about the given point.
Specified by:
`rotate` in interface `Rotatable`
Parameters:
`rotation` - the `Rotation` representing the rotation amount
`point` - the point to rotate about
• #### translate

```public void translate​(double x,
double y)```
Description copied from interface: `Translatable`
Translates the object the given amounts in the respective directions.
Specified by:
`translate` in interface `Translatable`
Parameters:
`x` - the translation in the x direction
`y` - the translation in the y direction
• #### translate

`public void translate​(Vector2 vector)`
Description copied from interface: `Translatable`
Translates the object along the given vector.
Specified by:
`translate` in interface `Translatable`
Parameters:
`vector` - the translation along a vector
• #### copy

`public Transform copy()`
Description copied from interface: `Copyable`
Returns a deep copy of this object.
Specified by:
`copy` in interface `Copyable<Transform>`
Returns:
T
• #### set

`public void set​(Transform transform)`
Sets this transform to the given transform.
Parameters:
`transform` - the transform to copy
Since:
1.1.0
• #### identity

`public void identity()`
Sets this `Transform` to the identity.
• #### isIdentity

`public boolean isIdentity()`
Returns true if this `Transform` is an identity transform.
Returns:
boolean
Since:
4.0.0
• #### getTransformedX

`public double getTransformedX​(Vector2 vector)`
Transforms only the x coordinate of the given `Vector2` and returns the result.
Parameters:
`vector` - the `Vector2` to transform
Returns:
the transformed x coordinate
Since:
3.4.0
• #### getTransformedY

`public double getTransformedY​(Vector2 vector)`
Transforms only the y coordinate of the given `Vector2` and returns the result.
Parameters:
`vector` - the `Vector2` to transform
Returns:
the transformed y coordinate
Since:
3.4.0
• #### transformX

`public void transformX​(Vector2 vector)`
Transforms only the x coordinate of the given `Vector2` and places the result in the x field of the given `Vector2`.
Parameters:
`vector` - the `Vector2` to transform
Since:
3.4.0
• #### transformY

`public void transformY​(Vector2 vector)`
Transforms only the y coordinate of the given `Vector2` and places the result in the y field of the given `Vector2`.
Parameters:
`vector` - the `Vector2` to transform
Since:
3.4.0
• #### getTransformed

```public void getTransformed​(Vector2 vector,
Vector2 destination)```
Transforms the given `Vector2` and returns the result in dest.
Parameters:
`vector` - the `Vector2` to transform
`destination` - the `Vector2` containing the result
• #### getTransformedR

```public void getTransformedR​(Vector2 vector,
Vector2 destination)```
Transforms the given `Vector2` only by the rotation and returns the result in the destination `Vector2`.
Parameters:
`vector` - the `Vector2` to transform
`destination` - the `Vector2` containing the result
Since:
3.1.5
• #### getInverseTransformedR

```public void getInverseTransformedR​(Vector2 vector,
Vector2 destination)```
Transforms the given `Vector2` only by the rotation and returns the result in the destination `Vector2`.
Parameters:
`vector` - the `Vector2` to transform
`destination` - the `Vector2` containing the result
Since:
3.1.5
• #### getTranslationX

`public double getTranslationX()`
Returns the x translation.
Returns:
double
• #### setTranslationX

`public void setTranslationX​(double x)`
Sets the translation along the x axis.
Parameters:
`x` - the translation along the x axis
Since:
1.2.0
• #### getTranslationY

`public double getTranslationY()`
Returns the x translation.
Returns:
double
• #### setTranslationY

`public void setTranslationY​(double y)`
Sets the translation along the y axis.
Parameters:
`y` - the translation along the y axis
Since:
1.2.0
• #### setTranslation

```public void setTranslation​(double x,
double y)```
Sets the translation.
Parameters:
`x` - the translation along the x axis
`y` - the translation along the y axis
Since:
1.2.0
• #### setTranslation

`public void setTranslation​(Vector2 translation)`
Sets the translation.
Parameters:
`translation` - the translation along both axes
Since:
1.2.0
• #### getCost

`public double getCost()`
Returns the cosine of the angle of rotation of this transform.
Returns:
double
Since:
4.1.0
• #### getSint

`public double getSint()`
Returns the sine of the angle of rotation of this transform.
Returns:
double
Since:
4.1.0
• #### getRotationAngle

`public double getRotationAngle()`
Returns the rotation.
Returns:
double angle in the range [-π, π]
• #### setRotation

`public double setRotation​(double theta)`
Sets the rotation and returns the previous rotation.
Parameters:
`theta` - the angle in radians
Returns:
double the old rotation in radians in the range [-π, π]
Since:
3.1.0
• #### setRotation

`public Rotation setRotation​(Rotation rotation)`
Sets the rotation and returns the previous rotation.
Parameters:
`rotation` - the `Rotation`
Returns:
A new `Rotation` object representing the old rotation of this `Transform`
Since:
3.4.0
• #### getValues

`public double[] getValues()`
Returns the values stored in this transform.

The values are in the order of 00, 01, x, 10, 11, y.

Returns:
double[]
Since:
3.0.1
• #### lerp

```public void lerp​(Transform end,
double alpha)```
Interpolates this transform linearly by alpha towards the given end transform.

Interpolating from one angle to another can have two results depending on the direction of the rotation. If a rotation was from 30 to 200 the rotation could be 170 or -190. This interpolation method will always choose the smallest rotation (regardless of sign) as the rotation direction.

Parameters:
`end` - the end transform
`alpha` - the amount to interpolate
Since:
1.2.0
• #### lerp

```public void lerp​(Transform end,
double alpha,
Transform result)```
Interpolates linearly by alpha towards the given end transform placing the result in the given transform.

Interpolating from one angle to another can have two results depending on the direction of the rotation. If a rotation was from 30 to 200 the rotation could be 170 or -190. This interpolation method will always choose the smallest rotation (regardless of sign) as the rotation direction.

Parameters:
`end` - the end transform
`alpha` - the amount to interpolate
`result` - the transform to place the result
Since:
1.2.0
• #### lerp

```public void lerp​(Vector2 dp,
double da,
double alpha,
Transform result)```
Interpolates this transform linearly, by alpha, given the change in position (Δp) and the change in angle (Δa) and places it into result.
Parameters:
`dp` - the change in position
`da` - the change in angle
`alpha` - the amount to interpolate
`result` - the transform to place the result
Since:
3.1.5
• #### lerp

```public void lerp​(Vector2 dp,
double da,
double alpha)```
Interpolates this transform linearly, by alpha, given the change in position (Δp) and the change in angle (Δa).
Parameters:
`dp` - the change in position
`da` - the change in angle
`alpha` - the amount to interpolate
Since:
3.1.5
• #### lerped

```public Transform lerped​(Vector2 dp,
double da,
double alpha)```
Interpolates this transform linearly, by alpha, given the change in position (Δp) and the change in angle (Δa) and returns the result.
Parameters:
`dp` - the change in position
`da` - the change in angle
`alpha` - the amount to interpolate
Returns:
`Transform`
Since:
3.1.5
• #### lerped

```public Transform lerped​(Transform end,
double alpha)```
Interpolates linearly by alpha towards the given end transform returning a new transform containing the result.

Interpolating from one angle to another can have two results depending on the direction of the rotation. If a rotation was from 30 to 200 the rotation could be 170 or -190. This interpolation method will always choose the smallest rotation (regardless of sign) as the rotation direction.

Parameters:
`end` - the end transform
`alpha` - the amount to interpolate
Returns:
`Transform` the resulting transform
Since:
1.2.0