Package org.eclipse.gef.geometry.planar
Class AffineTransform
java.lang.Object
org.eclipse.gef.geometry.planar.AffineTransform
- All Implemented Interfaces:
Cloneable
The AffineTransform class provides methods to create and modify
2-dimensional affine transformations.
It delegates to the AffineTransform functionality.
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a newAffineTransformwith its transformation matrix set to the identity matrix.AffineTransform(double[] flatmatrix) Creates a newAffineTransformwith its transformation matrix set to the values of the passed-in array.AffineTransform(double m00, double m10, double m01, double m11, double m02, double m12) Creates a newAffineTransformwith its transformation matrix set to the specified values. -
Method Summary
Modifier and TypeMethodDescriptionclone()Concatenates thisAffineTransformand the givenAffineTransform, multiplying the transformation matrix of thisAffineTransformfrom the left with the transformation matrix of the otherAffineTransform.voiddeltaTransform(double[] srcPts, int srcOff, double[] dstPts, int dstOff, int numPts) Transforms an array ofPoints specified by their coordinate values with thisAffineTransformwithout applying the translation components of the transformation matrix of thisAffineTransform.deltaTransform(Point pt) Transforms the givenPointwith thisAffineTransformwithout applying the translation components of the transformation matrix of thisAffineTransform.booleangetCopy()Returns a copy of thisAffineTransform.doubleComputes the determinant of the transformation matrix of thisAffineTransform.Creates a newAffineTransformthat represents the inverse transformation of thisAffineTransform.doublegetM00()Returns the matrix component in the first row and first column.doublegetM01()Returns the matrix component in the first row and second column.doublegetM10()Returns the matrix component in the second row and first column.doublegetM11()Returns the matrix component in the second row and second column.double[]Returns the 6 specifiable elements of the transformation matrix of thisAffineTransform.Returns the rotation component of thisAffineTransform.doubleReturns the x coordinate scaling of thisAffineTransform's transformation matrix.doubleReturns the y coordinate scaling of thisAffineTransform's transformation matrix.getTransformed(Point ptSrc) Transforms the givenPointwith thisAffineTransformby multiplying the transformation matrix of thisAffineTransformwith the givenPoint.Point[]getTransformed(Point[] points) Transforms the given array ofPoints with thisAffineTransformby multiplying the transformation matrix of thisAffineTransformindividually with each of the givenPoints.doubleReturns the x coordinate translation of thisAffineTransform's transformation matrix.doubleReturns the y coordinate translation of thisAffineTransform's transformation matrix.intgetType()Returns the type of transformation represented by thisAffineTransform.inthashCode()voidinverseTransform(double[] srcPts, int srcOff, double[] dstPts, int dstOff, int numPts) Inverse transforms an array ofPoints specified by their coordinate values with thisAffineTransform.Inverse transforms the givenPointwith thisAffineTransform.invert()Inverts thisAffineTransform.booleanChecks if the transformation matrix of thisAffineTransformequals the identity matrix.Concatenates thisAffineTransformand the givenAffineTransformin reverse order, multiplying the transformation matrix of thisAffineTransformfrom the right with the transformation matrix of the otherAffineTransform.quadrantRotate(int numquadrants) Adds a rotation by an integer multiple of 90deg to the transformation matrix of thisAffineTransform.quadrantRotate(int numquadrants, double anchorx, double anchory) Adds a rotation by an integer multiple of 90deg around thePointspecified by the given x and y coordinates to the transformation matrix of thisAffineTransform.rotate(double theta) Adds a rotation with the given angle (in radians) to the transformation matrix of thisAffineTransform.rotate(double vecx, double vecy) Adds a rotation to the transformation matrix of thisAffineTransform.rotate(double theta, double anchorx, double anchory) Adds a rotation with the given angle (in radians) around thePointspecified by the given x and y coordinates to the transformation matrix of thisAffineTransform.rotate(double vecx, double vecy, double anchorx, double anchory) Adds a rotation around aPointto the transformation matrix of thisAffineTransform.scale(double sx, double sy) Adds an x and y scaling to the transformation matrix of thisAffineTransform.Sets the transformation matrix of thisAffineTransformto the identity matrix.setToQuadrantRotation(int numquadrants) Sets the transformation matrix of thisAffineTransformto a pure rotation matrix where the rotation angle is an integer multiple of 90deg.setToQuadrantRotation(int numquadrants, double anchorx, double anchory) Sets the transformation matrix of thisAffineTransformto a pure rotation and translation matrix where the rotation angle is an integer multiple of 90deg and the rotation is around thePointspecified by the given x and y coordinates.setToRotation(double theta) Sets the transformation matrix of thisAffineTransformto a pure rotation matrix by the given angle specified in radians.setToRotation(double vecx, double vecy) Sets the transformation matrix of thisAffineTransformto a pure rotation matrix.setToRotation(double theta, double anchorx, double anchory) Sets the transformation matrix of thisAffineTransformto a pure rotation and translation matrix.setToRotation(double vecx, double vecy, double anchorx, double anchory) Sets the transformation matrix of thisAffineTransformto a pure rotation and translation matrix.setToScale(double sx, double sy) Sets the transformation matrix of thisAffineTransformto a pure scaling matrix.setToShear(double shx, double shy) Sets the transformation matrix of thisAffineTransformto a pure shearing matrix.setToTranslation(double tx, double ty) Sets the transformation matrix of thisAffineTransformto a pure translation matrix that translatesPoints by the given x and y values.setTransform(double m00, double m10, double m01, double m11, double m02, double m12) Sets the respective values of the transformation matrix of thisAffineTransformto the supplied ones.Sets the transformation matrix of thisAffineTransformto the transformation matrix of the givenAffineTransform.shear(double shx, double shy) Adds an x and y shearing to the transformation matrix of thisAffineTransform.toString()translate(double tx, double ty) Sets the translation values of the x and y coordinates of the transformation matrix of thisAffineTransform.
-
Constructor Details
-
AffineTransform
public AffineTransform()Creates a newAffineTransformwith its transformation matrix set to the identity matrix. -
AffineTransform
public AffineTransform(double m00, double m10, double m01, double m11, double m02, double m12) Creates a newAffineTransformwith its transformation matrix set to the specified values. Note that rotation is a combination of shearing and scaling.- Parameters:
m00- the value of the transformation matrix in row 0 and column 0 (x coordinate scaling)m10- the value of the transformation matrix in row 1 and column 0 (y coordinate shearing)m01- the value of the transformation matrix in row 0 and column 1 (x coordinate shearing)m11- the value of the transformation matrix in row 1 and column 1 (y coordinate scaling)m02- the value of the transformation matrix in row 0 and column 2 (x coordinate translation)m12- the value of the transformation matrix in row 1 and column 2 (y coordinate translation)
-
AffineTransform
public AffineTransform(double[] flatmatrix) Creates a newAffineTransformwith its transformation matrix set to the values of the passed-in array. See theAffineTransform(double, double, double, double, double, double)or theAffineTransform(double[])method for a specification of the values in the array.- Parameters:
flatmatrix- the values for the transformation matrix- See Also:
-
-
Method Details
-
clone
-
concatenate
Concatenates thisAffineTransformand the givenAffineTransform, multiplying the transformation matrix of thisAffineTransformfrom the left with the transformation matrix of the otherAffineTransform.- Parameters:
Tx- theAffineTransformthat is concatenated with thisAffineTransform- Returns:
thisfor convenience
-
deltaTransform
public void deltaTransform(double[] srcPts, int srcOff, double[] dstPts, int dstOff, int numPts) Transforms an array ofPoints specified by their coordinate values with thisAffineTransformwithout applying the translation components of the transformation matrix of thisAffineTransform.- Parameters:
srcPts- the array of x and y coordinates specifying thePoints that are transformedsrcOff- the index of the srcPts array where the x coordinate of the firstPointto transform is founddstPts- the destination array of x and y coordinates for the result of the transformationdstOff- the index of the dstPts array where the x coordinate of the first transformedPointis storednumPts- the number ofPoints to transform
-
deltaTransform
Transforms the givenPointwith thisAffineTransformwithout applying the translation components of the transformation matrix of thisAffineTransform. -
equals
-
getCopy
Returns a copy of thisAffineTransform.- Returns:
- a copy of this
AffineTransform
-
getDeterminant
public double getDeterminant()Computes the determinant of the transformation matrix of thisAffineTransform.- Returns:
- the determinant of the transformation matrix of this
AffineTransform
-
getInverse
Creates a newAffineTransformthat represents the inverse transformation of thisAffineTransform.- Returns:
- a new
AffineTransformthat represents the inverse transformation of thisAffineTransform
-
getM00
public double getM00()Returns the matrix component in the first row and first column.- Returns:
- The matrix component in the first row and first column.
-
getM01
public double getM01()Returns the matrix component in the first row and second column.- Returns:
- The matrix component in the first row and second column.
-
getM10
public double getM10()Returns the matrix component in the second row and first column.- Returns:
- The matrix component in the second row and first column.
-
getM11
public double getM11()Returns the matrix component in the second row and second column.- Returns:
- The matrix component in the second row and second column.
-
getMatrix
public double[] getMatrix()Returns the 6 specifiable elements of the transformation matrix of thisAffineTransform.- Returns:
- the 6 specifiable elements of the transformation matrix of this
AffineTransform
-
getRotation
Returns the rotation component of thisAffineTransform.- Returns:
- The rotation component of this
AffineTransform.
-
getScaleX
public double getScaleX()Returns the x coordinate scaling of thisAffineTransform's transformation matrix.- Returns:
- the x coordinate scaling of this
AffineTransform's transformation matrix
-
getScaleY
public double getScaleY()Returns the y coordinate scaling of thisAffineTransform's transformation matrix.- Returns:
- the y coordinate scaling of this
AffineTransform's transformation matrix
-
getTransformed
Transforms the givenPointwith thisAffineTransformby multiplying the transformation matrix of thisAffineTransformwith the givenPoint. -
getTransformed
Transforms the given array ofPoints with thisAffineTransformby multiplying the transformation matrix of thisAffineTransformindividually with each of the givenPoints. -
getTranslateX
public double getTranslateX()Returns the x coordinate translation of thisAffineTransform's transformation matrix.- Returns:
- the x coordinate translation of this
AffineTransform's transformation matrix
-
getTranslateY
public double getTranslateY()Returns the y coordinate translation of thisAffineTransform's transformation matrix.- Returns:
- the y coordinate translation of this
AffineTransform's transformation matrix
-
getType
public int getType()Returns the type of transformation represented by thisAffineTransform. See theAffineTransform.getType()method for a specification of the return type of this method.- Returns:
- the type of transformation represented by this
AffineTransform
-
hashCode
public int hashCode() -
inverseTransform
public void inverseTransform(double[] srcPts, int srcOff, double[] dstPts, int dstOff, int numPts) throws NoninvertibleTransformException Inverse transforms an array ofPoints specified by their coordinate values with thisAffineTransform.- Parameters:
srcPts- the array of x and y coordinates specifying thePoints that are inverse transformedsrcOff- the index of the srcPts array where the x coordinate of the firstPointto inverse transform is founddstPts- the destination array of x and y coordinates for the result of the inverse transformationdstOff- the index of the dstPts array where the x coordinate of the first inverse transformedPointis storednumPts- the number ofPoints to inverse transform- Throws:
NoninvertibleTransformException- when thisAffineTransformis not invertible.
-
inverseTransform
Inverse transforms the givenPointwith thisAffineTransform.- Parameters:
pt- thePointto inverse transform- Returns:
- a new, inverse transformed
Point - Throws:
NoninvertibleTransformException- when thisAffineTransformis not invertible.
-
invert
Inverts thisAffineTransform.- Returns:
thisfor convenience- Throws:
NoninvertibleTransformException- when thisAffineTransformis not invertible.
-
isIdentity
public boolean isIdentity()Checks if the transformation matrix of thisAffineTransformequals the identity matrix.- Returns:
trueif the transformation matrix of thisAffineTransformequals the identity matrix, otherwisefalse
-
preConcatenate
Concatenates thisAffineTransformand the givenAffineTransformin reverse order, multiplying the transformation matrix of thisAffineTransformfrom the right with the transformation matrix of the otherAffineTransform.- Parameters:
Tx- theAffineTransformthat is concatenated with thisAffineTransformin reverse order- Returns:
thisfor convenience
-
quadrantRotate
Adds a rotation by an integer multiple of 90deg to the transformation matrix of thisAffineTransform. The integer multiple of 90deg is specified by the given number of quadrants.- Parameters:
numquadrants- the integer that defines the number of quadrants to rotate by- Returns:
thisfor convenience
-
quadrantRotate
Adds a rotation by an integer multiple of 90deg around thePointspecified by the given x and y coordinates to the transformation matrix of thisAffineTransform. -
rotate
Adds a rotation with the given angle (in radians) to the transformation matrix of thisAffineTransform.- Parameters:
theta- the rotation angle in radians- Returns:
thisfor convenience
-
rotate
Adds a rotation to the transformation matrix of thisAffineTransform. The given coordinates specify aVectorwhoseAngleto the x-axis is the applied rotationAngle. -
rotate
Adds a rotation with the given angle (in radians) around thePointspecified by the given x and y coordinates to the transformation matrix of thisAffineTransform. -
rotate
-
scale
Adds an x and y scaling to the transformation matrix of thisAffineTransform.- Parameters:
sx- the x scaling factor added to the transformation matrix of thisAffineTransformsy- the y scaling factor added to the transformation matrix of thisAffineTransform- Returns:
thisfor convenience
-
setToIdentity
Sets the transformation matrix of thisAffineTransformto the identity matrix.- Returns:
thisfor convenience
-
setToQuadrantRotation
Sets the transformation matrix of thisAffineTransformto a pure rotation matrix where the rotation angle is an integer multiple of 90deg.- Parameters:
numquadrants- the integer that defines the number of quadrants to rotate by- Returns:
thisfor convenience
-
setToQuadrantRotation
Sets the transformation matrix of thisAffineTransformto a pure rotation and translation matrix where the rotation angle is an integer multiple of 90deg and the rotation is around thePointspecified by the given x and y coordinates. -
setToRotation
Sets the transformation matrix of thisAffineTransformto a pure rotation matrix by the given angle specified in radians.- Parameters:
theta- the rotation angle (in radians)- Returns:
thisfor convenience
-
setToRotation
Sets the transformation matrix of thisAffineTransformto a pure rotation matrix. The given x and y coordinates specify aVectorwhoseAngleto the x-axis defines the rotationAngle. -
setToRotation
Sets the transformation matrix of thisAffineTransformto a pure rotation and translation matrix. Thus, the resulting transformation matrix rotatesPoints by the given angle (in radians) around thePointspecified by the given x and y coordinates. -
setToRotation
Sets the transformation matrix of thisAffineTransformto a pure rotation and translation matrix. The firstly given x and y coordinates specify aVectorwhoseAngleto the x-axis defines the rotationAngle. The secondly given x and y coordinates specify thePointto rotate around.- Parameters:
vecx- the x coordinate of theVectorwhoseAngleto the x-axis defines the rotationAnglevecy- the y coordinate of theVectorwhoseAngleto the x-axis defines the rotationAngleanchorx- the x coordinate of thePointto rotate aroundanchory- the y coordinate of thePointto rotate around- Returns:
thisfor convenience
-
setToScale
Sets the transformation matrix of thisAffineTransformto a pure scaling matrix.- Parameters:
sx- the x scaling factorsy- the y scaling factor- Returns:
thisfor convenience
-
setToShear
Sets the transformation matrix of thisAffineTransformto a pure shearing matrix.- Parameters:
shx- the x shearing factorshy- the y shearing factor- Returns:
thisfor convenience
-
setToTranslation
Sets the transformation matrix of thisAffineTransformto a pure translation matrix that translatesPoints by the given x and y values.- Parameters:
tx- the x translation valuety- the y translation value- Returns:
thisfor convenience
-
setTransform
Sets the transformation matrix of thisAffineTransformto the transformation matrix of the givenAffineTransform.- Parameters:
Tx- theAffineTransformspecifying the new transformation matrix of thisAffineTransform- Returns:
thisfor convenience
-
setTransform
public AffineTransform setTransform(double m00, double m10, double m01, double m11, double m02, double m12) Sets the respective values of the transformation matrix of thisAffineTransformto the supplied ones. Note that rotation is a combination of shearing and scaling.- Parameters:
m00- the value of the transformation matrix in row 0 and column 0 (x coordinate scaling)m10- the value of the transformation matrix in row 1 and column 0 (y coordinate shearing)m01- the value of the transformation matrix in row 0 and column 1 (x coordinate shearing)m11- the value of the transformation matrix in row 1 and column 1 (y coordinate scaling)m02- the value of the transformation matrix in row 0 and column 2 (x coordinate translation)m12- the value of the transformation matrix in row 1 and column 2 (y coordinate translation)- Returns:
thisfor convenience
-
shear
Adds an x and y shearing to the transformation matrix of thisAffineTransform.- Parameters:
shx- the x shearing factor added to the transformation matrix of thisAffineTransformshy- the y shearing factor added to the transformation matrix of thisAffineTransform- Returns:
thisfor convenience
-
toString
-
translate
Sets the translation values of the x and y coordinates of the transformation matrix of thisAffineTransform.- Parameters:
tx- the x coordinate translationty- the y coordinate translation- Returns:
thisfor convenience
-