Documentation
¶
Overview ¶
Package matrix provides 2D affine transformations.
Index ¶
- type Transform
- func (T Transform) Apply(x, y fl) (outX, outY fl)
- func (t Transform) Determinant() fl
- func (T *Transform) Invert() error
- func (T *Transform) LeftMultBy(U Transform)
- func (T *Transform) RightMultBy(U Transform)
- func (T *Transform) Rotate(radians fl)
- func (T *Transform) Scale(sx, sy fl)
- func (T *Transform) Skew(thetax, thetay fl)
- func (T *Transform) Translate(tx, ty fl)
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 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 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 ¶
Invert modify the matrix in place. Return an error if the transformation is not bijective.
func (*Transform) LeftMultBy ¶ added in v0.0.2
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
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.