TinyLine
v2.0

com.tinyline.tiny2d
Class TinyMatrix

java.lang.Object
  extended bycom.tinyline.tiny2d.TinyMatrix

public final class TinyMatrix
extends java.lang.Object

The TinyMatrix class represents a 2D affine transformation matrix. By modifying a TinyMatrix, objects can be scaled, rotated, translated, or transformed. TinyMatrix is represented by a transformation matrix written as:

  [  a    b   0 ]
  [  c    d   0 ]
  [  tx   ty  1 ]
 
Here tx and ty are single fixed point numbers and a,b,c,d are double fixed point numbers.

The transformations could be specified as combinations of those listed below:

If several transformations are applied, the order is important. In general, trnasformations should be done in the following order: translate, rotate, scale.

Coordinate trnasformations could be expressed as:

                            [  a    b   0 ]
    [x' y' 1 ] = [x  y  1]  [  c    d   0 ]
                            [  tx   ty  1 ]

 
By carring out the multiplication:
    x' = ax + cy + tx;

    y' = bx + dy + ty;
 

If a series of transformations is carried out, the transformatios can be multiplied together to produce a single equivalent transformation.

Version:
1.11
Author:
Andrew Girow

Field Summary
 int a
          The X coordinate scaling element of the 3x3 matrix.
 int angle
          A convenience attribute for TRANSFORM_ROTATE, TRANSFORM_SKEWX and TRANSFORM_SKEWY.
 int b
          The X coordinate shearing element of the 3x3 matrix.
 int c
          The Y coordinate shearing element of the 3x3 matrix.
 int d
          The Y coordinate scaling element of the 3x3 matrix.
 int rotateOriginX
          The rotate is about the point with rotateOriginX X coordinate.
 int rotateOriginY
          The rotate is about the point with rotateOriginY Y coordinate.
static byte TRANSFORM_MATRIX
          A 'matrix(...)' transformation type
static byte TRANSFORM_ROTATE
          A 'rotate(...)' transformation type
static byte TRANSFORM_SCALE
          A 'scale(...)' transformation type
static byte TRANSFORM_SKEWX
          A 'skewX(...)' transformation type
static byte TRANSFORM_SKEWY
          A 'skewY(...)' transformation type
static byte TRANSFORM_TRANSLATE
          A 'translate(...)' transformation type
static byte TRANSFORM_UNKNOWN
          A transformation type is not one of predefined types.
 int tx
          The X coordinate of the translation element of the 3x3 matrix.
 int ty
          The Y coordinate of the translation element of the 3x3 matrix.
 byte type
          The transformation type of the value as specified by one of the constants specified.
 
Constructor Summary
TinyMatrix()
          Constructs a new TinyMatrix representing the Identity transformation
TinyMatrix(TinyMatrix src)
          Constructs a new TinyMatrix that is a copy of the specified TinyMatrix object.
 
Method Summary
 void concatenate(TinyMatrix matrix1)
          Concatenates an TinyMatrix matrix1 to this TinyMatrix .
 void copy(TinyMatrix src)
          Copyies TinyMatrix src to this TinyMatrix .
 TinyMatrix inverse()
          Returns an TinyMatrix object representing the inverse transformation.
 void preConcatenate(TinyMatrix matrix)
          Concatenates an TinyMatrix matrix to this TinyMatrix .
 void reset()
          Sets this TinyMatrix object to the Identity transformation
 void rotate(int theta, int cx, int cy)
          Sets this transform to a rotation transformation that rotates coordinates around an anchor point.
 void scale(int sx, int sy)
          Sets this transform matrix to a scaling transformation.
 void skew(int alpha, int betta)
          Sets this transform to a skew transformation.
 void transform(TinyPoint point)
          Transforms the specified point
 void transformToDev(TinyPoint point, TinyPoint point1)
          Transforms the specified point to DEVICE SPACE and stores the result in point1.
 TinyRect transformToDev(TinyRect rect)
          Transforms the specified TinyRect rect to DEVICE SPACE.
 void translate(int tx, int ty)
          Sets this transform matrix to a translating transformation.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TRANSFORM_UNKNOWN

public static final byte TRANSFORM_UNKNOWN
A transformation type is not one of predefined types.

See Also:
Constant Field Values

TRANSFORM_MATRIX

public static final byte TRANSFORM_MATRIX
A 'matrix(...)' transformation type

See Also:
Constant Field Values

TRANSFORM_TRANSLATE

public static final byte TRANSFORM_TRANSLATE
A 'translate(...)' transformation type

See Also:
Constant Field Values

TRANSFORM_SCALE

public static final byte TRANSFORM_SCALE
A 'scale(...)' transformation type

See Also:
Constant Field Values

TRANSFORM_ROTATE

public static final byte TRANSFORM_ROTATE
A 'rotate(...)' transformation type

See Also:
Constant Field Values

TRANSFORM_SKEWX

public static final byte TRANSFORM_SKEWX
A 'skewX(...)' transformation type

See Also:
Constant Field Values

TRANSFORM_SKEWY

public static final byte TRANSFORM_SKEWY
A 'skewY(...)' transformation type

See Also:
Constant Field Values

type

public byte type
The transformation type of the value as specified by one of the constants specified.


angle

public int angle
A convenience attribute for TRANSFORM_ROTATE, TRANSFORM_SKEWX and TRANSFORM_SKEWY. It holds the angle that was specified


rotateOriginX

public int rotateOriginX
The rotate is about the point with rotateOriginX X coordinate.


rotateOriginY

public int rotateOriginY
The rotate is about the point with rotateOriginY Y coordinate.


a

public int a
The X coordinate scaling element of the 3x3 matrix.


b

public int b
The X coordinate shearing element of the 3x3 matrix.


c

public int c
The Y coordinate shearing element of the 3x3 matrix.


d

public int d
The Y coordinate scaling element of the 3x3 matrix.


tx

public int tx
The X coordinate of the translation element of the 3x3 matrix.


ty

public int ty
The Y coordinate of the translation element of the 3x3 matrix.

Constructor Detail

TinyMatrix

public TinyMatrix()
Constructs a new TinyMatrix representing the Identity transformation


TinyMatrix

public TinyMatrix(TinyMatrix src)
Constructs a new TinyMatrix that is a copy of the specified TinyMatrix object.

Parameters:
src - the TinyMatrix object to copy
Method Detail

reset

public final void reset()
Sets this TinyMatrix object to the Identity transformation


concatenate

public final void concatenate(TinyMatrix matrix1)
Concatenates an TinyMatrix matrix1 to this TinyMatrix . In matrix notation, this method does the following:

[this] = [this] x [matrix]

Parameters:
matrix1 - the TinyMatrix object.

copy

public final void copy(TinyMatrix src)
Copyies TinyMatrix src to this TinyMatrix . In matrix notation, this method does the following:

[this] = [src]

Parameters:
src - the TinyMatrix object.

preConcatenate

public final void preConcatenate(TinyMatrix matrix)
Concatenates an TinyMatrix matrix to this TinyMatrix . In matrix notation, this method does the following:

[this] = [matrix] x [this]

Parameters:
matrix - The TinyMatrix object.

inverse

public final TinyMatrix inverse()
Returns an TinyMatrix object representing the inverse transformation.

Returns:
a new TinyMatrix object representing the inverse transformation.

translate

public final void translate(int tx,
                            int ty)
Sets this transform matrix to a translating transformation. The matrix representing this transform is:
    [  1  0  0  1  tx  ty ]
 

Parameters:
tx - the distance along the x-axis in FIXED POINT precision
ty - the distance along the y-axis in FIXED POINT precision

scale

public final void scale(int sx,
                        int sy)
Sets this transform matrix to a scaling transformation. The matrix representing this transform is:
    [  sx  0  0  sy  0  0 ]
 

Parameters:
sx - the factor along the x-axis in DOUBLE FIXED POINT precision
sy - the factor along the y-axis in DOUBLE FIXED POINT precision

rotate

public final void rotate(int theta,
                         int cx,
                         int cy)
Sets this transform to a rotation transformation that rotates coordinates around an anchor point. The matrix representing this transform is:
    [ cos(theta)  sin(theta)  -sin(theta)  cos(theta)  x-x*cos+y*sin  y-x*sin-y*cos ]
 
Rotating the coordinate system axes by degrees counterclockwise.

Parameters:
theta - the angle of rotation in degrees

skew

public void skew(int alpha,
                 int betta)
Sets this transform to a skew transformation. The matrix representing this transform is:
    [ 1  tan(alpha) tan(betta) 1  0  0  1 ]
 

Parameters:
alpha - (in degrees) skews the x-axis by an angle alpha
betta - (in degrees) skews the y-axis by an angle betta

transform

public final void transform(TinyPoint point)
Transforms the specified point

Parameters:
point - the specified point to be transformed

transformToDev

public final void transformToDev(TinyPoint point,
                                 TinyPoint point1)
Transforms the specified point to DEVICE SPACE and stores the result in point1.

Parameters:
point - the specified point to be transformed
point1 - the specified point that stores the result.

transformToDev

public final TinyRect transformToDev(TinyRect rect)
Transforms the specified TinyRect rect to DEVICE SPACE.

Parameters:
rect - the specified TinyRect rect to be transformed
Returns:
the transformed TinyRect rectangle

TinyLine
v2.0

Provided under the terms of the TinyLine License Agreement that has been included with this distribution