matrix

package
v0.0.12 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 9, 2025 License: BSD-3-Clause Imports: 3 Imported by: 2

Documentation

Overview

Package matrix provides 2D affine transformations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Transform

type Transform struct {
	A, B, C, D, E, F fl
}

Transform encode a (2D) linear transformation

The encoded transformation is given by :

x_new = a * x + c * y + e
y_new = b * x + d * y + f

which is equivalent to the vector notation Y = AX + B, with

A = | a c | ;  B = 	| e |
	| b	d |			| f |

Transformation may also be viewed as 3D matrices of the form T = | a c e |

| b d f |
| 0 0 1 |

and P = | x |

| y |
| 1 |

where | x_new | = T * P

| y_new |
|   1   |

func Identity

func Identity() Transform

Identity returns a new matrix initialized to the identity.

func Mul

func Mul(T, U Transform) Transform

Mul returns the transform T * U, which apply U then T.

func Mul3 added in v0.0.3

func Mul3(R, S, T Transform) Transform

Mul3 returns the transform R * S * T, which applies T, then S, then R.

func New

func New(a, b, c, d, e, f fl) Transform

func Rotation

func Rotation(radians fl) Transform

Rotation returns a rotation.

`radians` is the angle of rotation, in radians. The direction of rotation is defined such that positive angles rotate in the direction from the positive X axis toward the positive Y axis.

func Scaling

func Scaling(sx, sy fl) Transform

Scaling returns the scaling by (sx, sy).

func Skew

func Skew(thetax, thetay fl) Transform

Skew returns a skew transformation

func Translation

func Translation(tx, ty fl) Transform

Translation returns the translation by (tx, ty).

func (Transform) Apply added in v0.0.2

func (T Transform) Apply(x, y fl) (outX, outY fl)

Apply transforms the point `(x, y)` by this matrix, that is compute AX + B

func (Transform) Determinant

func (t Transform) Determinant() fl

Determinant returns the determinant of the matrix, which is non zero if and only if the transformation is reversible.

func (*Transform) Invert

func (T *Transform) Invert() error

Invert modify the matrix in place. Return an error if the transformation is not bijective.

func (*Transform) LeftMultBy added in v0.0.2

func (T *Transform) LeftMultBy(U Transform)

LeftMultBy update T in place with the result of U * T The resulting transformation apply T first, then U.

func (*Transform) RightMultBy added in v0.0.2

func (T *Transform) RightMultBy(U Transform)

RightMultBy update T in place with the result of T * U

func (*Transform) Rotate

func (T *Transform) Rotate(radians fl)

Applies a rotation by `radians` to the transformation in this matrix.

The effect of the new transformation is to first rotate the coordinates by `radians`, then apply the original transformation to the coordinates.

This is equivalent to computing T x Rotation(radians)

This changes the matrix in-place.

func (*Transform) Scale

func (T *Transform) Scale(sx, sy fl)

Applies scaling by `sx`, `sy` to the transformation in this matrix.

The effect of the new transformation is to first scale the coordinates by `sx` and `sy`, then apply the original transformation to the coordinates.

This is equivalent to computing T x Scaling(sx, sy).

This changes the matrix in-place.

func (*Transform) Skew

func (T *Transform) Skew(thetax, thetay fl)

Skew applies a skew transformation

The effect of the new transformation is to first skew the coordinates, then apply the original transformation to the coordinates.

This is equivalent to computing T x Skew(thetax, thetay)

func (*Transform) Translate

func (T *Transform) Translate(tx, ty fl)

Applies a translation by `tx`, `ty` to the transformation in this matrix.

The effect of the new transformation is to first translate the coordinates by `tx` and `ty`, then apply the original transformation to the coordinates.

This is equivalent to computing T x Translation(tx, ty)

This changes the matrix in-place.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL