|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--gishur.graph.gui.AffineTransformation
This class represents a 2D affine transform which performs a linear mapping from 2D coordinates to other 2D coordinates in a manner which preserves the "straightness" and "parallelness" of lines. Affine transformations can be constructed using sequences of translations, scales, flips, rotations, and shears.
Such a coordinate transformation can be represented by a 3 row by
3 column matrix with an implied last row of [ 0 0 1 ] which
transforms source coordinates (x,y)
into
destination coordinates (x',y')
by considering
them to be a column vector and multiplying the coordinate vector
by the matrix according to the following process.
[ x'] [ m00 m01 m02 ] [ x ] [ m00x + m01y + m02 ] [ y'] = [ m10 m11 m12 ] [ y ] = [ m10x + m11y + m12 ] [ 1 ] [ 0 0 1 ] [ 1 ] [ 1 ]
Constructor Summary | |
AffineTransformation()
Constructs a new AffineTransformation representing the Identity transformation. |
|
AffineTransformation(AffineTransformation Tx)
Constructs a new AffineTransformation representing a copy of another AffineTransformation object. |
|
AffineTransformation(double[] flatmatrix)
Constructs a new AffineTransformation from an array of double precision values representing either the 4 non-translation or the 6 specifiable entries of the 3x3 transformation matrix. |
|
AffineTransformation(double m00,
double m01,
double m02,
double m10,
double m11,
double m12)
Constructs a new AffineTransformation from 6 double precision values representing the 6 specifiable entries of the 3x3 transformation matrix. |
Method Summary | |
java.lang.Object |
clone()
Returns a copy of this AffineTransformation object. |
void |
concatenate(AffineTransformation Tx)
Concatenates an AffineTransformation Tx to this AffineTransformation Cx in the most commonly useful way to provide a new user space which is mapped to the former user space by Tx. |
void |
concatenate(double n00,
double n01,
double n02,
double n10,
double n11,
double n12)
Concatenates the given transformation matrix to this AffineTransformation. |
AffineTransformation |
createInverse()
Returns an AffineTransformation object representing the inverse transformation. |
static AffineTransformation |
createRotation(double theta)
Returns a transform representing a rotation transformation. |
static AffineTransformation |
createRotation(double theta,
double x,
double y)
Returns a transform that rotates coordinates around an anchor point. |
static AffineTransformation |
createScale(double sx,
double sy)
Returns a transform representing a scaling transformation. |
static AffineTransformation |
createShear(double shx,
double shy)
Returns a transform representing a shearing transformation. |
static AffineTransformation |
createTranslation(double tx,
double ty)
Returns a transform representing a translation transformation. |
void |
deltaTransform(float[] src,
int srcoff,
float[] dst,
int dstoff,
int num)
Transforms an array of relative distance vectors by this transform. |
float[] |
deltaTransform(float x,
float y)
Transforms a specified relative distance vector by this transform and returns the result as float array of length 2. |
FloatPoint |
deltaTransform(FloatPoint p)
Transforms the coordinates of the given Point like a distance
vector (neglecting translations possibly represented by this AffineTransformation )
and returns its result as a new Point . |
void |
deltaTransform(FloatPoint[] src,
int srcoff,
FloatPoint[] dst,
int dstoff,
int num)
Transforms an array of relative distance vectors by this transform. |
double |
determinant()
Returns the determinant of the matrix representation of the transform. |
double |
element(int i,
int j)
Returns the element with row index i and column index
j (e.g. |
boolean |
equals(java.lang.Object obj)
Returns true if this AffineTransformation represents the same affine coordinate transform as the given argument. |
void |
inverseTransform(float[] src,
int srcoff,
float[] dst,
int dstoff,
int num)
Inverse transforms an array of float precision coordinates by this transformation. |
float[] |
inverseTransform(float x,
float y)
Inverse transforms the specified point (given in float coordinates) and
returns the result as a FloatPoint . |
FloatPoint |
inverseTransform(FloatPoint p)
Inverse transforms the specified Point and returns the result as
a new java.awt.Point . |
void |
inverseTransform(FloatPoint[] src,
int srcoff,
FloatPoint[] dst,
int dstoff,
int num)
Inverse transforms an array of FloatPoints by this transformation.
|
boolean |
isIdentity()
Returns true if this AffineTransformation is an identity transform. |
double[] |
matrix()
Returns the 6 specifiable values in the 3x3 affine transformation matrix as an array of double precisions values. |
void |
preConcatenate(AffineTransformation Tx)
Concatenates an AffineTransformation Tx to this AffineTransformation Cx in a less commonly used way such that Tx modifies the coordinate transformation relative to the absolute pixel space rather than relative to the existing user space. |
void |
preConcatenate(double n00,
double n01,
double n02,
double n10,
double n11,
double n12)
Concatenates this AffineTransformation to the given transformation matrix. |
void |
rotate(double theta)
Concatenates this transform with a rotation transformation. |
void |
rotate(double theta,
double x,
double y)
Concatenates this transform with a transform that rotates coordinates around an anchor point. |
void |
scale(double sx,
double sy)
Concatenates this transform with a scaling transformation. |
double |
scaleX()
Returns the X coordinate scaling element (m00) of the 3x3 affine transformation matrix. |
double |
scaleY()
Returns the Y coordinate scaling element (m11) of the 3x3 affine transformation matrix. |
void |
setToIdentity()
Resets this transform to the Identity transform. |
void |
setToRotation(double theta)
Sets this transform to a rotation transformation. |
void |
setToRotation(double theta,
double x,
double y)
Sets this transform to a translated rotation transformation. |
void |
setToScale(double sx,
double sy)
Sets this transform to a scaling transformation. |
void |
setToShear(double shx,
double shy)
Sets this transform to a shearing transformation. |
void |
setToTranslation(double tx,
double ty)
Sets this transform to a translation transformation. |
void |
setTransform(AffineTransformation Tx)
Sets this transform to a copy of the transform in the indicated AffineTransformation object. |
void |
setTransform(double m00,
double m01,
double m02,
double m10,
double m11,
double m12)
Sets this transform to the matrix specified by the 6 double precision values. |
void |
shear(double shx,
double shy)
Concatenates this transform with a shearing transformation. |
double |
shearX()
Returns the X coordinate shearing element (m01) of the 3x3 affine transformation matrix. |
double |
shearY()
Returns the Y coordinate shearing element (m10) of the 3x3 affine transformation matrix. |
java.lang.String |
toString()
Returns a String that represents the value of this Object. |
void |
transform(float[] src,
int srcoff,
float[] dst,
int dstoff,
int num)
Transforms an array of float precision coordinates by this transformation. |
float[] |
transform(float x,
float y)
Transforms two float -coordinates to a FloatPoint . |
FloatPoint |
transform(FloatPoint point)
Transforms a FloatPoint to a FloatPoint . |
void |
transform(FloatPoint[] src,
int srcoff,
FloatPoint[] dst,
int dstoff,
int num)
Transforms an array of FloatPoint by this transformation.
|
void |
translate(double tx,
double ty)
Concatenates this transform with a translation transformation. |
double |
translateX()
Returns the X coordinate translation element (m02) of the 3x3 affine transformation matrix. |
double |
translateY()
Returns the Y coordinate translation element (m12) of the 3x3 affine transformation matrix. |
Methods inherited from class java.lang.Object |
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public AffineTransformation()
public AffineTransformation(AffineTransformation Tx)
Tx
- the AffineTransformation object from which to copy the
transformationpublic AffineTransformation(double m00, double m01, double m02, double m10, double m11, double m12)
public AffineTransformation(double[] flatmatrix)
{m00,m01,m02,m10,m11,m12}
.flatmatrix
- The double array containing the values to be set
in the new AffineTransformation object. The length of the array is
assumed to be at least 6.Method Detail |
public static AffineTransformation createTranslation(double tx, double ty)
[ 1 0 tx ] [ 0 1 ty ] [ 0 0 1 ]
tx
- The distance by which coordinates are translated in the
X axis directionty
- The distance by which coordinates are translated in the
Y axis directionpublic static AffineTransformation createRotation(double theta)
[ cos(theta) -sin(theta) 0 ] [ sin(theta) cos(theta) 0 ] [ 0 0 1 ]Rotating with a positive angle theta rotates points on the positive x axis toward the positive y axis.
theta
- The angle of rotation in radians.public static AffineTransformation createRotation(double theta, double x, double y)
The matrix representing by the returned transform transform will be:
[ cos(theta) -sin(theta) x-x*cos(theta)+y*sin(theta) ] [ sin(theta) cos(theta) y-x*sin(theta)-y*cos(theta) ] [ 0 0 1 ]Rotating with a positive angle theta rotates points on the positive x axis toward the positive y axis.
theta
- The angle of rotation in radians.x
- The x coordinate of the anchor point of the rotationy
- The x coordinate of the anchor point of the rotationpublic static AffineTransformation createScale(double sx, double sy)
[ sx 0 0 ] [ 0 sy 0 ] [ 0 0 1 ]
sx
- The factor by which coordinates are scaled along the
X axis directionsy
- The factor by which coordinates are scaled along the
Y axis directionpublic static AffineTransformation createShear(double shx, double shy)
[ 1 shx 0 ] [ shy 1 0 ] [ 0 0 1 ]
shx
- The multiplier by which coordinates are shifted in the
direction of the positive X axis as a factor of their Y coordinateshy
- The multiplier by which coordinates are shifted in the
direction of the positive Y axis as a factor of their X coordinatepublic double determinant()
If the determinant is non-zero, then this transform will be
invertible and the various methods which depend on the inverse
transform will not need to throw a NoninvertibleTransformationException
.
If the determinant is zero, then this transform can not be
inverted since the transform maps all input coordinates onto
a line or a point.
If the determinant is near enough to zero, then inverse transform
operations may not carry enough precision to produce meaningful
results.
Mathematically, the determinant is calculated using the formula:
| m00 m01 m02 | | m10 m11 m12 | = m00 * m11 - m01 * m10 | 0 0 1 |
createInverse()
,
inverseTransform(float, float)
public double[] matrix()
{m00,m01,m02,m10,m11,m12}
.scaleX()
,
scaleY()
,
shearX()
,
shearY()
,
translateX()
,
translateY()
public double element(int i, int j)
i
and column index
j
(e.g. element(0,1)
returns m01
).i
- row index;j
- column indexArrayIndexOutOfBoundsException
- if indizes are out of matrix
bounds.public double scaleX()
matrix()
public double scaleY()
matrix()
public double shearX()
matrix()
public double shearY()
matrix()
public double translateX()
matrix()
public double translateY()
matrix()
public void concatenate(AffineTransformation Tx)
[this] = [this] x [Tx]
Tx
- The AffineTransformation object to be concatenated with
this AffineTransformation object.preConcatenate(gishur.graph.gui.AffineTransformation)
public void concatenate(double n00, double n01, double n02, double n10, double n11, double n12)
[ m00 m01 m02 ] [ m10 m11 m12 ] [ 0 0 1 ]
n00,n01,n02
- first row of the transformation matrixn10,n11,n12
- second row of the transformation matrixpreConcatenate(gishur.graph.gui.AffineTransformation)
public void preConcatenate(AffineTransformation Tx)
[this] = [Tx] x [this]
Tx
- The AffineTransformation object to be concatenated with
this AffineTransformation object.concatenate(gishur.graph.gui.AffineTransformation)
public void preConcatenate(double n00, double n01, double n02, double n10, double n11, double n12)
[ n00 n01 n02 ] [ n10 n11 n12 ] [ 0 0 1 ]
n00,n01,n02
- first row of the transformation matrixn10,n11,n12
- second row of the transformation matrixpreConcatenate(gishur.graph.gui.AffineTransformation)
public void translate(double tx, double ty)
[ 1 0 tx ] [ 0 1 ty ] [ 0 0 1 ]
public void rotate(double theta)
[ cos(theta) -sin(theta) 0 ] [ sin(theta) cos(theta) 0 ] [ 0 0 1 ]Rotating with a positive angle theta rotates points on the positive x axis toward the positive y axis.
theta
- The angle of rotation in radians.public void rotate(double theta, double x, double y)
This operation is equivalent to the following sequence of calls:
translate(x, y); // S3: final translation rotate(theta); // S2: rotate around anchor translate(-x, -y); // S1: translate anchor to originRotating with a positive angle theta rotates points on the positive x axis toward the positive y axis.
theta
- The angle of rotation in radians.x
- The x coordinate of the anchor point of the rotationy
- The x coordinate of the anchor point of the rotationpublic void scale(double sx, double sy)
[ sx 0 0 ] [ 0 sy 0 ] [ 0 0 1 ]
public void shear(double shx, double shy)
[ 1 shx 0 ] [ shy 1 0 ] [ 0 0 1 ]
shx
- The multiplier by which coordinates are shifted in the
direction of the positive X axis as a factor of their Y coordinateshy
- The multiplier by which coordinates are shifted in the
direction of the positive Y axis as a factor of their X coordinatepublic void setToIdentity()
public void setToTranslation(double tx, double ty)
[ 1 0 tx ] [ 0 1 ty ] [ 0 0 1 ]
tx
- The distance by which coordinates are translated in the
X axis directionty
- The distance by which coordinates are translated in the
Y axis directionpublic void setToRotation(double theta)
[ cos(theta) -sin(theta) 0 ] [ sin(theta) cos(theta) 0 ] [ 0 0 1 ]Rotating with a positive angle theta rotates points on the positive x axis toward the positive y axis.
theta
- The angle of rotation in radians.public void setToRotation(double theta, double x, double y)
This operation is equivalent to the following sequence of calls:
setToTranslation(x, y); // S3: final translation rotate(theta); // S2: rotate around anchor translate(-x, -y); // S1: translate anchor to originThe matrix representing this transform becomes:
[ cos(theta) -sin(theta) x-x*cos+y*sin ] [ sin(theta) cos(theta) y-x*sin-y*cos ] [ 0 0 1 ]Rotating with a positive angle theta rotates points on the positive x axis toward the positive y axis.
theta
- The angle of rotation in radians.x
- The x coordinate of the anchor point of the rotationy
- The x coordinate of the anchor point of the rotationpublic void setToScale(double sx, double sy)
[ sx 0 0 ] [ 0 sy 0 ] [ 0 0 1 ]
sx
- The factor by which coordinates are scaled along the
X axis directionsy
- The factor by which coordinates are scaled along the
Y axis directionpublic void setToShear(double shx, double shy)
[ 1 shx 0 ] [ shy 1 0 ] [ 0 0 1 ]
shx
- The multiplier by which coordinates are shifted in the
direction of the positive X axis as a factor of their Y coordinateshy
- The multiplier by which coordinates are shifted in the
direction of the positive Y axis as a factor of their X coordinatepublic void setTransform(AffineTransformation Tx)
Tx
- the AffineTransformation object from which to copy the transformpublic void setTransform(double m00, double m01, double m02, double m10, double m11, double m12)
public AffineTransformation createInverse()
If this transform maps all coordinates onto a point or a line
then it will not have an inverse, since coordinates that do
not lie on the destination point or line will not have an inverse
mapping.
The determinant()
method can be used to determine if this
transform has no inverse, in which case an exception will be
thrown if the createInverse method is called.
determinant()
public float[] transform(float x, float y)
float
-coordinates to a FloatPoint
.x,y
- two coordinatesFloatPoint
public FloatPoint transform(FloatPoint point)
FloatPoint
to a FloatPoint
.x,y
- two coordinatesFloatPoint
public void transform(float[] src, int srcoff, float[] dst, int dstoff, int num)
[x0, y0, x1, y1, ..., xn, yn]
.src
- The array containing the source point coordinates.
Each point is stored as a pair of x,y coordinates.srcoff
- The offset to the first point to be transformed
in the source array.dst
- The array where the transformed point coordinates are
returned. Each point is stored as a pair of x,y coordinates.dstoff
- The offset to the location where the first transformed
point is stored in the destination array.num
- The number of point objects to be transformed.public void transform(FloatPoint[] src, int srcoff, FloatPoint[] dst, int dstoff, int num)
FloatPoint
by this transformation.
The two coordinate array sections may be exactly the same or
overlapping sections of the same array without affecting the
validity of the results.
This method will ensure that no source coordinates will be
overwritten by a previous operation before they can be transformed.
The coordinates are stored in the arrays starting at the indicated
offset.src
- The array containing the source points
Each point is stored as a FloatPoint
.srcoff
- The offset to the first point to be transformed
in the source array.dst
- The array where the transformed points are
returneddstoff
- The offset to the location where the first transformed
point is stored in the destination array.num
- The number of points to be transformed.public float[] inverseTransform(float x, float y)
float
coordinates) and
returns the result as a FloatPoint
.x,y
- point to transformFloatPoint
.public FloatPoint inverseTransform(FloatPoint p)
Point
and returns the result as
a new java.awt.Point
.x,y
- point to transformpublic void inverseTransform(float[] src, int srcoff, float[] dst, int dstoff, int num)
[x0, y0, x1, y1, ..., xn, yn]
.src
- The array containing the source point coordinates.
Each point is stored as a pair of x,y coordinates.srcoff
- The offset to the first point to be transformed
in the source array.dst
- The array where the transformed point coordinates are
returned. Each point is stored as a pair of x,y coordinates.dstoff
- The offset to the location where the first transformed
point is stored in the destination array.num
- The number of point objects to be transformed.public void inverseTransform(FloatPoint[] src, int srcoff, FloatPoint[] dst, int dstoff, int num)
FloatPoints
by this transformation.
The two coordinate array sections may be exactly the same or
overlapping sections of the same array without affecting the
validity of the results.
This method will ensure that no source coordinates will be
overwritten by a previous operation before they can be transformed.
The coordinates are stored in the arrays starting at the indicated
offset.src
- The array containing the source points
Each point is stored as a FloatPoint
.srcoff
- The offset to the first point to be inversely transformed
in the source array.dst
- The array where the transformed points are
returneddstoff
- The offset to the location where the first transformed
point is stored in the destination array.num
- The number of points to be transformed.public float[] deltaTransform(float x, float y)
x,y
- the relative distance vectorpublic FloatPoint deltaTransform(FloatPoint p)
Point
like a distance
vector (neglecting translations possibly represented by this AffineTransformation
)
and returns its result as a new Point
.p
- the Point
representing a vector to transformpublic void deltaTransform(float[] src, int srcoff, float[] dst, int dstoff, int num)
[ x' ] [ m00 m01 (m02) ] [ x ] [ m00x + m01y ] [ y' ] = [ m10 m11 (m12) ] [ y ] = [ m10x + m11y ] [ (1) ] [ (0) (0) ( 1 ) ] [ (1) ] [ (1) ]The two coordinate array sections may be exactly the same or overlapping sections of the same array without affecting the validity of the results. This method will ensure that no source coordinates will be overwritten by a previous operation before they can be transformed. The coordinates are stored in the arrays starting at the indicated offset in the order
[x0, y0, x1, y1, ..., xn, yn]
.src
- The array containing the source distance vectors.
Each vector is stored as a pair of relative x,y coordinates.dst
- The array where the transformed distance vectors are
returned. Each vector is stored as a pair of relative x,y coordinates.srcoff
- The offset to the first vector to be transformed
in the source array.dstoff
- The offset to the location where the first transformed
vector is stored in the destination array.num
- The number of vector coordinate pairs to be transformed.public void deltaTransform(FloatPoint[] src, int srcoff, FloatPoint[] dst, int dstoff, int num)
[ x' ] [ m00 m01 (m02) ] [ x ] [ m00x + m01y ] [ y' ] = [ m10 m11 (m12) ] [ y ] = [ m10x + m11y ] [ (1) ] [ (0) (0) ( 1 ) ] [ (1) ] [ (1) ]The two
FloatPoint
array sections may be exactly the same or
overlapping sections of the same array without affecting the
validity of the results.
This method will ensure that no source coordinates will be
overwritten by a previous operation before they can be transformed.src
- The array containing the source distance vectors as FloatPoints
.dst
- The array where the transformed distance vectors are
returned.srcoff
- The offset to the first vector to be transformed
in the source array.dstoff
- The offset to the location where the first transformed
vector is stored in the destination array.num
- The number of vector FloatPoints
to be transformed.public java.lang.String toString()
toString
in class java.lang.Object
public boolean isIdentity()
public java.lang.Object clone()
clone
in interface Cloneable
clone
in class java.lang.Object
gishur.core.Cloneable
this
object.public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |