mat2

package
v0.0.0-...-1137f6a Latest Latest
Warning

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

Go to latest
Published: May 2, 2024 License: MIT Imports: 5 Imported by: 12

Documentation

Overview

Package mat2 contains a 2x2 float64 matrix type T and functions.

Index

Constants

This section is empty.

Variables

View Source
var (
	// Zero holds a zero matrix.
	Zero = T{
		vec2.T{0, 0},
		vec2.T{0, 0},
	}

	// Ident holds an ident matrix.
	Ident = T{
		vec2.T{1, 0},
		vec2.T{0, 1},
	}
)

Functions

This section is empty.

Types

type T

type T [2]vec2.T

T represents a 2x2 matrix.

func From

func From(other generic.T) T

From copies a T from a generic.T implementation.

func Parse

func Parse(s string) (r T, err error)

Parse parses T from a string. See also String()

func (*T) Array

func (mat *T) Array() *[4]float64

Array returns the elements of the matrix as array pointer. The data may be a copy depending on the platform implementation.

func (*T) AssignMul

func (mat *T) AssignMul(a, b *T) *T

AssignMul multiplies a and b and assigns the result to mat.

func (*T) Cols

func (mat *T) Cols() int

Cols returns the number of columns of the matrix.

func (*T) Determinant

func (mat *T) Determinant() float64

func (*T) Get

func (mat *T) Get(col, row int) float64

Get returns one element of the matrix. Matrices are defined by (two) column vectors.

Note that this function use the opposite reference order of rows and columns to the mathematical matrix indexing.

A value in this matrix is referenced by <col><row> where both row and column is in the range [0..1]. This notation and range reflects the underlying representation.

A value in a matrix A is mathematically referenced by A<row><col> where both row and column is in the range [1..2]. (It is really the lower case 'a' followed by <row><col> but this documentation syntax is somewhat limited.)

matrixA.Get(0, 1) == matrixA[0][1] ( == A21 in mathematical indexing)

func (*T) Invert

func (mat *T) Invert() (*T, error)

Invert inverts the given matrix. Destructive operation. Does not check if matrix is singular and may lead to strange results!

func (*T) Inverted

func (mat *T) Inverted() (T, error)

Inverted inverts a copy of the given matrix. Does not check if matrix is singular and may lead to strange results!

func (*T) IsZero

func (mat *T) IsZero() bool

IsZero checks if all elements of the matrix are zero.

func (*T) MulVec2

func (mat *T) MulVec2(vec *vec2.T) vec2.T

MulVec2 multiplies vec with mat.

func (*T) PracticallyEquals

func (mat *T) PracticallyEquals(matrix *T, allowedDelta float64) bool

PracticallyEquals compares two matrices if they are equal with each other within a delta tolerance.

func (*T) Rows

func (mat *T) Rows() int

Rows returns the number of rows of the matrix.

func (*T) Scale

func (mat *T) Scale(f float64) *T

Scale multiplies the diagonal scale elements by f returns mat.

func (*T) Scaled

func (mat *T) Scaled(f float64) T

Scaled returns a copy of the matrix with the diagonal scale elements multiplied by f.

func (*T) Scaling

func (mat *T) Scaling() vec2.T

Scaling returns the scaling diagonal of the matrix.

func (*T) SetScaling

func (mat *T) SetScaling(s *vec2.T) *T

SetScaling sets the scaling diagonal of the matrix.

func (*T) Size

func (mat *T) Size() int

Size returns the number elements of the matrix.

func (*T) Slice

func (mat *T) Slice() []float64

Slice returns the elements of the matrix as slice. The data may be a copy depending on the platform implementation.

func (*T) String

func (mat *T) String() string

String formats T as string. See also Parse().

func (*T) Trace

func (mat *T) Trace() float64

Trace returns the trace value for the matrix.

func (*T) TransformVec2

func (mat *T) TransformVec2(v *vec2.T)

TransformVec2 multiplies v with mat and saves the result in v.

func (*T) Transpose

func (mat *T) Transpose() *T

Transpose transposes the matrix.

func (*T) Transposed

func (mat *T) Transposed() T

Transposed returns a transposed copy the matrix.

Jump to

Keyboard shortcuts

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