Class

Matrix

Source set: Common
public class Matrix(
    public val values: FloatArray =
        floatArrayOf(1f, 0f, 0f, 0f, 0f, 1f, 0f, 0f, 0f, 0f, 1f, 0f, 0f, 0f, 0f, 1f)
)

Functions

get

Source set: Common
public inline operator fun get(row: Int, column: Int): Float

set

Source set: Common
public inline operator fun set(row: Int, column: Int, v: Float)

map

Source set: Common
public fun map(point: Offset): Offset

Does the 3D transform on point and returns the x and y values in an Offset.

map

Source set: Common
public fun map(rect: Rect): Rect

Does a 3D transform on rect and returns its bounds after the transform.

map

Source set: Common
public fun map(rect: MutableRect)

Does a 3D transform on rect, transforming rect with the results.

timesAssign

Source set: Common
public operator fun timesAssign(m: Matrix)

Multiply this matrix by m and assign the result to this matrix.

toString

Source set: Common
override fun toString(): String

invert

Source set: Common
public fun invert()

Invert this Matrix.

reset

Source set: Common
public fun reset()

Resets the this to the identity matrix.

setFrom

Source set: Common
public fun setFrom(matrix: Matrix)

Sets the entire matrix to the matrix in matrix.

rotateX

Source set: Common
public fun rotateX(degrees: Float)

Applies a degrees rotation around X to this.

rotateY

Source set: Common
public fun rotateY(degrees: Float)

Applies a degrees rotation around Y to this.

rotateZ

Source set: Common
public fun rotateZ(degrees: Float)

Applies a degrees rotation around Z to this.

scale

Source set: Common
public fun scale(x: Float = 1f, y: Float = 1f, z: Float = 1f)

Scale this matrix by x, y, z

translate

Source set: Common
public fun translate(x: Float = 0f, y: Float = 0f, z: Float = 0f)

Translate this matrix by x, y, z

resetToPivotedTransform

Source set: Common
public fun resetToPivotedTransform(
        pivotX: Float = 0f,
        pivotY: Float = 0f,
        translationX: Float = 0f,
        translationY: Float = 0f,
        translationZ: Float = 0f,
        rotationX: Float = 0f,
        rotationY: Float = 0f,
        rotationZ: Float = 0f,
        scaleX: Float = 1f,
        scaleY: Float = 1f,
        scaleZ: Float = 1f,
    )

Resets this matrix to a "TRS" (translation, rotation, scale) transform around a pivot point. The transform operations encoded in the matrix are the following, in this specific order:

  • A translation by -pivotX, -pivotY
  • A translation by translationX, translationY, and translationZ
  • An X rotation by rotationX
  • A Y rotation by rotationY
  • A Z rotation by rotationZ
  • A scale by scaleX and scaleY
  • A translation by pivotX, pivotY

Calling this method is equivalent to the following code:

val m: Matrix ...
m.reset()
m.translate(-pivotX, -pivotY)
m *= Matrix().apply {
translate(translationX, translationY)
rotateX(rotationX)
rotateY(rotationY)
rotateZ(rotationZ)
scale(scaleX, scaleY)
}
m *= Matrix().apply { translate(pivotX, pivotY) }

Members

Companion

Source set: Common
public companion object

Properties

ScaleX

Source set: Common
public const val ScaleX: Int = 0

Index of the flattened array that represents the scale factor along the X axis

SkewY

Source set: Common
public const val SkewY: Int = 1

Index of the flattened array that represents the skew factor along the Y axis

Perspective0

Source set: Common
public const val Perspective0: Int = 3

Index of the flattened array that represents the perspective factor along the X axis

SkewX

Source set: Common
public const val SkewX: Int = 4

Index of the flattened array that represents the skew factor along the X axis

ScaleY

Source set: Common
public const val ScaleY: Int = 5

Index of the flattened array that represents the scale factor along the Y axis

Perspective1

Source set: Common
public const val Perspective1: Int = 7

Index of the flattened array that represents the perspective factor along the Y axis

ScaleZ

Source set: Common
public const val ScaleZ: Int = 10

Index of the flattened array that represents the scale factor along the Z axis

TranslateX

Source set: Common
public const val TranslateX: Int = 12

Index of the flattened array that represents the translation along the X axis

TranslateY

Source set: Common
public const val TranslateY: Int = 13

Index of the flattened array that represents the translation along the Y axis

TranslateZ

Source set: Common
public const val TranslateZ: Int = 14

Index of the flattened array that represents the translation along the Z axis

Perspective2

Source set: Common
public const val Perspective2: Int = 15

Index of the flattened array that represents the perspective factor along the Z axis

Jetpack Compose beyond MaterialFree components, screens and templates for apps that don’t look like Google’s. Copy them into your app, or let your coding agent add them.Browse for free

Content updated: