eu.webtoolkit.jwt
Class WTransform

java.lang.Object
  extended by eu.webtoolkit.jwt.WTransform

public class WTransform
extends java.lang.Object

A value class that defines a 2D affine transformation matrix.

The matrix is encoded using 6 parameters:

 m11  m12   0
  m21  m22   0
  dx   dy    1
 
 

In this representation, getDx() (= getM31()) and getDy() (= getM32()) represent the translation components, and mxy represent a 2D matrix that contains the scale, rotation (and skew) components.

The transformation is used to represent a tansformed coordinate system, and provides methods to rotate(), scale(), shear() or translate() this coordinate system.

There are also 2 methods to decompose an arbitrary matrix into elementary operations:

with T a translation, R a rotation, Sxx a scale, and Sxy a skew component.


Nested Class Summary
static class WTransform.TRSRDecomposition
          Result of a TRSR decomposition.
static class WTransform.TRSSDecomposition
          Result of a TRSS decomposition.
 
Field Summary
static WTransform Identity
          A constant that represents the identity transform.
 
Constructor Summary
WTransform()
          Default constructor.
WTransform(double m11, double m12, double m21, double m22, double dx, double dy)
          Construct a custom matrix by specifying the parameters.
 
Method Summary
 WTransform assign(WTransform rhs)
          Assignment method.
 WTransform clone()
          Clone method.
 void decomposeTranslateRotateScaleRotate(WTransform.TRSRDecomposition result)
          Decomposes the transformation.
 void decomposeTranslateRotateScaleSkew(WTransform.TRSSDecomposition result)
          Decomposes the transformation.
static double degreesToRadians(double angle)
          Utility method to convert degrees to radians.
 boolean equals(WTransform rhs)
          Indicates whether some other object is "equal to" this one.
 WTransform getAdjoint()
          Returns the adjoint.
 double getDeterminant()
          Returns the determinant.
 double getDx()
          Returns the horizontal translation factor.
 double getDy()
          Returns the vertical translation factor.
 WTransform getInverted()
          Returns the inverted transformation.
 double getM11()
          Returns the horizontal scaling factor.
 double getM12()
          Returns the vertical shearing factor.
 double getM13()
          Returns m13 = 0.
 double getM21()
          Returns the horizontal shearing factor.
 double getM22()
          Returns the vertical scaling factor.
 double getM23()
          Returns m23 = 0.
 double getM31()
          Returns the horizontal translation factor.
 double getM32()
          Returns the vertical translation factor.
 double getM33()
          Returns m33 = 1.
 boolean isIdentity()
          Identity check.
 void map(double x, double y, java.lang.Double tx, java.lang.Double ty)
          Applys the transformation to a point.
 WPointF map(WPointF p)
          Applys the transformation to a point.
 WTransform multiply(WTransform rhs)
          Multiply 2 transform objects.
 WTransform multiplyAndAssign(WTransform Y)
          Adds a transform that is conceptually applied after this transform.
 void reset()
          Resets the transformation to the identity.
 WTransform rotate(double angle)
          Rotates the transformation.
 WTransform rotateRadians(double angle)
          Rotates the transformation.
 WTransform scale(double sx, double sy)
          Scales the transformation.
 WTransform shear(double sh, double sv)
          Shears the transformation.
 WTransform translate(double dx, double dy)
          Translates the transformation.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

Identity

public static final WTransform Identity
A constant that represents the identity transform.

See Also:
isIdentity()
Constructor Detail

WTransform

public WTransform()
Default constructor.

Creates the identity transformation matrix.


WTransform

public WTransform(double m11,
                  double m12,
                  double m21,
                  double m22,
                  double dx,
                  double dy)
Construct a custom matrix by specifying the parameters.

Creates a matrix from the specified parameters.

Method Detail

assign

public WTransform assign(WTransform rhs)
Assignment method.

Copies the transformation from the rhs.


clone

public WTransform clone()
Clone method.

Clones this WTransform object.

Overrides:
clone in class java.lang.Object

equals

public boolean equals(WTransform rhs)
Indicates whether some other object is "equal to" this one.

Returns true if the transforms are exactly the same.


isIdentity

public boolean isIdentity()
Identity check.

Returns true if the transform represents an identity transformation.


getM11

public double getM11()
Returns the horizontal scaling factor.


getM12

public double getM12()
Returns the vertical shearing factor.


getM13

public double getM13()
Returns m13 = 0.


getM21

public double getM21()
Returns the horizontal shearing factor.


getM22

public double getM22()
Returns the vertical scaling factor.


getM23

public double getM23()
Returns m23 = 0.


getM31

public double getM31()
Returns the horizontal translation factor.

Is equivalent to getDx()


getM32

public double getM32()
Returns the vertical translation factor.

Is equivalent to getDy()


getM33

public double getM33()
Returns m33 = 1.


getDx

public double getDx()
Returns the horizontal translation factor.

Is equivalent to getM31()


getDy

public double getDy()
Returns the vertical translation factor.

Is equivalent to getM32()


map

public WPointF map(WPointF p)
Applys the transformation to a point.

Returns the transformed point.

See Also:
map(double x, double y, Double tx, Double ty)

map

public void map(double x,
                double y,
                java.lang.Double tx,
                java.lang.Double ty)
Applys the transformation to a point.

Sets the point (tx, ty) to the transformation of the point (x, y).

See Also:
map(WPointF p)

reset

public void reset()
Resets the transformation to the identity.

See Also:
isIdentity(), WTransform()

rotate

public WTransform rotate(double angle)
Rotates the transformation.

Applies a clock-wise rotation to the current transformation matrix, over angle degrees.

See Also:
rotateRadians(double angle)

rotateRadians

public WTransform rotateRadians(double angle)
Rotates the transformation.

Applies a clock-wise rotation to the current transformation matrix, over angle radians.

See Also:
rotate(double angle)

scale

public WTransform scale(double sx,
                        double sy)
Scales the transformation.

Applies a clock-wise rotation to the current transformation matrix, over angle radians.

See Also:
shear(double sh, double sv)

shear

public WTransform shear(double sh,
                        double sv)
Shears the transformation.

Shears the current transformation.

See Also:
scale(double sx, double sy), rotate(double angle)

translate

public WTransform translate(double dx,
                            double dy)
Translates the transformation.

Translates the current transformation.


multiplyAndAssign

public WTransform multiplyAndAssign(WTransform Y)
Adds a transform that is conceptually applied after this transform.


multiply

public WTransform multiply(WTransform rhs)
Multiply 2 transform objects.


getDeterminant

public double getDeterminant()
Returns the determinant.


getAdjoint

public WTransform getAdjoint()
Returns the adjoint.


getInverted

public WTransform getInverted()
Returns the inverted transformation.

Returns this if the transformation could not be inverted ( getDeterminant() == 0), and logs an error instead.


decomposeTranslateRotateScaleSkew

public void decomposeTranslateRotateScaleSkew(WTransform.TRSSDecomposition result)
Decomposes the transformation.

Decomposes the transformation into elementary operations: translation (dx, dy), followed by rotation (alpha), followed by scale (sx, sy) and vertical shearing factor (sh). The angle is expressed in radians.

This performs a Gram-Schmidt orthonormalization.


decomposeTranslateRotateScaleRotate

public void decomposeTranslateRotateScaleRotate(WTransform.TRSRDecomposition result)
Decomposes the transformation.

Decomposes the transformation into elementary operations: translation (dx, dy), followed by rotation (alpha2), followed by scale (sx, sy) and again a rotation ( alpha2). The angles are expressed in radians.

This performs a Singular Value Decomposition (SVD).


degreesToRadians

public static double degreesToRadians(double angle)
Utility method to convert degrees to radians.