AffineTransform


public abstract class AffineTransform

Known direct subclasses
ImmutableAffineTransform

An affine transformation in the plane.

MutableAffineTransform

An affine transformation in the plane.


An affine transformation in the plane. The transformation can be thought of as a 3x3 matrix:

⎡m00  m10  m20⎤
⎢m01 m11 m21⎥
⎣ 0 0 1 ⎦

Applying the transformation can be thought of as a matrix multiplication, with the to-be-transformed point represented as a column vector with an extra 1:

⎡m00  m10  m20⎤   ⎡x⎤   ⎡m00*x + m10*y + m20⎤
⎢m01 m11 m21⎥ * ⎢y⎥ = ⎢m01*x + m11*y + m21⎥
⎣ 0 0 1 ⎦ ⎣1⎦ ⎣ 1 ⎦

Transformations are composed via multiplication. Multiplication is not commutative (i.e. AB != BA), and the left-hand transformation is composed "after" the right hand transformation. E.g., if you have:

val rotate = ImmutableAffineTransform.rotate(Angle.degreesToRadians(45))
val translate = ImmutableAffineTransform.translate(Vec(10, 0))

then rotate * translate first translates 10 units in the positive x-direction, then rotates 45° about the origin.

ImmutableAffineTransform and MutableAffineTransform are the two concrete implementations of this.

Summary

Public fields

static final @NonNull ImmutableAffineTransform

Constant representing an identity transformation, which maps a point to itself, i.e. it leaves it unchanged.

Public methods

final @NonNull MutableParallelogram
applyTransform(
    @NonNull Box box,
    @NonNull MutableParallelogram outParallelogram
)

Apply the AffineTransform to the Box and store the result in the MutableParallelogram.

final @NonNull MutableParallelogram
applyTransform(
    @NonNull Parallelogram parallelogram,
    @NonNull MutableParallelogram outParallelogram
)

Apply the AffineTransform to the Parallelogram and store the result in the MutableParallelogram.

final @NonNull MutableSegment
applyTransform(
    @NonNull Segment segment,
    @NonNull MutableSegment outSegment
)

Apply the AffineTransform to the Segment and store the result in the MutableSegment.

final @NonNull MutableTriangle
applyTransform(
    @NonNull Triangle triangle,
    @NonNull MutableTriangle outTriangle
)

Apply the AffineTransform to the Triangle and store the result in the MutableTriangle.

final @NonNull MutableVec

Apply the AffineTransform to the Vec and store the result in the MutableVec.

final @NonNull MutableAffineTransform

Populates outAffineTransform with the inverse of this AffineTransform.

final @Size(min = 6) @NonNull float[]
getValues(@Size(min = 6) @NonNull float[] outArray)

Populates the first 6 elements of outArray with the values of this transform, starting with the top left corner of the matrix and proceeding in row-major order.

Public fields

IDENTITY

public static final @NonNull ImmutableAffineTransform IDENTITY

Constant representing an identity transformation, which maps a point to itself, i.e. it leaves it unchanged.

Public methods

applyTransform

Added in 1.0.0-alpha01
public final @NonNull MutableParallelogram applyTransform(
    @NonNull Box box,
    @NonNull MutableParallelogram outParallelogram
)

Apply the AffineTransform to the Box and store the result in the MutableParallelogram. This is the only Apply function where the input cannot also be the output, as applying an Affine Transform to a Box makes a Parallelogram.

applyTransform

Added in 1.0.0-alpha01
public final @NonNull MutableParallelogram applyTransform(
    @NonNull Parallelogram parallelogram,
    @NonNull MutableParallelogram outParallelogram
)

Apply the AffineTransform to the Parallelogram and store the result in the MutableParallelogram. The same MutableParallelogram can be used as both the input and output to avoid additional allocations.

applyTransform

Added in 1.0.0-alpha01
public final @NonNull MutableSegment applyTransform(
    @NonNull Segment segment,
    @NonNull MutableSegment outSegment
)

Apply the AffineTransform to the Segment and store the result in the MutableSegment. The same MutableSegment can be used as both the input and output to avoid additional allocations. Returns outSegment.

applyTransform

Added in 1.0.0-alpha01
public final @NonNull MutableTriangle applyTransform(
    @NonNull Triangle triangle,
    @NonNull MutableTriangle outTriangle
)

Apply the AffineTransform to the Triangle and store the result in the MutableTriangle. The same MutableTriangle can be used as both the input and output to avoid additional allocations. Returns outTriangle.

applyTransform

Added in 1.0.0-alpha01
public final @NonNull MutableVec applyTransform(@NonNull Vec vec, @NonNull MutableVec outVec)

Apply the AffineTransform to the Vec and store the result in the MutableVec. The same MutableVec can be used as both the input and output to avoid additional allocations. Returns outVec.

computeInverse

Added in 1.0.0-alpha01
public final @NonNull MutableAffineTransform computeInverse(@NonNull MutableAffineTransform outAffineTransform)

Populates outAffineTransform with the inverse of this AffineTransform. The same MutableAffineTransform instance can be used as the output to avoid additional allocations. Returns outAffineTransform.

getValues

Added in 1.0.0-alpha01
public final @Size(min = 6) @NonNull float[] getValues(@Size(min = 6) @NonNull float[] outArray)

Populates the first 6 elements of outArray with the values of this transform, starting with the top left corner of the matrix and proceeding in row-major order.

In performance-sensitive code, prefer to pass in an array that has already been allocated and is being reused, rather than relying on the default behavior of allocating a new instance for each call.

Prefer to apply this transform to an object, such as with applyTransform, rather than accessing the actual numeric values of this transform. This function is useful for when the values are needed in bulk but not to apply a transform, for example for serialization.

To set these values on a transform in the same order that they are retrieved here, use the ImmutableAffineTransform constructor or use MutableAffineTransform.setValues.