Matrix
open class Matrix
kotlin.Any | |
↳ | android.graphics.Matrix |
The Matrix class holds a 3x3 matrix for transforming coordinates.
Summary
Nested classes | |
---|---|
Controls how the src rect should align into the dst rect for setRectToRect(). |
Constants | |
---|---|
static Int | |
static Int | |
static Int | |
static Int | |
static Int | |
static Int | |
static Int | |
static Int | |
static Int |
Public constructors | |
---|---|
Matrix() Create an identity matrix |
|
Create a matrix that is a (deep) copy of src |
Public methods | |
---|---|
Unit |
dump(pw: PrintWriter) Dumps a human-readable shortened string of the matrix into the given stream |
open Boolean |
Returns true iff obj is a Matrix and its values equal our values. |
open Unit |
getValues(values: FloatArray!) Copy 9 values from the matrix into the array. |
open Int |
hashCode() |
open Boolean |
If this matrix can be inverted, return true and if inverse is not null, set inverse to be the inverse of this matrix. |
open Boolean |
isAffine() Gets whether this matrix is affine. |
open Boolean |
Returns true if the matrix is identity. |
open Unit |
mapPoints(pts: FloatArray!) Apply this matrix to the array of 2D points, and write the transformed points back into the array |
open Unit |
mapPoints(dst: FloatArray!, src: FloatArray!) Apply this matrix to the array of 2D points specified by src, and write the transformed points into the array of points specified by dst. |
open Unit |
mapPoints(dst: FloatArray!, dstIndex: Int, src: FloatArray!, srcIndex: Int, pointCount: Int) Apply this matrix to the array of 2D points specified by src, and write the transformed points into the array of points specified by dst. |
open Float |
Return the mean radius of a circle after it has been mapped by this matrix. |
open Boolean |
Apply this matrix to the rectangle, and write the transformed rectangle back into it. |
open Boolean |
Apply this matrix to the src rectangle, and write the transformed rectangle into dst. |
open Unit |
mapVectors(vecs: FloatArray!) Apply this matrix to the array of 2D vectors, and write the transformed vectors back into the array. |
open Unit |
mapVectors(dst: FloatArray!, src: FloatArray!) Apply this matrix to the array of 2D vectors specified by src, and write the transformed vectors into the array of vectors specified by dst. |
open Unit |
mapVectors(dst: FloatArray!, dstIndex: Int, src: FloatArray!, srcIndex: Int, vectorCount: Int) Apply this matrix to the array of 2D vectors specified by src, and write the transformed vectors into the array of vectors specified by dst. |
open Boolean |
postConcat(other: Matrix!) Postconcats the matrix with the specified matrix. |
open Boolean |
postRotate(degrees: Float) Postconcats the matrix with the specified rotation. |
open Boolean |
postRotate(degrees: Float, px: Float, py: Float) Postconcats the matrix with the specified rotation. |
open Boolean |
Postconcats the matrix with the specified scale. |
open Boolean |
Postconcats the matrix with the specified scale. |
open Boolean |
Postconcats the matrix with the specified skew. |
open Boolean |
Postconcats the matrix with the specified skew. |
open Boolean |
postTranslate(dx: Float, dy: Float) Postconcats the matrix with the specified translation. |
open Boolean |
Preconcats the matrix with the specified matrix. |
open Boolean |
Preconcats the matrix with the specified rotation. |
open Boolean |
Preconcats the matrix with the specified rotation. |
open Boolean |
Preconcats the matrix with the specified scale. |
open Boolean |
Preconcats the matrix with the specified scale. |
open Boolean |
Preconcats the matrix with the specified skew. |
open Boolean |
Preconcats the matrix with the specified skew. |
open Boolean |
preTranslate(dx: Float, dy: Float) Preconcats the matrix with the specified translation. |
open Boolean |
Returns true if will map a rectangle to another rectangle. |
open Unit |
reset() Set the matrix to identity |
open Unit |
(deep) copy the src matrix into this matrix. |
open Boolean |
Set the matrix to the concatenation of the two specified matrices and return true. |
open Boolean |
setPolyToPoly(src: FloatArray!, srcIndex: Int, dst: FloatArray!, dstIndex: Int, pointCount: Int) Set the matrix such that the specified src points would map to the specified dst points. |
open Boolean |
setRectToRect(src: RectF!, dst: RectF!, stf: Matrix.ScaleToFit!) Set the matrix to the scale and translate values that map the source rectangle to the destination rectangle, returning true if the result can be represented. |
open Unit |
Set the matrix to rotate about (0,0) by the specified number of degrees. |
open Unit |
Set the matrix to rotate by the specified number of degrees, with a pivot point at (px, py). |
open Unit |
Set the matrix to scale by sx and sy. |
open Unit |
Set the matrix to scale by sx and sy, with a pivot point at (px, py). |
open Unit |
Set the matrix to rotate by the specified sine and cosine values. |
open Unit |
Set the matrix to rotate by the specified sine and cosine values, with a pivot point at (px, py). |
open Unit |
Set the matrix to skew by sx and sy. |
open Unit |
Set the matrix to skew by sx and sy, with a pivot point at (px, py). |
open Unit |
setTranslate(dx: Float, dy: Float) Set the matrix to translate by (dx, dy). |
open Unit |
setValues(values: FloatArray!) Copy 9 values from the array into the matrix. |
open String! | |
open String |
toString() |
Properties | |
---|---|
static Matrix |
The identity matrix. |
Constants
Public constructors
Matrix
Matrix(src: Matrix!)
Create a matrix that is a (deep) copy of src
Parameters | |
---|---|
src |
Matrix!: The matrix to copy into this matrix |
Public methods
dump
fun dump(pw: PrintWriter): Unit
Dumps a human-readable shortened string of the matrix into the given stream
Parameters | |
---|---|
pw |
PrintWriter: The PrintWriter into which the string representation of the matrix will be written. This value cannot be null . |
equals
open fun equals(other: Any?): Boolean
Returns true iff obj is a Matrix and its values equal our values.
Parameters | |
---|---|
obj |
the reference object with which to compare. |
Return | |
---|---|
Boolean |
true if this object is the same as the obj argument; false otherwise. |
getValues
open fun getValues(values: FloatArray!): Unit
Copy 9 values from the matrix into the array.
hashCode
open fun hashCode(): Int
Return | |
---|---|
Int |
a hash code value for this object. |
invert
open fun invert(inverse: Matrix!): Boolean
If this matrix can be inverted, return true and if inverse is not null, set inverse to be the inverse of this matrix. If this matrix cannot be inverted, ignore inverse and return false.
isAffine
open fun isAffine(): Boolean
Gets whether this matrix is affine. An affine matrix preserves straight lines and has no perspective.
Return | |
---|---|
Boolean |
Whether the matrix is affine. |
isIdentity
open fun isIdentity(): Boolean
Returns true if the matrix is identity. This maybe faster than testing if (getType() == 0)
mapPoints
open fun mapPoints(pts: FloatArray!): Unit
Apply this matrix to the array of 2D points, and write the transformed points back into the array
Parameters | |
---|---|
pts |
FloatArray!: The array [x0, y0, x1, y1, ...] of points to transform. |
mapPoints
open fun mapPoints(
dst: FloatArray!,
src: FloatArray!
): Unit
Apply this matrix to the array of 2D points specified by src, and write the transformed points into the array of points specified by dst. The two arrays represent their "points" as pairs of floats [x, y].
Parameters | |
---|---|
dst |
FloatArray!: The array of dst points (x,y pairs) |
src |
FloatArray!: The array of src points (x,y pairs) |
mapPoints
open fun mapPoints(
dst: FloatArray!,
dstIndex: Int,
src: FloatArray!,
srcIndex: Int,
pointCount: Int
): Unit
Apply this matrix to the array of 2D points specified by src, and write the transformed points into the array of points specified by dst. The two arrays represent their "points" as pairs of floats [x, y].
Parameters | |
---|---|
dst |
FloatArray!: The array of dst points (x,y pairs) |
dstIndex |
Int: The index of the first [x,y] pair of dst floats |
src |
FloatArray!: The array of src points (x,y pairs) |
srcIndex |
Int: The index of the first [x,y] pair of src floats |
pointCount |
Int: The number of points (x,y pairs) to transform |
mapRadius
open fun mapRadius(radius: Float): Float
Return the mean radius of a circle after it has been mapped by this matrix. NOTE: in perspective this value assumes the circle has its center at the origin.
mapRect
open fun mapRect(rect: RectF!): Boolean
Apply this matrix to the rectangle, and write the transformed rectangle back into it. This is accomplished by transforming the 4 corners of rect, and then setting it to the bounds of those points
Parameters | |
---|---|
rect |
RectF!: The rectangle to transform. |
Return | |
---|---|
Boolean |
the result of calling rectStaysRect() |
mapRect
open fun mapRect(
dst: RectF!,
src: RectF!
): Boolean
Apply this matrix to the src rectangle, and write the transformed rectangle into dst. This is accomplished by transforming the 4 corners of src, and then setting dst to the bounds of those points.
Parameters | |
---|---|
dst |
RectF!: Where the transformed rectangle is written. |
src |
RectF!: The original rectangle to be transformed. |
Return | |
---|---|
Boolean |
the result of calling rectStaysRect() |
mapVectors
open fun mapVectors(vecs: FloatArray!): Unit
Apply this matrix to the array of 2D vectors, and write the transformed vectors back into the array. Note: this method does not apply the translation associated with the matrix. Use Matrix.mapPoints(float[])
if you want the translation to be applied.
Parameters | |
---|---|
vecs |
FloatArray!: The array [x0, y0, x1, y1, ...] of vectors to transform. |
mapVectors
open fun mapVectors(
dst: FloatArray!,
src: FloatArray!
): Unit
Apply this matrix to the array of 2D vectors specified by src, and write the transformed vectors into the array of vectors specified by dst. The two arrays represent their "vectors" as pairs of floats [x, y]. Note: this method does not apply the translation associated with the matrix. Use Matrix.mapPoints(float[], float[])
if you want the translation to be applied.
Parameters | |
---|---|
dst |
FloatArray!: The array of dst vectors (x,y pairs) |
src |
FloatArray!: The array of src vectors (x,y pairs) |
mapVectors
open fun mapVectors(
dst: FloatArray!,
dstIndex: Int,
src: FloatArray!,
srcIndex: Int,
vectorCount: Int
): Unit
Apply this matrix to the array of 2D vectors specified by src, and write the transformed vectors into the array of vectors specified by dst. The two arrays represent their "vectors" as pairs of floats [x, y]. Note: this method does not apply the translation associated with the matrix. Use Matrix.mapPoints(float[], int, float[], int, int)
if you want the translation to be applied.
Parameters | |
---|---|
dst |
FloatArray!: The array of dst vectors (x,y pairs) |
dstIndex |
Int: The index of the first [x,y] pair of dst floats |
src |
FloatArray!: The array of src vectors (x,y pairs) |
srcIndex |
Int: The index of the first [x,y] pair of src floats |
vectorCount |
Int: The number of vectors (x,y pairs) to transform |
postConcat
open fun postConcat(other: Matrix!): Boolean
Postconcats the matrix with the specified matrix. M' = other * M
postRotate
open fun postRotate(degrees: Float): Boolean
Postconcats the matrix with the specified rotation. M' = R(degrees) * M
postRotate
open fun postRotate(
degrees: Float,
px: Float,
py: Float
): Boolean
Postconcats the matrix with the specified rotation. M' = R(degrees, px, py) * M
postScale
open fun postScale(
sx: Float,
sy: Float
): Boolean
Postconcats the matrix with the specified scale. M' = S(sx, sy) * M
postScale
open fun postScale(
sx: Float,
sy: Float,
px: Float,
py: Float
): Boolean
Postconcats the matrix with the specified scale. M' = S(sx, sy, px, py) * M
postSkew
open fun postSkew(
kx: Float,
ky: Float
): Boolean
Postconcats the matrix with the specified skew. M' = K(kx, ky) * M
postSkew
open fun postSkew(
kx: Float,
ky: Float,
px: Float,
py: Float
): Boolean
Postconcats the matrix with the specified skew. M' = K(kx, ky, px, py) * M
postTranslate
open fun postTranslate(
dx: Float,
dy: Float
): Boolean
Postconcats the matrix with the specified translation. M' = T(dx, dy) * M
preConcat
open fun preConcat(other: Matrix!): Boolean
Preconcats the matrix with the specified matrix. M' = M * other
preRotate
open fun preRotate(degrees: Float): Boolean
Preconcats the matrix with the specified rotation. M' = M * R(degrees)
preRotate
open fun preRotate(
degrees: Float,
px: Float,
py: Float
): Boolean
Preconcats the matrix with the specified rotation. M' = M * R(degrees, px, py)
preScale
open fun preScale(
sx: Float,
sy: Float
): Boolean
Preconcats the matrix with the specified scale. M' = M * S(sx, sy)
preScale
open fun preScale(
sx: Float,
sy: Float,
px: Float,
py: Float
): Boolean
Preconcats the matrix with the specified scale. M' = M * S(sx, sy, px, py)
preSkew
open fun preSkew(
kx: Float,
ky: Float
): Boolean
Preconcats the matrix with the specified skew. M' = M * K(kx, ky)
preSkew
open fun preSkew(
kx: Float,
ky: Float,
px: Float,
py: Float
): Boolean
Preconcats the matrix with the specified skew. M' = M * K(kx, ky, px, py)
preTranslate
open fun preTranslate(
dx: Float,
dy: Float
): Boolean
Preconcats the matrix with the specified translation. M' = M * T(dx, dy)
rectStaysRect
open fun rectStaysRect(): Boolean
Returns true if will map a rectangle to another rectangle. This can be true if the matrix is identity, scale-only, or rotates a multiple of 90 degrees.
set
open fun set(src: Matrix!): Unit
(deep) copy the src matrix into this matrix. If src is null, reset this matrix to the identity matrix.
setConcat
open fun setConcat(
a: Matrix!,
b: Matrix!
): Boolean
Set the matrix to the concatenation of the two specified matrices and return true.
Either of the two matrices may also be the target matrix, that is matrixA.setConcat(matrixA, matrixB);
is valid.
In android.os.Build.VERSION_CODES#GINGERBREAD_MR1
and below, this function returns true only if the result can be represented. In android.os.Build.VERSION_CODES#HONEYCOMB
and above, it always returns true.
setPolyToPoly
open fun setPolyToPoly(
src: FloatArray!,
srcIndex: Int,
dst: FloatArray!,
dstIndex: Int,
pointCount: Int
): Boolean
Set the matrix such that the specified src points would map to the specified dst points. The "points" are represented as an array of floats, order [x0, y0, x1, y1, ...], where each "point" is 2 float values.
Parameters | |
---|---|
src |
FloatArray!: The array of src [x,y] pairs (points) |
srcIndex |
Int: Index of the first pair of src values |
dst |
FloatArray!: The array of dst [x,y] pairs (points) |
dstIndex |
Int: Index of the first pair of dst values |
pointCount |
Int: The number of pairs/points to be used. Must be [0..4] |
Return | |
---|---|
Boolean |
true if the matrix was set to the specified transformation |
setRectToRect
open fun setRectToRect(
src: RectF!,
dst: RectF!,
stf: Matrix.ScaleToFit!
): Boolean
Set the matrix to the scale and translate values that map the source rectangle to the destination rectangle, returning true if the result can be represented.
Parameters | |
---|---|
src |
RectF!: the source rectangle to map from. |
dst |
RectF!: the destination rectangle to map to. |
stf |
Matrix.ScaleToFit!: the ScaleToFit option |
Return | |
---|---|
Boolean |
true if the matrix can be represented by the rectangle mapping. |
setRotate
open fun setRotate(degrees: Float): Unit
Set the matrix to rotate about (0,0) by the specified number of degrees.
setRotate
open fun setRotate(
degrees: Float,
px: Float,
py: Float
): Unit
Set the matrix to rotate by the specified number of degrees, with a pivot point at (px, py). The pivot point is the coordinate that should remain unchanged by the specified transformation.
setScale
open fun setScale(
sx: Float,
sy: Float
): Unit
Set the matrix to scale by sx and sy.
setScale
open fun setScale(
sx: Float,
sy: Float,
px: Float,
py: Float
): Unit
Set the matrix to scale by sx and sy, with a pivot point at (px, py). The pivot point is the coordinate that should remain unchanged by the specified transformation.
setSinCos
open fun setSinCos(
sinValue: Float,
cosValue: Float
): Unit
Set the matrix to rotate by the specified sine and cosine values.
setSinCos
open fun setSinCos(
sinValue: Float,
cosValue: Float,
px: Float,
py: Float
): Unit
Set the matrix to rotate by the specified sine and cosine values, with a pivot point at (px, py). The pivot point is the coordinate that should remain unchanged by the specified transformation.
setSkew
open fun setSkew(
kx: Float,
ky: Float
): Unit
Set the matrix to skew by sx and sy.
setSkew
open fun setSkew(
kx: Float,
ky: Float,
px: Float,
py: Float
): Unit
Set the matrix to skew by sx and sy, with a pivot point at (px, py). The pivot point is the coordinate that should remain unchanged by the specified transformation.
setTranslate
open fun setTranslate(
dx: Float,
dy: Float
): Unit
Set the matrix to translate by (dx, dy).
setValues
open fun setValues(values: FloatArray!): Unit
Copy 9 values from the array into the matrix. Depending on the implementation of Matrix, these may be transformed into 16.16 integers in the Matrix, such that a subsequent call to getValues() will not yield exactly the same values.
toString
open fun toString(): String
Return | |
---|---|
String |
a string representation of the object. |
Properties
IDENTITY_MATRIX
static val IDENTITY_MATRIX: Matrix
The identity matrix. Multiplying by another matrix M
returns M
. This matrix is immutable, and attempting to modify it will throw an IllegalStateException
.