public class Matrix extends Object
Canvas instance.
This class maintains a floating point array (whose length is 9) to form a 3x3 matrix. It provides interfaces to transform values in the array.
| 限定符和类型 | 类 | 说明 |
|---|---|---|
static class |
Matrix.ScaleToFit |
Enumerates modes of scaling a source rectangle into a destination rectangle.
|
| 构造器 | 说明 |
|---|---|
Matrix() |
Default constructor used to create a
Matrix instance. |
Matrix(float[] srcMatrixArray) |
A constructor used to create a
Matrix instance. |
Matrix(Matrix srcMatrix) |
A constructor used to create a
Matrix instance. |
| 限定符和类型 | 方法 | 说明 |
|---|---|---|
boolean |
cheapEqualTo(Matrix matrixM) |
Checks whether this
Matrix and a specified matrix are represented by identical bit patterns. |
void |
dirtyMatrixTypeCache() |
Sets internal cache to an unknown state.
|
boolean |
equals(Object object) |
Checks whether this
Matrix object equals the specified Matrix object. |
boolean |
equalsMatrixValue(Matrix otherMatrix) |
Obtains whether the specified object`s matrix value equals to the current matrix`s value.
|
float |
get(int index) |
Obtains a matrix value based on the array index.
|
float[] |
getData() |
Obtains the floating point array of a matrix.
|
void |
getElements(float[] elements) |
Obtains element values of this
Matrix. |
float |
getMaxScale() |
Obtains the maximum scale factor of this
Matrix by decomposing the scaling and skewing elements. |
float |
getMinScale() |
Obtains the minimum scale factor of this
Matrix by decomposing the scaling and skewing elements. |
float |
getPerspX() |
Obtains the horizontal perspective factor of this
Matrix. |
float |
getPerspY() |
Obtains the vertical perspective factor of this
Matrix. |
float |
getScaleX() |
Obtains the horizontal scale factor of this
Matrix. |
float |
getScaleY() |
Obtains the vertical scale factor of this
Matrix. |
float |
getSkewX() |
Obtains the horizontal skew factor of this
Matrix. |
float |
getSkewY() |
Obtains the vertical skew factor of this
Matrix. |
float |
getTranslateX() |
Obtains the horizontal translation factor of this
Matrix. |
float |
getTranslateY() |
Obtains the vertical translation factor of this
Matrix. |
int |
hashCode() |
Returns a hash code value for the object.
|
boolean |
hasPerspective() |
Checks whether this
Matrix contains perspective elements. |
int |
index(int row,
int col) |
Calculates the array index based on the input row and column numbers.
|
boolean |
invert(Matrix inverse) |
Inverts this
Matrix. |
boolean |
isFinite() |
Checks whether all elements of this
Matrix are finite. |
boolean |
isFixedStepInX() |
Checks whether an x-axis unit step can be represented by a constant vector
after matrix transformation is performed on the y axis.
|
boolean |
isIdentity() |
Checks if a matrix is an identity matrix.
|
boolean |
isScaleTranslate() |
Checks whether this
Matrix has been scaled and translated. |
boolean |
isSimilarity() |
Checks whether this
Matrix contains only rotation, uniform scale, and translation. |
boolean |
isTranslate() |
Checks whether this
Matrix has been translated. |
void |
mapPoints(float[] pts) |
Performs a matrix transformation on an array of points, and writes the transformation result into that array.
|
void |
mapPoints(float[] dst,
float[] src) |
Performs a matrix transformation on a source array of points, and writes the transformation result into a
destination array.
|
void |
mapPoints(float[] dst,
int dstIndex,
float[] src,
int srcIndex,
int pointCount) |
Performs a matrix transformation that starts from a specified point in a source array, and writes the
transformation result into a destination array.
|
float |
mapRadius(float radius) |
Calculates the mean radius of a circle after being mapped by this
Matrix. |
boolean |
mapRect(RectFloat rectFloat) |
Performs a matrix transformation on a rectangle and writes the transformation result into that rectangle.
|
boolean |
mapRect(RectFloat dst,
RectFloat src) |
Performs a matrix transformation on a source rectangle and writes the transformation result into a destination
rectangle.
|
void |
mapRectScaleTranslate(RectFloat dst,
RectFloat src) |
Performs matrix transformation on the source rectangle and
stores the transformation result in the destination rectangle.
|
void |
multiply(Matrix otherMatrix) |
Calculates the result of multiplying the current matrix with a specified one.
|
boolean |
postConcat(Matrix otherMatrix) |
Post-multiplies this
Matrix by a specified matrix. |
boolean |
postIDiv(int divx,
int divy) |
Post-multiplies this
Matrix with the specified scale factors. |
void |
postRotate(float degrees) |
Post-multiplies this
Matrix with the specified rotation. |
boolean |
postRotate(float degrees,
float px,
float py) |
Post-multiplies this
Matrix with the specified rotation and the specified position of the perspective
point. |
boolean |
postScale(float sx,
float sy) |
Post-multiplies this
Matrix with the specified scale. |
boolean |
postScale(float sx,
float sy,
float px,
float py) |
Post-multiplies this
Matrix with the specified scale and the specified position of the perspective
point. |
boolean |
postSkew(float kx,
float ky) |
Post-multiplies this
Matrix with the specified skew factors. |
boolean |
postSkew(float kx,
float ky,
float px,
float py) |
Post-multiplies this
Matrix around a specified pivot by the specified skew factors. |
boolean |
postTranslate(float dx,
float dy) |
Post-multiplies this
Matrix with the specified translation. |
boolean |
preConcat(Matrix otherMatrix) |
Pre-multiplies this
Matrix by a specified matrix. |
boolean |
preRotate(float degrees) |
Pre-multiplies this
Matrix with the specified rotation. |
boolean |
preRotate(float degrees,
float px,
float py) |
Pre-multiplies this
Matrix with the specified rotation and the specified position of the perspective
point. |
boolean |
preScale(float sx,
float sy) |
Pre-multiplies this
Matrix with the specified scale. |
boolean |
preScale(float sx,
float sy,
float px,
float py) |
Pre-multiplies this
Matrix with the specified scale and the specified position of the perspective point. |
boolean |
preservesAxisAlignment() |
Checks whether this
Matrix can map one Rect object to another. |
boolean |
preservesRightAngles() |
Checks whether this
Matrix contains only rotation, scale (non-uniform scale allowed), and translation. |
boolean |
preSkew(float kx,
float ky) |
Pre-multiplies this
Matrix with the specified skew. |
void |
preSkew(float kx,
float ky,
float px,
float py) |
Pre-multiplies this
Matrix with the specified skew and the specified position of the perspective point. |
boolean |
preTranslate(float dx,
float dy) |
Pre-multiplies this
Matrix with the specified translation. |
boolean |
rectStaysRect() |
Checks whether this
Matrix can map one rectangle to another. |
void |
reset() |
Resets this
Matrix to a unit matrix, also referred to as an identity matrix. |
void |
rotate(float angle) |
Implements the rotation of a matrix by a specified degree.
|
void |
scale(float scaleX,
float scaleY) |
Implements the scaling of a matrix on X-axis and Y-axis.
|
boolean |
setConcat(Matrix matrixA,
Matrix matrixB) |
Sets this
Matrix to matrix A multiplied by matrix B. |
void |
setElements(float[] elements) |
Sets element values for this
Matrix. |
void |
setIdentity() |
Sets the current matrix as an identity matrix.
|
void |
setMatrix(int row,
int col,
float value) |
Sets a value in a specified row and column of a matrix.
|
void |
setMatrix(Matrix srcMatrix) |
Copies the values in a specified
srcMatrix matrix to the current one. |
void |
setPerspX(float v) |
Sets the horizontal perspective factor for this
Matrix. |
void |
setPerspY(float v) |
Sets the vertical perspective factor for this
Matrix. |
boolean |
setPolyToPoly(float[] src,
int srcIndex,
float[] dst,
int dstIndex,
int pointCount) |
Sets this
Matrix to make the specified source points map to the specified destination points. |
boolean |
setRectToRect(RectFloat src,
RectFloat dst,
Matrix.ScaleToFit scaleToFit) |
Sets a source rectangle to be inside a destination rectangle based on the specified scaling mode.
|
void |
setRotate(float degrees) |
Sets the matrix to rotate around the pivot point (0,0) by a specified number of degrees.
|
void |
setRotate(float degrees,
float px,
float py) |
Sets the matrix to rotate around the pivot point (px,py) by a specified number of degrees.
|
void |
setScale(float sx,
float sy) |
Scales this
Matrix by the specified values. |
void |
setScale(float sx,
float sy,
float px,
float py) |
Scales this
Matrix by the specified values and the specified position of the perspective point. |
void |
setScaleTranslate(float sx,
float sy,
float tx,
float ty) |
Initializes the scale and translation factors of this
Matrix. |
void |
setScaleX(float v) |
Sets the horizontal scale factor for this
Matrix. |
void |
setScaleY(float v) |
Sets the vertical scale factor for this
Matrix. |
void |
setSinCos(float sinValue,
float cosValue) |
Sets this
Matrix to rotate about the perspective point (0,0) by the specified horizontal
and vertical components of the rotation vector. |
void |
setSinCos(float sinValue,
float cosValue,
float px,
float py) |
Sets this
Matrix to rotate about the perspective point at the specified coordinates
by the given horizontal and vertical components of the rotation vector. |
void |
setSkew(float kx,
float ky) |
Skews this
Matrix by the specified skew factors. |
void |
setSkew(float kx,
float ky,
float px,
float py) |
Skews this
Matrix around a specified pivot by the specified skew factors. |
void |
setSkewX(float v) |
Sets the horizontal skew factor for this
Matrix. |
void |
setSkewY(float v) |
Sets the vertical skew factor for this
Matrix. |
void |
setTranslate(float dx,
float dy) |
Translates this
Matrix with the specified values. |
void |
setTranslateX(float v) |
Sets the horizontal translation factor for this
Matrix. |
void |
setTranslateY(float v) |
Sets the vertical translation factor for this
Matrix. |
String |
toString() |
Obtains a string representation of this
Matrix object. |
void |
translate(float transX,
float transY) |
Implements the translation of a matrix according to the translation degree on X-axis and Y-axis.
|
void |
transpose() |
Implements the transpose of a matrix.
|
public Matrix()
Matrix instance.public Matrix(float[] srcMatrixArray)
Matrix instance.
This constructor creates a 3x3 matrix, and copies a specified array to initialize the matrix.
srcMatrixArray - Indicates the floating point array of the matrix. The array length is 9.public Matrix(Matrix srcMatrix)
Matrix instance.srcMatrix - Indicates the matrix from which the values are to copy.public float[] getData()
public int index(int row,
int col)
col - - Indicates the row index.row - - Indicates the column index.public void setMatrix(int row,
int col,
float value)
col - Indicates the column in which the value is to be set.row - Indicates the row in which the value is to be set.value - Indicates the value to be set.public void setMatrix(Matrix srcMatrix)
srcMatrix matrix to the current one.srcMatrix - Indicates the matrix from which the values are to copy.public void setIdentity()
public void reset()
Matrix to a unit matrix, also referred to as an identity matrix.public boolean isIdentity()
true if the matrix is an identity matrix; returns false otherwise.public boolean equalsMatrixValue(Matrix otherMatrix)
otherMatrix - Indicates the specified matrix.true if the specified object`s matrix value equals to the current matrix, returns
false otherwise.public void multiply(Matrix otherMatrix)
The specified matrix is placed to the right of the multiplication sign.
otherMatrix - Indicates the specified matrix to be multiplied with.public void rotate(float angle)
The matrix rotates clockwise if angle is a positive value, and counterclockwise
if it is a negative value.
angle - Indicates the rotation degree of the matrix.public void scale(float scaleX,
float scaleY)
scaleX - Indicates the scaling ratio on X-axis.scaleY - Indicates the scaling ratio on Y-axis.public void translate(float transX,
float transY)
transX - Indicates the X-axis translation degree.transY - Indicates the Y-axis translation degree.public void transpose()
public void setRotate(float degrees)
degrees - Indicates the number of degrees to rotate.public void setRotate(float degrees,
float px,
float py)
degrees - Indicates the number of degrees to rotate.px - Indicates the X coordinate of the pivot point.py - Indicates the Y coordinate of the pivot point.public void getElements(float[] elements)
Matrix.elements - Indicates an array for storing the obtained element values.public void setElements(float[] elements)
Matrix.elements - Indicates an array of element values to be set for this Matrix.public boolean invert(Matrix inverse)
Matrix.inverse - Indicates the matrix to hold the inverse of this Matrix.true if this Matrix is inverted; returns false otherwise.public void mapPoints(float[] pts)
pts - Indicates the array of points to transform.public void mapPoints(float[] dst,
float[] src)
dst - Indicates the destination array for storing transformed points.src - Indicates the source array of points to transform.public void mapPoints(float[] dst,
int dstIndex,
float[] src,
int srcIndex,
int pointCount)
dst - Indicates the destination array for storing transformed points.dstIndex - Indicates the index of the first transformed point in the destination array.src - Indicates the source array of points to transform.srcIndex - Indicates the index of the first point to transform in the source array.pointCount - Indicates the number of points to transform.public boolean postConcat(Matrix otherMatrix)
Matrix by a specified matrix.otherMatrix - Indicates the specified matrix for post-multiplication.true if the operation is successful; returns false otherwise.public boolean postScale(float sx,
float sy)
Matrix with the specified scale.sx - Indicates the horizontal scale.sy - Indicates the vertical scale.true if the operation is successful; returns false otherwise.public boolean postScale(float sx,
float sy,
float px,
float py)
Matrix with the specified scale and the specified position of the perspective
point.sx - Indicates the horizontal scale.sy - Indicates the vertical scale.px - Indicates the X coordinate of the center point for scaling.py - Indicates the Y coordinate of the center point for scaling.true if the operation is successful; returns false otherwise.public boolean postTranslate(float dx,
float dy)
Matrix with the specified translation.dx - Indicates the horizontal length to translate.dy - Indicates the vertical length to translate.true if the operation is successful; returns false otherwise.public boolean preConcat(Matrix otherMatrix)
Matrix by a specified matrix.otherMatrix - Indicates the specified matrix for pre-multiplication.true if the operation is successful; returns false otherwise.public boolean preRotate(float degrees)
Matrix with the specified rotation.degrees - Indicates the number of degrees to rotate.true if the operation is successful; returns false otherwise.public boolean preRotate(float degrees,
float px,
float py)
Matrix with the specified rotation and the specified position of the perspective
point.degrees - Indicates the number of degrees to rotate.px - Indicates the X coordinate of the center point for rotation.py - Indicates the Y coordinate of the center point for rotation.true if the operation is successful; returns false otherwise.public void setScale(float sx,
float sy)
Matrix by the specified values.sx - Indicates the horizontal scale.sy - Indicates the vertical scale.public void setScale(float sx,
float sy,
float px,
float py)
Matrix by the specified values and the specified position of the perspective point.sx - Indicates the horizontal scale.sy - Indicates the vertical scale.px - Indicates the X coordinate of the center point for scaling.py - Indicates the Y coordinate of the center point for scaling.public boolean preTranslate(float dx,
float dy)
Matrix with the specified translation.dx - Indicates the horizontal length to translate.dy - Indicates the vertical length to translate.true if the operation is successful; returns false otherwise.public void setTranslate(float dx,
float dy)
Matrix with the specified values.dx - Indicates the horizontal length to translate.dy - Indicates the vertical length to translate.public boolean preScale(float sx,
float sy)
Matrix with the specified scale.sx - Indicates the horizontal scale.sy - Indicates the vertical scale.true if the operation is successful; returns false otherwise.public boolean preScale(float sx,
float sy,
float px,
float py)
Matrix with the specified scale and the specified position of the perspective point.sx - Indicates the horizontal scale.sy - Indicates the vertical scale.px - Indicates the X coordinate of the center point for scaling.py - Indicates the Y coordinate of the center point for scaling.true if the operation is successful; returns false otherwise.public boolean preSkew(float kx,
float ky)
Matrix with the specified skew.kx - Indicates the horizontal skew.ky - Indicates the vertical skew.true if the operation is successful; returns false otherwise.public float mapRadius(float radius)
Matrix.radius - Indicates the radius of the circle after being mapped.public boolean postRotate(float degrees,
float px,
float py)
Matrix with the specified rotation and the specified position of the perspective
point.degrees - Indicates the number of degrees to rotate.px - Indicates the X coordinate of the center point for rotation.py - Indicates the Y coordinate of the center point for rotation.true if the operation is successful; returns false otherwise.public boolean mapRect(RectFloat rectFloat)
rectFloat - Indicates the rectangle to transform.true if the operation is successful; returns false otherwise.public boolean mapRect(RectFloat dst, RectFloat src)
dst - Indicates the destination rectangle for storing the transformation result.src - Indicates the source rectangle to transform.true if the operation is successful; returns false otherwise.public boolean setRectToRect(RectFloat src, RectFloat dst, Matrix.ScaleToFit scaleToFit)
src - Indicates the source rectangle.dst - Indicates the destination rectanglescaleToFit - Indicates the scaling mode, as enumerated in ScaleToFit.true if the operation is successful; returns false otherwise.public void setSkew(float kx,
float ky)
Matrix by the specified skew factors.kx - Indicates the horizontal skew factor.ky - Indicates the vertical skew factor.public void setSkew(float kx,
float ky,
float px,
float py)
Matrix around a specified pivot by the specified skew factors.kx - Indicates the horizontal skew factor.ky - Indicates the vertical skew factor.px - Indicates the x coordinate of the skew pivot.py - Indicates the y coordinate of the skew pivot.public boolean setConcat(Matrix matrixA, Matrix matrixB)
Matrix to matrix A multiplied by matrix B.matrixA - Indicates matrix A.matrixB - Indicates matrix B.true if the operation is successful; returns false otherwise.public boolean postSkew(float kx,
float ky)
Matrix with the specified skew factors.kx - Indicates the horizontal skew factor.ky - Indicates the vertical skew factor.true if the operation is successful; returns false otherwise.public boolean postSkew(float kx,
float ky,
float px,
float py)
Matrix around a specified pivot by the specified skew factors.kx - Indicates the horizontal skew factor.ky - Indicates the vertical skew factor.px - Indicates the x coordinate of the skew pivot.py - Indicates the y coordinate of the skew pivot.true if the operation is successful; returns false otherwise.public boolean setPolyToPoly(float[] src,
int srcIndex,
float[] dst,
int dstIndex,
int pointCount)
Matrix to make the specified source points map to the specified destination points.src - Indicates the array of source points.srcIndex - Indicates the index of the first pair of points to be used in the source point array.dst - Indicates the array of destination points.dstIndex - Indicates the index of the first pair of points to be used in the destination point array.pointCount - Indicates the number of points.true if the operation is successful; returns false otherwise.public boolean rectStaysRect()
Matrix can map one rectangle to another. This method is equivalent to
preservesAxisAlignment().true if this Matrix can map one rectangle to another; returns false
otherwise.public boolean isScaleTranslate()
Matrix has been scaled and translated.true if scaling and translation have been performed; returns false otherwise.public boolean isTranslate()
Matrix has been translated.true if translation has been performed; returns false otherwise.public boolean preservesAxisAlignment()
Matrix can map one Rect object to another.
This method is equivalent to rectStaysRect().true if this Matrix can map one Rect object to another;
returns false otherwise.public boolean hasPerspective()
Matrix contains perspective elements.true if perspective elements are contained; returns false otherwise.public boolean isSimilarity()
Matrix contains only rotation, uniform scale, and translation.true if only rotation, uniform scale, and translation are contained;
returns false otherwise.public boolean preservesRightAngles()
Matrix contains only rotation, scale (non-uniform scale allowed), and translation.true if only rotation, scale (non-uniform scale allowed), and translation are contained;
returns false otherwise.public float get(int index)
index - Indicates the array index, ranging from 0 to 8.public float getScaleX()
Matrix.public float getScaleY()
Matrix.public float getSkewY()
Matrix.public float getSkewX()
Matrix.public float getTranslateX()
Matrix.public float getTranslateY()
Matrix.public float getPerspX()
Matrix.public float getPerspY()
Matrix.public void setScaleX(float v)
Matrix.v - Indicates the horizontal scale factor to set.public void setScaleY(float v)
Matrix.v - Indicates the vertical scale factor to set.public void setSkewX(float v)
Matrix.v - Indicates the horizontal skew factor to set.public void setSkewY(float v)
Matrix.v - Indicates the vertical skew factor to set.public void setTranslateX(float v)
Matrix.v - Indicates the horizontal translation factor to set.public void setTranslateY(float v)
Matrix.v - Indicates the vertical translation factor to set.public void setPerspX(float v)
Matrix.v - Indicates the horizontal perspective factor to set.public void setPerspY(float v)
Matrix.v - Indicates the vertical perspective factor to set.public void setSinCos(float sinValue,
float cosValue,
float px,
float py)
Matrix to rotate about the perspective point at the specified coordinates
by the given horizontal and vertical components of the rotation vector.sinValue - Indicates the horizontal component of the rotation vector.cosValue - Indicates the vertical component of the rotation vector.px - Indicates the x coordinate of the perspective point.py - Indicates the y coordinate of the perspective point.public void setSinCos(float sinValue,
float cosValue)
Matrix to rotate about the perspective point (0,0) by the specified horizontal
and vertical components of the rotation vector.sinValue - Indicates the horizontal component of the rotation vector.cosValue - Indicates the vertical component of the rotation vector.public void preSkew(float kx,
float ky,
float px,
float py)
Matrix with the specified skew and the specified position of the perspective point.kx - Indicates the horizontal skew factor.ky - Indicates the vertical skew factor.px - Indicates the x coordinate of the skew pivot.py - Indicates the y coordinate of the skew pivot.public boolean postIDiv(int divx,
int divy)
Matrix with the specified scale factors.divx - Indicates the reciprocal of the horizontal scale factor.divy - Indicates the reciprocal of the vertical scale factor.true if the operation is successful;
returns false if either divx or divy is 0.public void postRotate(float degrees)
Matrix with the specified rotation.degrees - Indicates the number of degrees to rotate.public void mapRectScaleTranslate(RectFloat dst, RectFloat src)
dst - Indicates the destination rectangle for storing the transformation result.src - Indicates the source rectangle to transform.public boolean isFixedStepInX()
true if the x-aix unit step can be represented by a constant vector,
that is, this Matrix does not have complex perspective; returns false otherwise.public boolean cheapEqualTo(Matrix matrixM)
Matrix and a specified matrix are represented by identical bit patterns.matrixM - Indicates the specified matrix to compare.true if this Matrix and the specified matrix have identical bit patterns;
returns false otherwise.public float getMinScale()
Matrix by decomposing the scaling and skewing elements.public float getMaxScale()
Matrix by decomposing the scaling and skewing elements.public void dirtyMatrixTypeCache()
public void setScaleTranslate(float sx,
float sy,
float tx,
float ty)
Matrix.sx - Indicates the horizontal scale factor to initialize.sy - Indicates the vertical scale factor to initialize.tx - Indicates the horizontal translation factor to initialize.ty - Indicates the vertical translation factor to initialize.public boolean isFinite()
Matrix are finite.true if all elements are finite; returns false otherwise.public boolean equals(Object object)
Matrix object equals the specified Matrix object.equals 在类中 Objectobject - Indicates the Matrix object to compare.true if the two objects are equal; returns false otherwise.Object.hashCode(),
HashMappublic int hashCode()
ObjectHashMap.
The general contract of hashCode is:
hashCode method
must consistently return the same integer, provided no information
used in equals comparisons on the object is modified.
This integer need not remain consistent from one execution of an
application to another execution of the same application.
equals(Object)
method, then calling the hashCode method on each of
the two objects must produce the same integer result.
Object.equals(java.lang.Object)
method, then calling the hashCode method on each of the
two objects must produce distinct integer results. However, the
programmer should be aware that producing distinct integer results
for unequal objects may improve the performance of hash tables.
As much as is reasonably practical, the hashCode method defined by
class Object does return distinct integers for distinct
objects. (This is typically implemented by converting the internal
address of the object into an integer, but this implementation
technique is not required by the
Java™ programming language.)
hashCode 在类中 ObjectObject.equals(java.lang.Object),
System.identityHashCode(java.lang.Object)