## Documentation ¶

### Overview ¶

Package mgl[32|64] (an abbreviation of mathgl since the packages were split between 32 and 64-bit versions) is a pure Go math package specialized for 3D math, with inspiration from GLM. It provides statically-sized vectors and matrices with compile-time generated calculations for most basic math operations. It also provides several basic graphics utilities such as bezier curves and surfaces, generation of basic primitives like circles, easy creation of common matrices such as perspective or rotation, and common operations like converting to/from screen/OpenGL coordinates or Projecting/Unprojecting from an MVP matrix. Quaternions are also supported.

The basic vectors and matrices are written with code generation, so looking directly at the source will probably be a bit confusing. I recommend looking at the Godoc instead, as all basic functions are documented.

This package is written in Column Major Order to make it easier with OpenGL. This means for uniform blocks you can use the default ordering, and when you call pass-in functions you can leave the "transpose" argument as false.

The package now contains variable sized vectors and matrices. Using these is discouraged. They exist for corner cases where you need "small" matrices that are still bigger than 4x4. An example may be a Jacobean used for inverse kinematics. Things like computer vision or general linear algebra are best left to packages more directly suited for that task -- OpenCV, BLAS, LAPACK, numpy, gonum (if you want to stay in Go), and so on.

### Index ¶

- Variables
- func Abs(a float32) float32
- func CartesianToCylindical(coord Vec3) (rho, phi, z float32)
- func CartesianToSpherical(coord Vec3) (r, theta, phi float32)
- func Clamp(a, low, high float32) float32
- func ClampFunc(low, high float32) func(float32) float32
- func CopyMatMN(dst, src *MatMxN)
- func CylindircalToSpherical(rho, phi, z float32) (r, theta, phi2 float32)
- func DegToRad(angle float32) float32
- func DisableMemoryPooling()
- func Extract3DScale(m Mat4) (x, y, z float32)
- func ExtractMaxScale(m Mat4) float32
- func FloatEqual(a, b float32) bool
- func FloatEqualFunc(epsilon float32) func(float32, float32) bool
- func FloatEqualThreshold(a, b, epsilon float32) bool
- func GLToScreenCoords(x, y float32, screenWidth, screenHeight int) (xOut, yOut int)
- func IsClamped(a, low, high float32) bool
- func RadToDeg(angle float32) float32
- func ReticulateSplines(ranges [][][2]float32, cPoints [][][]Vec2, withLlamas bool)
- func Round(v float32, precision int) float32
- func ScreenToGLCoords(x, y int, screenWidth, screenHeight int) (xOut, yOut float32)
- func SetMax(a, b *float32)
- func SetMin(a, b *float32)
- func SphericalToCylindrical(r, theta, phi float32) (rho, phi2, z float32)
- type InferMatrixError
- type Mat2
- func (m Mat2) Abs() Mat2
- func (m1 Mat2) Add(m2 Mat2) Mat2
- func (m1 Mat2) ApproxEqual(m2 Mat2) bool
- func (m1 Mat2) ApproxEqualThreshold(m2 Mat2, threshold float32) bool
- func (m1 Mat2) ApproxFuncEqual(m2 Mat2, eq func(float32, float32) bool) bool
- func (m Mat2) At(row, col int) float32
- func (m Mat2) Col(col int) Vec2
- func (m Mat2) Cols() (col0, col1 Vec2)
- func (m Mat2) Det() float32
- func (m Mat2) Diag() Vec2
- func (m Mat2) Index(row, col int) int
- func (m Mat2) Inv() Mat2
- func (m Mat2) Mat3() Mat3
- func (m Mat2) Mat4() Mat4
- func (m1 Mat2) Mul(c float32) Mat2
- func (m1 Mat2) Mul2(m2 Mat2) Mat2
- func (m1 Mat2) Mul2x1(m2 Vec2) Vec2
- func (m1 Mat2) Mul2x3(m2 Mat2x3) Mat2x3
- func (m1 Mat2) Mul2x4(m2 Mat2x4) Mat2x4
- func (m Mat2) Row(row int) Vec2
- func (m Mat2) Rows() (row0, row1 Vec2)
- func (m *Mat2) Set(row, col int, value float32)
- func (m *Mat2) SetCol(col int, v Vec2)
- func (m *Mat2) SetRow(row int, v Vec2)
- func (m Mat2) String() string
- func (m1 Mat2) Sub(m2 Mat2) Mat2
- func (m Mat2) Trace() float32
- func (m1 Mat2) Transpose() Mat2

- type Mat2x3
- func (m Mat2x3) Abs() Mat2x3
- func (m1 Mat2x3) Add(m2 Mat2x3) Mat2x3
- func (m1 Mat2x3) ApproxEqual(m2 Mat2x3) bool
- func (m1 Mat2x3) ApproxEqualThreshold(m2 Mat2x3, threshold float32) bool
- func (m1 Mat2x3) ApproxFuncEqual(m2 Mat2x3, eq func(float32, float32) bool) bool
- func (m Mat2x3) At(row, col int) float32
- func (m Mat2x3) Col(col int) Vec2
- func (m Mat2x3) Cols() (col0, col1, col2 Vec2)
- func (m Mat2x3) Index(row, col int) int
- func (m1 Mat2x3) Mul(c float32) Mat2x3
- func (m1 Mat2x3) Mul3(m2 Mat3) Mat2x3
- func (m1 Mat2x3) Mul3x1(m2 Vec3) Vec2
- func (m1 Mat2x3) Mul3x2(m2 Mat3x2) Mat2
- func (m1 Mat2x3) Mul3x4(m2 Mat3x4) Mat2x4
- func (m Mat2x3) Row(row int) Vec3
- func (m Mat2x3) Rows() (row0, row1 Vec3)
- func (m *Mat2x3) Set(row, col int, value float32)
- func (m *Mat2x3) SetCol(col int, v Vec2)
- func (m *Mat2x3) SetRow(row int, v Vec3)
- func (m Mat2x3) String() string
- func (m1 Mat2x3) Sub(m2 Mat2x3) Mat2x3
- func (m1 Mat2x3) Transpose() Mat3x2

- type Mat2x4
- func (m Mat2x4) Abs() Mat2x4
- func (m1 Mat2x4) Add(m2 Mat2x4) Mat2x4
- func (m1 Mat2x4) ApproxEqual(m2 Mat2x4) bool
- func (m1 Mat2x4) ApproxEqualThreshold(m2 Mat2x4, threshold float32) bool
- func (m1 Mat2x4) ApproxFuncEqual(m2 Mat2x4, eq func(float32, float32) bool) bool
- func (m Mat2x4) At(row, col int) float32
- func (m Mat2x4) Col(col int) Vec2
- func (m Mat2x4) Cols() (col0, col1, col2, col3 Vec2)
- func (m Mat2x4) Index(row, col int) int
- func (m1 Mat2x4) Mul(c float32) Mat2x4
- func (m1 Mat2x4) Mul4(m2 Mat4) Mat2x4
- func (m1 Mat2x4) Mul4x1(m2 Vec4) Vec2
- func (m1 Mat2x4) Mul4x2(m2 Mat4x2) Mat2
- func (m1 Mat2x4) Mul4x3(m2 Mat4x3) Mat2x3
- func (m Mat2x4) Row(row int) Vec4
- func (m Mat2x4) Rows() (row0, row1 Vec4)
- func (m *Mat2x4) Set(row, col int, value float32)
- func (m *Mat2x4) SetCol(col int, v Vec2)
- func (m *Mat2x4) SetRow(row int, v Vec4)
- func (m Mat2x4) String() string
- func (m1 Mat2x4) Sub(m2 Mat2x4) Mat2x4
- func (m1 Mat2x4) Transpose() Mat4x2

- type Mat3
- func Diag3(v Vec3) Mat3
- func HomogRotate2D(angle float32) Mat3
- func Ident3() Mat3
- func Mat3FromCols(col0, col1, col2 Vec3) Mat3
- func Mat3FromRows(row0, row1, row2 Vec3) Mat3
- func Mat4Normal(m Mat4) Mat3
- func Rotate3DX(angle float32) Mat3
- func Rotate3DY(angle float32) Mat3
- func Rotate3DZ(angle float32) Mat3
- func Scale2D(scaleX, scaleY float32) Mat3
- func ShearX2D(shear float32) Mat3
- func ShearY2D(shear float32) Mat3
- func Translate2D(Tx, Ty float32) Mat3

- func (m Mat3) Abs() Mat3
- func (m1 Mat3) Add(m2 Mat3) Mat3
- func (m1 Mat3) ApproxEqual(m2 Mat3) bool
- func (m1 Mat3) ApproxEqualThreshold(m2 Mat3, threshold float32) bool
- func (m1 Mat3) ApproxFuncEqual(m2 Mat3, eq func(float32, float32) bool) bool
- func (m Mat3) At(row, col int) float32
- func (m Mat3) Col(col int) Vec3
- func (m Mat3) Cols() (col0, col1, col2 Vec3)
- func (m Mat3) Det() float32
- func (m Mat3) Diag() Vec3
- func (m Mat3) Index(row, col int) int
- func (m Mat3) Inv() Mat3
- func (m Mat3) Mat2() Mat2
- func (m Mat3) Mat4() Mat4
- func (m1 Mat3) Mul(c float32) Mat3
- func (m1 Mat3) Mul3(m2 Mat3) Mat3
- func (m1 Mat3) Mul3x1(m2 Vec3) Vec3
- func (m1 Mat3) Mul3x2(m2 Mat3x2) Mat3x2
- func (m1 Mat3) Mul3x4(m2 Mat3x4) Mat3x4
- func (m Mat3) Row(row int) Vec3
- func (m Mat3) Rows() (row0, row1, row2 Vec3)
- func (m *Mat3) Set(row, col int, value float32)
- func (m *Mat3) SetCol(col int, v Vec3)
- func (m *Mat3) SetRow(row int, v Vec3)
- func (m Mat3) String() string
- func (m1 Mat3) Sub(m2 Mat3) Mat3
- func (m Mat3) Trace() float32
- func (m1 Mat3) Transpose() Mat3

- type Mat3x2
- func (m Mat3x2) Abs() Mat3x2
- func (m1 Mat3x2) Add(m2 Mat3x2) Mat3x2
- func (m1 Mat3x2) ApproxEqual(m2 Mat3x2) bool
- func (m1 Mat3x2) ApproxEqualThreshold(m2 Mat3x2, threshold float32) bool
- func (m1 Mat3x2) ApproxFuncEqual(m2 Mat3x2, eq func(float32, float32) bool) bool
- func (m Mat3x2) At(row, col int) float32
- func (m Mat3x2) Col(col int) Vec3
- func (m Mat3x2) Cols() (col0, col1 Vec3)
- func (m Mat3x2) Index(row, col int) int
- func (m1 Mat3x2) Mul(c float32) Mat3x2
- func (m1 Mat3x2) Mul2(m2 Mat2) Mat3x2
- func (m1 Mat3x2) Mul2x1(m2 Vec2) Vec3
- func (m1 Mat3x2) Mul2x3(m2 Mat2x3) Mat3
- func (m1 Mat3x2) Mul2x4(m2 Mat2x4) Mat3x4
- func (m Mat3x2) Row(row int) Vec2
- func (m Mat3x2) Rows() (row0, row1, row2 Vec2)
- func (m *Mat3x2) Set(row, col int, value float32)
- func (m *Mat3x2) SetCol(col int, v Vec3)
- func (m *Mat3x2) SetRow(row int, v Vec2)
- func (m Mat3x2) String() string
- func (m1 Mat3x2) Sub(m2 Mat3x2) Mat3x2
- func (m1 Mat3x2) Transpose() Mat2x3

- type Mat3x4
- func (m Mat3x4) Abs() Mat3x4
- func (m1 Mat3x4) Add(m2 Mat3x4) Mat3x4
- func (m1 Mat3x4) ApproxEqual(m2 Mat3x4) bool
- func (m1 Mat3x4) ApproxEqualThreshold(m2 Mat3x4, threshold float32) bool
- func (m1 Mat3x4) ApproxFuncEqual(m2 Mat3x4, eq func(float32, float32) bool) bool
- func (m Mat3x4) At(row, col int) float32
- func (m Mat3x4) Col(col int) Vec3
- func (m Mat3x4) Cols() (col0, col1, col2, col3 Vec3)
- func (m Mat3x4) Index(row, col int) int
- func (m1 Mat3x4) Mul(c float32) Mat3x4
- func (m1 Mat3x4) Mul4(m2 Mat4) Mat3x4
- func (m1 Mat3x4) Mul4x1(m2 Vec4) Vec3
- func (m1 Mat3x4) Mul4x2(m2 Mat4x2) Mat3x2
- func (m1 Mat3x4) Mul4x3(m2 Mat4x3) Mat3
- func (m Mat3x4) Row(row int) Vec4
- func (m Mat3x4) Rows() (row0, row1, row2 Vec4)
- func (m *Mat3x4) Set(row, col int, value float32)
- func (m *Mat3x4) SetCol(col int, v Vec3)
- func (m *Mat3x4) SetRow(row int, v Vec4)
- func (m Mat3x4) String() string
- func (m1 Mat3x4) Sub(m2 Mat3x4) Mat3x4
- func (m1 Mat3x4) Transpose() Mat4x3

- type Mat4
- func Diag4(v Vec4) Mat4
- func Frustum(left, right, bottom, top, near, far float32) Mat4
- func HomogRotate3D(angle float32, axis Vec3) Mat4
- func HomogRotate3DX(angle float32) Mat4
- func HomogRotate3DY(angle float32) Mat4
- func HomogRotate3DZ(angle float32) Mat4
- func Ident4() Mat4
- func LookAt(eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ float32) Mat4
- func LookAtV(eye, center, up Vec3) Mat4
- func Mat4FromCols(col0, col1, col2, col3 Vec4) Mat4
- func Mat4FromRows(row0, row1, row2, row3 Vec4) Mat4
- func Ortho(left, right, bottom, top, near, far float32) Mat4
- func Ortho2D(left, right, bottom, top float32) Mat4
- func Perspective(fovy, aspect, near, far float32) Mat4
- func Scale3D(scaleX, scaleY, scaleZ float32) Mat4
- func ShearX3D(shearY, shearZ float32) Mat4
- func ShearY3D(shearX, shearZ float32) Mat4
- func ShearZ3D(shearX, shearY float32) Mat4
- func Translate3D(Tx, Ty, Tz float32) Mat4

- func (m Mat4) Abs() Mat4
- func (m1 Mat4) Add(m2 Mat4) Mat4
- func (m1 Mat4) ApproxEqual(m2 Mat4) bool
- func (m1 Mat4) ApproxEqualThreshold(m2 Mat4, threshold float32) bool
- func (m1 Mat4) ApproxFuncEqual(m2 Mat4, eq func(float32, float32) bool) bool
- func (m Mat4) At(row, col int) float32
- func (m Mat4) Col(col int) Vec4
- func (m Mat4) Cols() (col0, col1, col2, col3 Vec4)
- func (m Mat4) Det() float32
- func (m Mat4) Diag() Vec4
- func (m Mat4) Index(row, col int) int
- func (m Mat4) Inv() Mat4
- func (m Mat4) Mat2() Mat2
- func (m Mat4) Mat3() Mat3
- func (m1 Mat4) Mul(c float32) Mat4
- func (m1 Mat4) Mul4(m2 Mat4) Mat4
- func (m1 Mat4) Mul4x1(m2 Vec4) Vec4
- func (m1 Mat4) Mul4x2(m2 Mat4x2) Mat4x2
- func (m1 Mat4) Mul4x3(m2 Mat4x3) Mat4x3
- func (m Mat4) Row(row int) Vec4
- func (m Mat4) Rows() (row0, row1, row2, row3 Vec4)
- func (m *Mat4) Set(row, col int, value float32)
- func (m *Mat4) SetCol(col int, v Vec4)
- func (m *Mat4) SetRow(row int, v Vec4)
- func (m Mat4) String() string
- func (m1 Mat4) Sub(m2 Mat4) Mat4
- func (m Mat4) Trace() float32
- func (m1 Mat4) Transpose() Mat4

- type Mat4x2
- func (m Mat4x2) Abs() Mat4x2
- func (m1 Mat4x2) Add(m2 Mat4x2) Mat4x2
- func (m1 Mat4x2) ApproxEqual(m2 Mat4x2) bool
- func (m1 Mat4x2) ApproxEqualThreshold(m2 Mat4x2, threshold float32) bool
- func (m1 Mat4x2) ApproxFuncEqual(m2 Mat4x2, eq func(float32, float32) bool) bool
- func (m Mat4x2) At(row, col int) float32
- func (m Mat4x2) Col(col int) Vec4
- func (m Mat4x2) Cols() (col0, col1 Vec4)
- func (m Mat4x2) Index(row, col int) int
- func (m1 Mat4x2) Mul(c float32) Mat4x2
- func (m1 Mat4x2) Mul2(m2 Mat2) Mat4x2
- func (m1 Mat4x2) Mul2x1(m2 Vec2) Vec4
- func (m1 Mat4x2) Mul2x3(m2 Mat2x3) Mat4x3
- func (m1 Mat4x2) Mul2x4(m2 Mat2x4) Mat4
- func (m Mat4x2) Row(row int) Vec2
- func (m Mat4x2) Rows() (row0, row1, row2, row3 Vec2)
- func (m *Mat4x2) Set(row, col int, value float32)
- func (m *Mat4x2) SetCol(col int, v Vec4)
- func (m *Mat4x2) SetRow(row int, v Vec2)
- func (m Mat4x2) String() string
- func (m1 Mat4x2) Sub(m2 Mat4x2) Mat4x2
- func (m1 Mat4x2) Transpose() Mat2x4

- type Mat4x3
- func (m Mat4x3) Abs() Mat4x3
- func (m1 Mat4x3) Add(m2 Mat4x3) Mat4x3
- func (m1 Mat4x3) ApproxEqual(m2 Mat4x3) bool
- func (m1 Mat4x3) ApproxEqualThreshold(m2 Mat4x3, threshold float32) bool
- func (m1 Mat4x3) ApproxFuncEqual(m2 Mat4x3, eq func(float32, float32) bool) bool
- func (m Mat4x3) At(row, col int) float32
- func (m Mat4x3) Col(col int) Vec4
- func (m Mat4x3) Cols() (col0, col1, col2 Vec4)
- func (m Mat4x3) Index(row, col int) int
- func (m1 Mat4x3) Mul(c float32) Mat4x3
- func (m1 Mat4x3) Mul3(m2 Mat3) Mat4x3
- func (m1 Mat4x3) Mul3x1(m2 Vec3) Vec4
- func (m1 Mat4x3) Mul3x2(m2 Mat3x2) Mat4x2
- func (m1 Mat4x3) Mul3x4(m2 Mat3x4) Mat4
- func (m Mat4x3) Row(row int) Vec3
- func (m Mat4x3) Rows() (row0, row1, row2, row3 Vec3)
- func (m *Mat4x3) Set(row, col int, value float32)
- func (m *Mat4x3) SetCol(col int, v Vec4)
- func (m *Mat4x3) SetRow(row int, v Vec3)
- func (m Mat4x3) String() string
- func (m1 Mat4x3) Sub(m2 Mat4x3) Mat4x3
- func (m1 Mat4x3) Transpose() Mat3x4

- type MatMxN
- func (mat *MatMxN) Add(dst *MatMxN, addend *MatMxN) *MatMxN
- func (mat *MatMxN) ApproxEqual(m2 *MatMxN) bool
- func (mat *MatMxN) ApproxEqualFunc(m2 *MatMxN, comp func(float32, float32) bool) bool
- func (mat *MatMxN) ApproxEqualThreshold(m2 *MatMxN, epsilon float32) bool
- func (mat *MatMxN) At(row, col int) float32
- func (mat *MatMxN) InferMatrix(m interface{}) (*MatMxN, error)
- func (mat *MatMxN) Mul(dst *MatMxN, c float32) *MatMxN
- func (mat *MatMxN) MulMxN(dst *MatMxN, mul *MatMxN) *MatMxN
- func (mat *MatMxN) MulNx1(dst, v *VecN) *VecN
- func (mat *MatMxN) NumCols() int
- func (mat *MatMxN) NumRowCols() (rows, cols int)
- func (mat *MatMxN) NumRows() int
- func (mat *MatMxN) Raw() []float32
- func (mat *MatMxN) Reshape(m, n int) *MatMxN
- func (mat *MatMxN) Set(row, col int, val float32)
- func (mat *MatMxN) Sub(dst *MatMxN, subtrahend *MatMxN) *MatMxN
- func (mat *MatMxN) Trace() float32
- func (mat *MatMxN) Transpose(dst *MatMxN) (t *MatMxN)
- func (mat *MatMxN) Zero(m, n int)

- type NilMatrixError
- type Quat
- func AnglesToQuat(angle1, angle2, angle3 float32, order RotationOrder) Quat
- func Mat4ToQuat(m Mat4) Quat
- func QuatBetweenVectors(start, dest Vec3) Quat
- func QuatIdent() Quat
- func QuatLerp(q1, q2 Quat, amount float32) Quat
- func QuatLookAtV(eye, center, up Vec3) Quat
- func QuatNlerp(q1, q2 Quat, amount float32) Quat
- func QuatRotate(angle float32, axis Vec3) Quat
- func QuatSlerp(q1, q2 Quat, amount float32) Quat

- func (q1 Quat) Add(q2 Quat) Quat
- func (q1 Quat) ApproxEqual(q2 Quat) bool
- func (q1 Quat) ApproxEqualFunc(q2 Quat, f func(float32, float32) bool) bool
- func (q1 Quat) ApproxEqualThreshold(q2 Quat, epsilon float32) bool
- func (q1 Quat) Conjugate() Quat
- func (q1 Quat) Dot(q2 Quat) float32
- func (q1 Quat) Inverse() Quat
- func (q1 Quat) Len() float32
- func (q1 Quat) Mat4() Mat4
- func (q1 Quat) Mul(q2 Quat) Quat
- func (q1 Quat) Norm() float32
- func (q1 Quat) Normalize() Quat
- func (q1 Quat) OrientationEqual(q2 Quat) bool
- func (q1 Quat) OrientationEqualThreshold(q2 Quat, epsilon float32) bool
- func (q1 Quat) Rotate(v Vec3) Vec3
- func (q1 Quat) Scale(c float32) Quat
- func (q1 Quat) Sub(q2 Quat) Quat
- func (q Quat) X() float32
- func (q Quat) Y() float32
- func (q Quat) Z() float32

- type RectangularMatrixError
- type RotationOrder
- type Vec2
- func BezierCurve2D(t float32, cPoints []Vec2) Vec2
- func BezierSplineInterpolate2D(t float32, ranges [][2]float32, cPoints [][]Vec2) Vec2
- func Circle(radiusX, radiusY float32, numSlices int) []Vec2
- func CubicBezierCurve2D(t float32, cPoint1, cPoint2, cPoint3, cPoint4 Vec2) Vec2
- func MakeBezierCurve2D(numPoints int, cPoints []Vec2) (line []Vec2)
- func QuadraticBezierCurve2D(t float32, cPoint1, cPoint2, cPoint3 Vec2) Vec2
- func Rect(width, height float32) []Vec2

- func (v1 Vec2) Add(v2 Vec2) Vec2
- func (v1 Vec2) ApproxEqual(v2 Vec2) bool
- func (v1 Vec2) ApproxEqualThreshold(v2 Vec2, threshold float32) bool
- func (v1 Vec2) ApproxFuncEqual(v2 Vec2, eq func(float32, float32) bool) bool
- func (v1 Vec2) Dot(v2 Vec2) float32
- func (v Vec2) Elem() (x, y float32)
- func (v1 Vec2) Len() float32
- func (v1 Vec2) LenSqr() float32
- func (v1 Vec2) Mul(c float32) Vec2
- func (v1 Vec2) Normalize() Vec2
- func (v1 Vec2) OuterProd2(v2 Vec2) Mat2
- func (v1 Vec2) OuterProd3(v2 Vec3) Mat2x3
- func (v1 Vec2) OuterProd4(v2 Vec4) Mat2x4
- func (v1 Vec2) Sub(v2 Vec2) Vec2
- func (v Vec2) Vec3(z float32) Vec3
- func (v Vec2) Vec4(z, w float32) Vec4
- func (v Vec2) X() float32
- func (v Vec2) Y() float32

- type Vec3
- func BezierCurve3D(t float32, cPoints []Vec3) Vec3
- func BezierSplineInterpolate3D(t float32, ranges [][2]float32, cPoints [][]Vec3) Vec3
- func BezierSurface(u, v float32, cPoints [][]Vec3) Vec3
- func CubicBezierCurve3D(t float32, cPoint1, cPoint2, cPoint3, cPoint4 Vec3) Vec3
- func CylindricalToCartesian(rho, phi, z float32) Vec3
- func MakeBezierCurve3D(numPoints int, cPoints []Vec3) (line []Vec3)
- func Project(obj Vec3, modelview, projection Mat4, initialX, initialY, width, height int) (win Vec3)
- func QuadraticBezierCurve3D(t float32, cPoint1, cPoint2, cPoint3 Vec3) Vec3
- func SphericalToCartesian(r, theta, phi float32) Vec3
- func TransformCoordinate(v Vec3, m Mat4) Vec3
- func TransformNormal(v Vec3, m Mat4) Vec3
- func UnProject(win Vec3, modelview, projection Mat4, initialX, initialY, width, height int) (obj Vec3, err error)

- func (v1 Vec3) Add(v2 Vec3) Vec3
- func (v1 Vec3) ApproxEqual(v2 Vec3) bool
- func (v1 Vec3) ApproxEqualThreshold(v2 Vec3, threshold float32) bool
- func (v1 Vec3) ApproxFuncEqual(v2 Vec3, eq func(float32, float32) bool) bool
- func (v1 Vec3) Cross(v2 Vec3) Vec3
- func (v1 Vec3) Dot(v2 Vec3) float32
- func (v Vec3) Elem() (x, y, z float32)
- func (v1 Vec3) Len() float32
- func (v1 Vec3) LenSqr() float32
- func (v1 Vec3) Mul(c float32) Vec3
- func (v1 Vec3) Normalize() Vec3
- func (v1 Vec3) OuterProd2(v2 Vec2) Mat3x2
- func (v1 Vec3) OuterProd3(v2 Vec3) Mat3
- func (v1 Vec3) OuterProd4(v2 Vec4) Mat3x4
- func (v1 Vec3) Sub(v2 Vec3) Vec3
- func (v Vec3) Vec2() Vec2
- func (v Vec3) Vec4(w float32) Vec4
- func (v Vec3) X() float32
- func (v Vec3) Y() float32
- func (v Vec3) Z() float32

- type Vec4
- func (v1 Vec4) Add(v2 Vec4) Vec4
- func (v1 Vec4) ApproxEqual(v2 Vec4) bool
- func (v1 Vec4) ApproxEqualThreshold(v2 Vec4, threshold float32) bool
- func (v1 Vec4) ApproxFuncEqual(v2 Vec4, eq func(float32, float32) bool) bool
- func (v1 Vec4) Dot(v2 Vec4) float32
- func (v Vec4) Elem() (x, y, z, w float32)
- func (v1 Vec4) Len() float32
- func (v1 Vec4) LenSqr() float32
- func (v1 Vec4) Mul(c float32) Vec4
- func (v1 Vec4) Normalize() Vec4
- func (v1 Vec4) OuterProd2(v2 Vec2) Mat4x2
- func (v1 Vec4) OuterProd3(v2 Vec3) Mat4x3
- func (v1 Vec4) OuterProd4(v2 Vec4) Mat4
- func (v Vec4) Quat() Quat
- func (v1 Vec4) Sub(v2 Vec4) Vec4
- func (v Vec4) Vec2() Vec2
- func (v Vec4) Vec3() Vec3
- func (v Vec4) W() float32
- func (v Vec4) X() float32
- func (v Vec4) Y() float32
- func (v Vec4) Z() float32

- type VecN
- func (vn *VecN) Add(dst *VecN, subtrahend *VecN) *VecN
- func (vn *VecN) ApproxEqual(vn2 *VecN) bool
- func (vn *VecN) ApproxEqualFunc(vn2 *VecN, comp func(float32, float32) bool) bool
- func (vn *VecN) ApproxEqualThreshold(vn2 *VecN, epsilon float32) bool
- func (vn *VecN) Cap() int
- func (vn *VecN) Cross(dst *VecN, other *VecN) *VecN
- func (vn *VecN) Dot(other *VecN) float32
- func (vn VecN) Get(i int) float32
- func (vn *VecN) Len() float32
- func (vn *VecN) LenSqr() float32
- func (vn *VecN) Mul(dst *VecN, c float32) *VecN
- func (vn *VecN) Normalize(dst *VecN) *VecN
- func (vn *VecN) OuterProd(dst *MatMxN, v2 *VecN) *MatMxN
- func (vn VecN) Raw() []float32
- func (vn *VecN) Resize(n int) *VecN
- func (vn *VecN) Set(i int, val float32)
- func (vn *VecN) SetBackingSlice(newSlice []float32)
- func (vn *VecN) Size() int
- func (vn *VecN) Sub(dst *VecN, addend *VecN) *VecN
- func (vn *VecN) Vec2() Vec2
- func (vn *VecN) Vec3() Vec3
- func (vn *VecN) Vec4() Vec4
- func (vn *VecN) Zero(n int)

### Constants ¶

### Variables ¶

var ( MinNormal = float32(1.1754943508222875e-38) // 1 / 2**(127 - 1) MinValue = float32(math.SmallestNonzeroFloat32) MaxValue = float32(math.MaxFloat32) InfPos = float32(math.Inf(1)) InfNeg = float32(math.Inf(-1)) NaN = float32(math.NaN()) )

Various useful constants.

`var Epsilon float32 = 1e-10`

Epsilon is some tiny value that determines how precisely equal we want our floats to be This is exported and left as a variable in case you want to change the default threshold for the purposes of certain methods (e.g. Unproject uses the default epsilon when determining if the determinant is "close enough" to zero to mean there's no inverse).

This is, obviously, not mutex protected so be **absolutely sure** that no functions using Epsilon are being executed when you change this.

### Functions ¶

#### func Abs ¶

Abs is a direct copy of the math package's Abs. This is here for the mgl32 package, to prevent rampant type conversions during equality tests.

#### func CartesianToCylindical ¶

CartesianToCylindical converts 3-dimensional cartesian coordinates (x,y,z) to cylindrical coordinates with radial distance r, azimuth phi, and height z.

All angles are in radians.

#### func CartesianToSpherical ¶

CartesianToSpherical converts 3-dimensional cartesian coordinates (x,y,z) to spherical coordinates with radius r, inclination theta, and azimuth phi.

All angles are in radians.

#### func Clamp ¶

Clamp takes in a value and two thresholds. If the value is smaller than the low threshold, it returns the low threshold. If it's bigger than the high threshold it returns the high threshold. Otherwise it returns the value.

Useful to prevent some functions from freaking out because a value was teeeeechnically out of range.

#### func ClampFunc ¶

ClampFunc generates a closure that returns its parameter clamped to the range [low,high].

#### func CopyMatMN ¶

func CopyMatMN(dst, src *MatMxN)

CopyMatMN copies src into dst. This Reshapes dst to the same size as src.

If dst or src is nil, this is a no-op

#### func CylindircalToSpherical ¶

CylindircalToSpherical converts cylindrical coordinates with radial distance r, azimuth phi, and height z to spherical coordinates with radius r, inclination theta, and azimuth phi.

Angles are in radians

#### func DisableMemoryPooling ¶

func DisableMemoryPooling()

#### func Extract3DScale ¶

Extract3DScale extracts the 3d scaling from a homogeneous matrix

#### func ExtractMaxScale ¶

ExtractMaxScale extracts the maximum scaling from a homogeneous matrix

#### func FloatEqual ¶

FloatEqual is a safe utility function to compare floats. It's Taken from http://floating-point-gui.de/errors/comparison/

It is slightly altered to not call Abs when not needed.

#### func FloatEqualFunc ¶

FloatEqualFunc is a utility closure that will generate a function that always approximately compares floats like FloatEqualThreshold with a different threshold.

#### func FloatEqualThreshold ¶

FloatEqualThreshold is a utility function to compare floats. It's Taken from http://floating-point-gui.de/errors/comparison/

It is slightly altered to not call Abs when not needed.

This differs from FloatEqual in that it lets you pass in your comparison threshold, so that you can adjust the comparison value to your specific needs

#### func GLToScreenCoords ¶

GLToScreenCoords transforms from GL's proportional system to pixel coordinates.

Assumes the pixel coordinate system has its origin in the top left corner. (GL's is in the bottom left)

GL's coordinate system maps [screenWidth-1,0] to [1.0,1.0] and [0,screenHeight-1] to [-1.0,-1.0]. If x and y are out of the range, they'll still be mapped correctly, just off the screen. (e.g. if y=-3.0, you'll get 2*(screenHeight-1) for yOut)

This is similar to Project, except for 2D cases and much simpler

#### func IsClamped ¶

IsClamped checks if a is clamped between low and high as if Clamp(a, low, high) had been called.

In most cases it's probably better to just call Clamp without checking this since it's relatively cheap.

The IsClamped functions use strict equality (meaning: not the FloatEqual function) there shouldn't be any major issues with this since clamp is often used to fix minor errors

#### func ReticulateSplines ¶

ReticulateSplines reticulates ALL the Splines.

For the overly serious: the function is just for fun. It does nothing except prints a Maxis reference. Technically you could "reticulate splines" by joining a bunch of splines together, but that ruins the joke.

#### func Round ¶

Round shortens a float32 value to a specified precision (number of digits after the decimal point) with "round half up" tie-braking rule. Half-way values (23.5) are always rounded up (24).

#### func ScreenToGLCoords ¶

ScreenToGLCoords transforms from pixel coordinates to GL coordinates.

This assumes that your pixel coordinate system considers its origin to be in the top left corner (GL's is in the bottom left). The coordinates x and y may be out of the range [0,screenWidth-1] and [0,screeneHeight-1].

GL's coordinate system maps [screenWidth-1,0] to [1.0,1.0] and [0,screenHeight-1] to [-1.0,-1.0]. If x and y are out of the range, they'll still be mapped correctly, just off the screen. (e.g. if y = 2*(screenHeight-1) you'll get -3.0 for yOut)

This is similar to Unproject, except for 2D cases and much simpler (especially since an inverse may always be found)

#### func SphericalToCylindrical ¶

SphericalToCylindrical converts spherical coordinates with radius r, inclination theta, and azimuth phi to cylindrical coordinates with radial distance r, azimuth phi, and height z.

Angles are in radians

### Types ¶

#### type InferMatrixError ¶

type InferMatrixError struct{}

InferMatrixError may be returned by InferMatrix.

Make sure you're using a constant matrix such as Mat3 from within the same package (meaning: mgl32.MatMxN can't handle a mgl64.Mat2x3).

#### func (InferMatrixError) Error ¶

func (me InferMatrixError) Error() string

#### type Mat2 ¶

type Mat2 [4]float32

#### func Diag2 ¶

Diag2 creates a diagonal matrix from the entries of the input vector. That is, for each pointer for row==col, vector[row] is the entry. Otherwise it's 0.

Another way to think about it is that the identity is this function where the every vector element is 1.

#### func Ident2 ¶

func Ident2() Mat2

Ident2 returns the 2x2 identity matrix. The identity matrix is a square matrix with the value 1 on its diagonals. The characteristic property of the identity matrix is that any matrix multiplied by it is itself. (MI = M; IN = N)

#### func Mat2FromCols ¶

Mat2FromCols builds a new matrix from column vectors.

#### func Mat2FromRows ¶

#### func Rotate2D ¶

Rotate2D returns a rotation Matrix about a angle in 2-D space. Specifically about the origin. It is a 2x2 matrix, if you need a 3x3 for Homogeneous math (e.g. composition with a Translation matrix) see HomogRotate2D

#### func (Mat2) Add ¶

Add performs an element-wise addition of two matrices, this is equivalent to iterating over every element of m1 and adding the corresponding value of m2.

#### func (Mat2) ApproxEqual ¶

ApproxEqual performs an element-wise approximate equality test between two matrices, as if FloatEqual had been used.

#### func (Mat2) ApproxEqualThreshold ¶

ApproxEqualThreshold performs an element-wise approximate equality test between two matrices with a given epsilon threshold, as if FloatEqualThreshold had been used.

#### func (Mat2) ApproxFuncEqual ¶

ApproxFuncEqual performs an element-wise approximate equality test between two matrices with a given equality functions, intended to be used with FloatEqualFunc; although and comparison function may be used in practice.

#### func (Mat2) At ¶

At returns the matrix element at the given row and column. This is equivalent to mat[col * numRow + row] where numRow is constant (E.G. for a Mat3x2 it's equal to 3)

This method is garbage-in garbage-out. For instance, on a Mat4 asking for At(5,0) will work just like At(1,1). Or it may panic if it's out of bounds.

#### func (Mat2) Col ¶

Col returns a vector representing the corresponding column (starting at col 0). This package makes no distinction between row and column vectors, so it will be a normal VecN for a MxN matrix.

#### func (Mat2) Cols ¶

Cols decomposes a matrix into its corresponding column vectors. This is equivalent to calling mat.Col for each column.

#### func (Mat2) Det ¶

Det returns the determinant of a matrix. It is a measure of a square matrix's singularity and invertability, among other things. In this library, the determinant is hard coded based on pre-computed cofactor expansion, and uses no loops. Of course, the addition and multiplication must still be done.

#### func (Mat2) Diag ¶

Diag is a basic operation on a square matrix that simply returns main diagonal (meaning all elements such that row==col).

#### func (Mat2) Index ¶

Index returns the index of the given row and column, to be used with direct access. E.G. Index(0,0) = 0.

This is a garbage-in garbage-out method. For instance, on a Mat4 asking for the index of (5,0) will work the same as asking for (1,1). Or it may give you a value that will cause a panic if you try to access the array with it if it's truly out of bounds.

#### func (Mat2) Inv ¶

Inv computes the inverse of a square matrix. An inverse is a square matrix such that when multiplied by the original, yields the identity.

M_inv * M = M * M_inv = I

In this library, the math is precomputed, and uses no loops, though the multiplications, additions, determinant calculation, and scaling are still done. This can still be (relatively) expensive for a 4x4.

This function checks the determinant to see if the matrix is invertible. If the determinant is 0.0, this function returns the zero matrix. However, due to floating point errors, it is entirely plausible to get a false positive or negative. In the future, an alternate function may be written which takes in a pre-computed determinant.

#### func (Mat2) Mul ¶

Mul performs a scalar multiplcation of the matrix. This is equivalent to iterating over every element of the matrix and multiply it by c.

#### func (Mat2) Mul2 ¶

Mul2 performs a "matrix product" between this matrix and another of the given dimension. For any two matrices of dimensionality MxN and NxO, the result will be MxO. For instance, Mat4 multiplied using Mul4x2 will result in a Mat4x2.

#### func (Mat2) Mul2x1 ¶

Mul2x1 performs a "matrix product" between this matrix and another of the given dimension. For any two matrices of dimensionality MxN and NxO, the result will be MxO. For instance, Mat4 multiplied using Mul4x2 will result in a Mat4x2.

#### func (Mat2) Mul2x3 ¶

Mul2x3 performs a "matrix product" between this matrix and another of the given dimension. For any two matrices of dimensionality MxN and NxO, the result will be MxO. For instance, Mat4 multiplied using Mul4x2 will result in a Mat4x2.

#### func (Mat2) Mul2x4 ¶

Mul2x4 performs a "matrix product" between this matrix and another of the given dimension. For any two matrices of dimensionality MxN and NxO, the result will be MxO. For instance, Mat4 multiplied using Mul4x2 will result in a Mat4x2.

#### func (Mat2) Row ¶

Row returns a vector representing the corresponding row (starting at row 0). This package makes no distinction between row and column vectors, so it will be a normal VecM for a MxN matrix.

#### func (Mat2) Rows ¶

Rows decomposes a matrix into its corresponding row vectors. This is equivalent to calling mat.Row for each row.

#### func (*Mat2) Set ¶

Set sets the corresponding matrix element at the given row and column. This has a pointer receiver because it mutates the matrix.

This method is garbage-in garbage-out. For instance, on a Mat4 asking for Set(5,0,val) will work just like Set(1,1,val). Or it may panic if it's out of bounds.

#### func (Mat2) Sub ¶

Sub performs an element-wise subtraction of two matrices, this is equivalent to iterating over every element of m1 and subtracting the corresponding value of m2.

#### func (Mat2) Trace ¶

Trace is a basic operation on a square matrix that simply sums up all elements on the main diagonal (meaning all elements such that row==col).

#### type Mat2x3 ¶

type Mat2x3 [6]float32

#### func Mat2x3FromCols ¶

Mat2x3FromCols builds a new matrix from column vectors.

#### func Mat2x3FromRows ¶

#### func (Mat2x3) Add ¶

Add performs an element-wise addition of two matrices, this is equivalent to iterating over every element of m1 and adding the corresponding value of m2.

#### func (Mat2x3) ApproxEqual ¶

ApproxEqual performs an element-wise approximate equality test between two matrices, as if FloatEqual had been used.

#### func (Mat2x3) ApproxEqualThreshold ¶

ApproxEqualThreshold performs an element-wise approximate equality test between two matrices with a given epsilon threshold, as if FloatEqualThreshold had been used.

#### func (Mat2x3) ApproxFuncEqual ¶

ApproxFuncEqual performs an element-wise approximate equality test between two matrices with a given equality functions, intended to be used with FloatEqualFunc; although and comparison function may be used in practice.

#### func (Mat2x3) At ¶

At returns the matrix element at the given row and column. This is equivalent to mat[col * numRow + row] where numRow is constant (E.G. for a Mat3x2 it's equal to 3)

This method is garbage-in garbage-out. For instance, on a Mat4 asking for At(5,0) will work just like At(1,1). Or it may panic if it's out of bounds.

#### func (Mat2x3) Col ¶

Col returns a vector representing the corresponding column (starting at col 0). This package makes no distinction between row and column vectors, so it will be a normal VecN for a MxN matrix.

#### func (Mat2x3) Cols ¶

Cols decomposes a matrix into its corresponding column vectors. This is equivalent to calling mat.Col for each column.

#### func (Mat2x3) Index ¶

Index returns the index of the given row and column, to be used with direct access. E.G. Index(0,0) = 0.

This is a garbage-in garbage-out method. For instance, on a Mat4 asking for the index of (5,0) will work the same as asking for (1,1). Or it may give you a value that will cause a panic if you try to access the array with it if it's truly out of bounds.

#### func (Mat2x3) Mul ¶

Mul performs a scalar multiplcation of the matrix. This is equivalent to iterating over every element of the matrix and multiply it by c.

#### func (Mat2x3) Mul3 ¶

Mul3 performs a "matrix product" between this matrix and another of the given dimension. For any two matrices of dimensionality MxN and NxO, the result will be MxO. For instance, Mat4 multiplied using Mul4x2 will result in a Mat4x2.

#### func (Mat2x3) Mul3x1 ¶

Mul3x1 performs a "matrix product" between this matrix and another of the given dimension. For any two matrices of dimensionality MxN and NxO, the result will be MxO. For instance, Mat4 multiplied using Mul4x2 will result in a Mat4x2.

#### func (Mat2x3) Mul3x2 ¶

Mul3x2 performs a "matrix product" between this matrix and another of the given dimension. For any two matrices of dimensionality MxN and NxO, the result will be MxO. For instance, Mat4 multiplied using Mul4x2 will result in a Mat4x2.

#### func (Mat2x3) Mul3x4 ¶

Mul3x4 performs a "matrix product" between this matrix and another of the given dimension. For any two matrices of dimensionality MxN and NxO, the result will be MxO. For instance, Mat4 multiplied using Mul4x2 will result in a Mat4x2.

#### func (Mat2x3) Row ¶

Row returns a vector representing the corresponding row (starting at row 0). This package makes no distinction between row and column vectors, so it will be a normal VecM for a MxN matrix.

#### func (Mat2x3) Rows ¶

Rows decomposes a matrix into its corresponding row vectors. This is equivalent to calling mat.Row for each row.

#### func (*Mat2x3) Set ¶

Set sets the corresponding matrix element at the given row and column. This has a pointer receiver because it mutates the matrix.

This method is garbage-in garbage-out. For instance, on a Mat4 asking for Set(5,0,val) will work just like Set(1,1,val). Or it may panic if it's out of bounds.

#### func (Mat2x3) Sub ¶

Sub performs an element-wise subtraction of two matrices, this is equivalent to iterating over every element of m1 and subtracting the corresponding value of m2.

#### type Mat2x4 ¶

type Mat2x4 [8]float32

#### func Mat2x4FromCols ¶

Mat2x4FromCols builds a new matrix from column vectors.

#### func Mat2x4FromRows ¶

#### func (Mat2x4) Add ¶

Add performs an element-wise addition of two matrices, this is equivalent to iterating over every element of m1 and adding the corresponding value of m2.

#### func (Mat2x4) ApproxEqual ¶

ApproxEqual performs an element-wise approximate equality test between two matrices, as if FloatEqual had been used.

#### func (Mat2x4) ApproxEqualThreshold ¶

ApproxEqualThreshold performs an element-wise approximate equality test between two matrices with a given epsilon threshold, as if FloatEqualThreshold had been used.

#### func (Mat2x4) ApproxFuncEqual ¶

ApproxFuncEqual performs an element-wise approximate equality test between two matrices with a given equality functions, intended to be used with FloatEqualFunc; although and comparison function may be used in practice.

#### func (Mat2x4) At ¶

At returns the matrix element at the given row and column. This is equivalent to mat[col * numRow + row] where numRow is constant (E.G. for a Mat3x2 it's equal to 3)

This method is garbage-in garbage-out. For instance, on a Mat4 asking for At(5,0) will work just like At(1,1). Or it may panic if it's out of bounds.

#### func (Mat2x4) Col ¶

Col returns a vector representing the corresponding column (starting at col 0). This package makes no distinction between row and column vectors, so it will be a normal VecN for a MxN matrix.

#### func (Mat2x4) Cols ¶

Cols decomposes a matrix into its corresponding column vectors. This is equivalent to calling mat.Col for each column.

#### func (Mat2x4) Index ¶

Index returns the index of the given row and column, to be used with direct access. E.G. Index(0,0) = 0.

This is a garbage-in garbage-out method. For instance, on a Mat4 asking for the index of (5,0) will work the same as asking for (1,1). Or it may give you a value that will cause a panic if you try to access the array with it if it's truly out of bounds.

#### func (Mat2x4) Mul ¶

Mul performs a scalar multiplcation of the matrix. This is equivalent to iterating over every element of the matrix and multiply it by c.

#### func (Mat2x4) Mul4 ¶

Mul4 performs a "matrix product" between this matrix and another of the given dimension. For any two matrices of dimensionality MxN and NxO, the result will be MxO. For instance, Mat4 multiplied using Mul4x2 will result in a Mat4x2.

#### func (Mat2x4) Mul4x1 ¶

Mul4x1 performs a "matrix product" between this matrix and another of the given dimension. For any two matrices of dimensionality MxN and NxO, the result will be MxO. For instance, Mat4 multiplied using Mul4x2 will result in a Mat4x2.

#### func (Mat2x4) Mul4x2 ¶

Mul4x2 performs a "matrix product" between this matrix and another of the given dimension. For any two matrices of dimensionality MxN and NxO, the result will be MxO. For instance, Mat4 multiplied using Mul4x2 will result in a Mat4x2.

#### func (Mat2x4) Mul4x3 ¶

Mul4x3 performs a "matrix product" between this matrix and another of the given dimension. For any two matrices of dimensionality MxN and NxO, the result will be MxO. For instance, Mat4 multiplied using Mul4x2 will result in a Mat4x2.

#### func (Mat2x4) Row ¶

Row returns a vector representing the corresponding row (starting at row 0). This package makes no distinction between row and column vectors, so it will be a normal VecM for a MxN matrix.

#### func (Mat2x4) Rows ¶

Rows decomposes a matrix into its corresponding row vectors. This is equivalent to calling mat.Row for each row.

#### func (*Mat2x4) Set ¶

Set sets the corresponding matrix element at the given row and column. This has a pointer receiver because it mutates the matrix.

This method is garbage-in garbage-out. For instance, on a Mat4 asking for Set(5,0,val) will work just like Set(1,1,val). Or it may panic if it's out of bounds.

#### func (Mat2x4) Sub ¶

Sub performs an element-wise subtraction of two matrices, this is equivalent to iterating over every element of m1 and subtracting the corresponding value of m2.

#### type Mat3 ¶

#### func Diag3 ¶

Diag3 creates a diagonal matrix from the entries of the input vector. That is, for each pointer for row==col, vector[row] is the entry. Otherwise it's 0.

Another way to think about it is that the identity is this function where the every vector element is 1.

#### func HomogRotate2D ¶

HomogRotate2D is the same as Rotate2D, except homogeneous (3x3 with the extra row/col being all zeroes with a one in the bottom right)

#### func Ident3 ¶

func Ident3() Mat3

Ident3 returns the 3x3 identity matrix. The identity matrix is a square matrix with the value 1 on its diagonals. The characteristic property of the identity matrix is that any matrix multiplied by it is itself. (MI = M; IN = N)

#### func Mat3FromCols ¶

Mat3FromCols builds a new matrix from column vectors.

#### func Mat3FromRows ¶

#### func Mat4Normal ¶

Mat4Normal calculates the Normal of the Matrix (aka the inverse transpose)

#### func Rotate3DX ¶

Rotate3DX returns a 3x3 (non-homogeneous) Matrix that rotates by angle about the X-axis

Where c is cos(angle) and s is sin(angle)

[1 0 0] [0 c -s] [0 s c ]

#### func Rotate3DY ¶

Rotate3DY returns a 3x3 (non-homogeneous) Matrix that rotates by angle about the Y-axis

Where c is cos(angle) and s is sin(angle)

[c 0 s] [0 1 0] [s 0 c ]

#### func Rotate3DZ ¶

Rotate3DZ returns a 3x3 (non-homogeneous) Matrix that rotates by angle about the Z-axis

Where c is cos(angle) and s is sin(angle)

[c -s 0] [s c 0] [0 0 1 ]

#### func Scale2D ¶

Scale2D creates a homogeneous 2D scaling matrix [[ scaleX, 0 , 0 ]] [[ 0 , scaleY, 0 ]] [[ 0 , 0 , 1 ]]

#### func Translate2D ¶

Translate2D returns a homogeneous (3x3 for 2D-space) Translation matrix that moves a point by Tx units in the x-direction and Ty units in the y-direction

[[1, 0, Tx]] [[0, 1, Ty]] [[0, 0, 1 ]]

#### func (Mat3) Add ¶

#### func (Mat3) ApproxEqual ¶

#### func (Mat3) ApproxEqualThreshold ¶

#### func (Mat3) ApproxFuncEqual ¶

#### func (Mat3) At ¶

#### func (Mat3) Col ¶

#### func (Mat3) Cols ¶

#### func (Mat3) Det ¶

Det returns the determinant of a matrix. It is a measure of a square matrix's singularity and invertability, among other things. In this library, the determinant is hard coded based on pre-computed cofactor expansion, and uses no loops. Of course, the addition and multiplication must still be done.

#### func (Mat3) Diag ¶

Diag is a basic operation on a square matrix that simply returns main diagonal (meaning all elements such that row==col).

#### func (Mat3) Index ¶

#### func (Mat3) Inv ¶

Inv computes the inverse of a square matrix. An inverse is a square matrix such that when multiplied by the original, yields the identity.

M_inv * M = M * M_inv = I

In this library, the math is precomputed, and uses no loops, though the multiplications, additions, determinant calculation, and scaling are still done. This can still be (relatively) expensive for a 4x4.

This function checks the determinant to see if the matrix is invertible. If the determinant is 0.0, this function returns the zero matrix. However, due to floating point errors, it is entirely plausible to get a false positive or negative. In the future, an alternate function may be written which takes in a pre-computed determinant.

#### func (Mat3) Mul ¶

#### func (Mat3) Mul3 ¶

Mul3 performs a "matrix product" between this matrix and another of the given dimension. For any two matrices of dimensionality MxN and NxO, the result will be MxO. For instance, Mat4 multiplied using Mul4x2 will result in a Mat4x2.

#### func (Mat3) Mul3x1 ¶

Mul3x1 performs a "matrix product" between this matrix and another of the given dimension. For any two matrices of dimensionality MxN and NxO, the result will be MxO. For instance, Mat4 multiplied using Mul4x2 will result in a Mat4x2.

#### func (Mat3) Mul3x2 ¶

Mul3x2 performs a "matrix product" between this matrix and another of the given dimension. For any two matrices of dimensionality MxN and NxO, the result will be MxO. For instance, Mat4 multiplied using Mul4x2 will result in a Mat4x2.

#### func (Mat3) Mul3x4 ¶

Mul3x4 performs a "matrix product" between this matrix and another of the given dimension. For any two matrices of dimensionality MxN and NxO, the result will be MxO. For instance, Mat4 multiplied using Mul4x2 will result in a Mat4x2.

#### func (Mat3) Row ¶

#### func (Mat3) Rows ¶

#### func (*Mat3) Set ¶

#### func (Mat3) Sub ¶

#### func (Mat3) Trace ¶

Trace is a basic operation on a square matrix that simply sums up all elements on the main diagonal (meaning all elements such that row==col).

#### type Mat3x2 ¶

type Mat3x2 [6]float32

#### func Mat3x2FromCols ¶

Mat3x2FromCols builds a new matrix from column vectors.

#### func Mat3x2FromRows ¶

#### func (Mat3x2) Add ¶

#### func (Mat3x2) ApproxEqual ¶

#### func (Mat3x2) ApproxEqualThreshold ¶

#### func (Mat3x2) ApproxFuncEqual ¶

#### func (Mat3x2) At ¶

#### func (Mat3x2) Col ¶

#### func (Mat3x2) Cols ¶

#### func (Mat3x2) Index ¶

#### func (Mat3x2) Mul ¶

#### func (Mat3x2) Mul2 ¶

Mul2 performs a "matrix product" between this matrix and another of the given dimension. For any two matrices of dimensionality MxN and NxO, the result will be MxO. For instance, Mat4 multiplied using Mul4x2 will result in a Mat4x2.

#### func (Mat3x2) Mul2x1 ¶

Mul2x1 performs a "matrix product" between this matrix and another of the given dimension. For any two matrices of dimensionality MxN and NxO, the result will be MxO. For instance, Mat4 multiplied using Mul4x2 will result in a Mat4x2.

#### func (Mat3x2) Mul2x3 ¶

Mul2x3 performs a "matrix product" between this matrix and another of the given dimension. For any two matrices of dimensionality MxN and NxO, the result will be MxO. For instance, Mat4 multiplied using Mul4x2 will result in a Mat4x2.

#### func (Mat3x2) Mul2x4 ¶

Mul2x4 performs a "matrix product" between this matrix and another of the given dimension. For any two matrices of dimensionality MxN and NxO, the result will be MxO. For instance, Mat4 multiplied using Mul4x2 will result in a Mat4x2.

#### func (Mat3x2) Row ¶

#### func (Mat3x2) Rows ¶

#### func (*Mat3x2) Set ¶

#### func (Mat3x2) Sub ¶

#### type Mat3x4 ¶

type Mat3x4 [12]float32

#### func Mat3x4FromCols ¶

Mat3x4FromCols builds a new matrix from column vectors.

#### func Mat3x4FromRows ¶

#### func (Mat3x4) Add ¶

#### func (Mat3x4) ApproxEqual ¶

#### func (Mat3x4) ApproxEqualThreshold ¶

#### func (Mat3x4) ApproxFuncEqual ¶

#### func (Mat3x4) At ¶

#### func (Mat3x4) Col ¶

#### func (Mat3x4) Cols ¶

#### func (Mat3x4) Index ¶

#### func (Mat3x4) Mul ¶

#### func (Mat3x4) Mul4 ¶

Mul4 performs a "matrix product" between this matrix and another of the given dimension. For any two matrices of dimensionality MxN and NxO, the result will be MxO. For instance, Mat4 multiplied using Mul4x2 will result in a Mat4x2.

#### func (Mat3x4) Mul4x1 ¶

Mul4x1 performs a "matrix product" between this matrix and another of the given dimension. For any two matrices of dimensionality MxN and NxO, the result will be MxO. For instance, Mat4 multiplied using Mul4x2 will result in a Mat4x2.

#### func (Mat3x4) Mul4x2 ¶

Mul4x2 performs a "matrix product" between this matrix and another of the given dimension. For any two matrices of dimensionality MxN and NxO, the result will be MxO. For instance, Mat4 multiplied using Mul4x2 will result in a Mat4x2.

#### func (Mat3x4) Mul4x3 ¶

Mul4x3 performs a "matrix product" between this matrix and another of the given dimension. For any two matrices of dimensionality MxN and NxO, the result will be MxO. For instance, Mat4 multiplied using Mul4x2 will result in a Mat4x2.

#### func (Mat3x4) Row ¶

#### func (Mat3x4) Rows ¶

#### func (*Mat3x4) Set ¶

#### func (Mat3x4) Sub ¶

#### type Mat4 ¶

#### func Diag4 ¶

Diag4 creates a diagonal matrix from the entries of the input vector. That is, for each pointer for row==col, vector[row] is the entry. Otherwise it's 0.

Another way to think about it is that the identity is this function where the every vector element is 1.

#### func HomogRotate3D ¶

HomogRotate3D creates a 3D rotation Matrix that rotates by (radian) angle about some arbitrary axis given by a normalized Vector. It produces a homogeneous matrix (4x4)

Where c is cos(angle) and s is sin(angle), and x, y, and z are the first, second, and third elements of the axis vector (respectively):

[[ x^2(1-c)+c, xy(1-c)-zs, xz(1-c)+ys, 0 ]] [[ xy(1-c)+zs, y^2(1-c)+c, yz(1-c)-xs, 0 ]] [[ xz(1-c)-ys, yz(1-c)+xs, z^2(1-c)+c, 0 ]] [[ 0 , 0 , 0 , 1 ]]

#### func HomogRotate3DX ¶

HomogRotate3DX is the same as Rotate3DX, except homogeneous (4x4 with the extra row/col being all zeroes with a one in the bottom right)

#### func HomogRotate3DY ¶

HomogRotate3DY is the same as Rotate3DY, except homogeneous (4x4 with the extra row/col being all zeroes with a one in the bottom right)

#### func HomogRotate3DZ ¶

HomogRotate3DZ is the same as Rotate3DZ, except homogeneous (4x4 with the extra row/col being all zeroes with a one in the bottom right)

#### func Ident4 ¶

func Ident4() Mat4

Ident4 returns the 4x4 identity matrix. The identity matrix is a square matrix with the value 1 on its diagonals. The characteristic property of the identity matrix is that any matrix multiplied by it is itself. (MI = M; IN = N)

#### func Mat4FromCols ¶

Mat4FromCols builds a new matrix from column vectors.

#### func Mat4FromRows ¶

#### func Ortho2D ¶

Ortho2D is equivalent to Ortho with the near and far planes being -1 and 1, respectively.

#### func Perspective ¶

Perspective generates a Perspective Matrix.

#### func Scale3D ¶

Scale3D creates a homogeneous 3D scaling matrix [[ scaleX, 0 , 0 , 0 ]] [[ 0 , scaleY, 0 , 0 ]] [[ 0 , 0 , scaleZ, 0 ]] [[ 0 , 0 , 0 , 1 ]]

#### func Translate3D ¶

Translate3D returns a homogeneous (4x4 for 3D-space) Translation matrix that moves a point by Tx units in the x-direction, Ty units in the y-direction, and Tz units in the z-direction

[[1, 0, 0, Tx]] [[0, 1, 0, Ty]] [[0, 0, 1, Tz]] [[0, 0, 0, 1 ]]

#### func (Mat4) Add ¶

#### func (Mat4) ApproxEqual ¶

#### func (Mat4) ApproxEqualThreshold ¶

#### func (Mat4) ApproxFuncEqual ¶

#### func (Mat4) At ¶

#### func (Mat4) Col ¶

#### func (Mat4) Cols ¶

#### func (Mat4) Det ¶

Det returns the determinant of a matrix. It is a measure of a square matrix's singularity and invertability, among other things. In this library, the determinant is hard coded based on pre-computed cofactor expansion, and uses no loops. Of course, the addition and multiplication must still be done.

#### func (Mat4) Diag ¶

Diag is a basic operation on a square matrix that simply returns main diagonal (meaning all elements such that row==col).

#### func (Mat4) Index ¶

#### func (Mat4) Inv ¶

Inv computes the inverse of a square matrix. An inverse is a square matrix such that when multiplied by the original, yields the identity.

M_inv * M = M * M_inv = I

In this library, the math is precomputed, and uses no loops, though the multiplications, additions, determinant calculation, and scaling are still done. This can still be (relatively) expensive for a 4x4.

This function checks the determinant to see if the matrix is invertible. If the determinant is 0.0, this function returns the zero matrix. However, due to floating point errors, it is entirely plausible to get a false positive or negative. In the future, an alternate function may be written which takes in a pre-computed determinant.

#### func (Mat4) Mul ¶

#### func (Mat4) Mul4 ¶

Mul4 performs a "matrix product" between this matrix and another of the given dimension. For any two matrices of dimensionality MxN and NxO, the result will be MxO. For instance, Mat4 multiplied using Mul4x2 will result in a Mat4x2.

#### func (Mat4) Mul4x1 ¶

Mul4x1 performs a "matrix product" between this matrix and another of the given dimension. For any two matrices of dimensionality MxN and NxO, the result will be MxO. For instance, Mat4 multiplied using Mul4x2 will result in a Mat4x2.

#### func (Mat4) Mul4x2 ¶

Mul4x2 performs a "matrix product" between this matrix and another of the given dimension. For any two matrices of dimensionality MxN and NxO, the result will be MxO. For instance, Mat4 multiplied using Mul4x2 will result in a Mat4x2.

#### func (Mat4) Mul4x3 ¶

Mul4x3 performs a "matrix product" between this matrix and another of the given dimension. For any two matrices of dimensionality MxN and NxO, the result will be MxO. For instance, Mat4 multiplied using Mul4x2 will result in a Mat4x2.

#### func (Mat4) Row ¶

#### func (Mat4) Rows ¶

#### func (*Mat4) Set ¶

#### func (Mat4) Sub ¶

#### func (Mat4) Trace ¶

Trace is a basic operation on a square matrix that simply sums up all elements on the main diagonal (meaning all elements such that row==col).

#### type Mat4x2 ¶

type Mat4x2 [8]float32

#### func Mat4x2FromCols ¶

Mat4x2FromCols builds a new matrix from column vectors.

#### func Mat4x2FromRows ¶

#### func (Mat4x2) Add ¶

#### func (Mat4x2) ApproxEqual ¶

#### func (Mat4x2) ApproxEqualThreshold ¶

#### func (Mat4x2) ApproxFuncEqual ¶

#### func (Mat4x2) At ¶

#### func (Mat4x2) Col ¶

#### func (Mat4x2) Cols ¶

#### func (Mat4x2) Index ¶

#### func (Mat4x2) Mul ¶

#### func (Mat4x2) Mul2 ¶

Mul2 performs a "matrix product" between this matrix and another of the given dimension. For any two matrices of dimensionality MxN and NxO, the result will be MxO. For instance, Mat4 multiplied using Mul4x2 will result in a Mat4x2.

#### func (Mat4x2) Mul2x1 ¶

Mul2x1 performs a "matrix product" between this matrix and another of the given dimension. For any two matrices of dimensionality MxN and NxO, the result will be MxO. For instance, Mat4 multiplied using Mul4x2 will result in a Mat4x2.

#### func (Mat4x2) Mul2x3 ¶

Mul2x3 performs a "matrix product" between this matrix and another of the given dimension. For any two matrices of dimensionality MxN and NxO, the result will be MxO. For instance, Mat4 multiplied using Mul4x2 will result in a Mat4x2.

#### func (Mat4x2) Mul2x4 ¶

Mul2x4 performs a "matrix product" between this matrix and another of the given dimension. For any two matrices of dimensionality MxN and NxO, the result will be MxO. For instance, Mat4 multiplied using Mul4x2 will result in a Mat4x2.

#### func (Mat4x2) Row ¶

#### func (Mat4x2) Rows ¶

#### func (*Mat4x2) Set ¶

#### func (Mat4x2) Sub ¶

#### type Mat4x3 ¶

type Mat4x3 [12]float32

#### func Mat4x3FromCols ¶

Mat4x3FromCols builds a new matrix from column vectors.

#### func Mat4x3FromRows ¶

#### func (Mat4x3) Add ¶

#### func (Mat4x3) ApproxEqual ¶

#### func (Mat4x3) ApproxEqualThreshold ¶

#### func (Mat4x3) ApproxFuncEqual ¶

#### func (Mat4x3) At ¶

#### func (Mat4x3) Col ¶

#### func (Mat4x3) Cols ¶

#### func (Mat4x3) Index ¶

#### func (Mat4x3) Mul ¶

#### func (Mat4x3) Mul3 ¶

Mul3 performs a "matrix product" between this matrix and another of the given dimension. For any two matrices of dimensionality MxN and NxO, the result will be MxO. For instance, Mat4 multiplied using Mul4x2 will result in a Mat4x2.

#### func (Mat4x3) Mul3x1 ¶

Mul3x1 performs a "matrix product" between this matrix and another of the given dimension. For any two matrices of dimensionality MxN and NxO, the result will be MxO. For instance, Mat4 multiplied using Mul4x2 will result in a Mat4x2.

#### func (Mat4x3) Mul3x2 ¶

Mul3x2 performs a "matrix product" between this matrix and another of the given dimension. For any two matrices of dimensionality MxN and NxO, the result will be MxO. For instance, Mat4 multiplied using Mul4x2 will result in a Mat4x2.

#### func (Mat4x3) Mul3x4 ¶

Mul3x4 performs a "matrix product" between this matrix and another of the given dimension. For any two matrices of dimensionality MxN and NxO, the result will be MxO. For instance, Mat4 multiplied using Mul4x2 will result in a Mat4x2.

#### func (Mat4x3) Row ¶

#### func (Mat4x3) Rows ¶

#### func (*Mat4x3) Set ¶

#### func (Mat4x3) Sub ¶

#### type MatMxN ¶

```
type MatMxN struct {
// contains filtered or unexported fields
}
```

MatMxN is an arbitrary mxn matrix backed by a slice of floats.

This is emphatically not recommended for hardcore n-dimensional linear algebra. For that purpose I recommend github.com/gonum/matrix or well-tested C libraries such as BLAS or LAPACK.

This is meant to complement future algorithms that may require matrices larger than 4x4, but still relatively small (e.g. Jacobeans for inverse kinematics).

It makes use of the same memory sync.Pool set that VecN does, with the same sizing rules.

MatMN will always check if the receiver is nil on any method. Meaning MathMN(nil).Add(dst,m2) should always work. Except for the Reshape function, the semantics of this is to "propogate" nils forward, so if an invalid operation occurs in a long chain of matrix operations, the overall result will be nil.

#### func DiagN ¶

DiagN creates an NxN diagonal matrix seeded by the diagonal vector diag. Meaning: for all entries, where i==j, dst.At(i,j) = diag[i]. Otherwise dst.At(i,j) = 0

This reshapes dst to the correct size, returning/grabbing from the memory pool as necessary.

#### func NewMatrixFromData ¶

NewMatrixFromData returns a matrix with data specified by the data in src

For instance, to create a 3x3 MatMN from a Mat3

m1 := mgl32.Rotate3DX(3.14159) mat := mgl32.NewBackedMatrix(m1[:],3,3)

will create an MN matrix matching the data in the original rotation matrix. This matrix is NOT backed by the initial slice; it's a copy of the data

If m*n > cap(src), this function will panic.

#### func (*MatMxN) ApproxEqual ¶

ApproxEqual returns whether the two vectors are approximately equal (See FloatEqual).

#### func (*MatMxN) ApproxEqualFunc ¶

ApproxEqualFunc returns whether the two vectors are approximately equal, given a function which compares two scalar elements.

#### func (*MatMxN) ApproxEqualThreshold ¶

ApproxEqualThreshold returns whether the two vectors are approximately equal to within the given threshold given by "epsilon" (See ApproxEqualThreshold).

#### func (*MatMxN) At ¶

At returns the element at the given row and column. This is garbage in/garbage out and does no bounds checking. If the computation happens to lead to an invalid element, it will be returned; or it may panic.

#### func (*MatMxN) InferMatrix ¶

InferMatrix infers an MxN matrix from a constant matrix from this package. For instance, a Mat2x3 inferred with this function will work just like NewMatrixFromData(m[:],2,3) where m is the Mat2x3. This uses a type switch.

I personally recommend using NewMatrixFromData, because it avoids a potentially costly type switch. However, this is also more robust and less error prone if you change the size of your matrix somewhere.

If the value passed in is not recognized, it returns an InferMatrixError.

#### func (*MatMxN) Mul ¶

Mul performs a scalar multiplication between mat and some constant c, storing the result in dst. Mat and dst can be equal. If dst is not the correct size, a Reshape will occur.

#### func (*MatMxN) MulMxN ¶

MulMxN performs matrix multiplication on MxN matrix mat and NxO matrix mul, storing the result in dst. This returns dst, or nil if the operation is not able to be performed.

If mat == dst, or mul == dst a temporary matrix will be used.

This uses the naive algorithm (though on smaller matrices, this can actually be faster; about len(mat)+len(mul) < ~100)

#### func (*MatMxN) MulNx1 ¶

MulNx1 multiplies the matrix by a vector of size n. If mat or v is nil, this returns nil. If the number of columns in mat does not match the Size of v, this also returns nil.

Dst will be resized if it's not big enough. If dst == v; a temporary vector will be allocated and returned via the realloc callback when complete.

#### func (*MatMxN) NumRowCols ¶

NumRowCols returns the number of rows and columns in this matrix as a single operation

#### func (*MatMxN) Reshape ¶

Reshape reshapes the matrix to the desired dimensions. If the overall size of the new matrix (m*n) is bigger than the current size, the underlying slice will be grown, sending the current slice to the memory pool and grabbing a bigger one if necessary

If the caller is a nil pointer, the return value will be a new matrix, as if NewMatrix(m,n) had been called. Otherwise it's simply the caller.

#### func (*MatMxN) Set ¶

Set sets the element at the given row and column. This is garbage in/garbage out and does no bounds checking. If the computation happens to lead to an invalid element, it will be set; or it may panic.

#### func (*MatMxN) Trace ¶

Trace returns the trace of a square matrix (sum of all diagonal elements). If the matrix is nil, or not square, the result will be NaN.

#### func (*MatMxN) Transpose ¶

Transpose takes the transpose of mat and puts it in dst.

If dst is not of the correct dimensions, it will be Reshaped, if dst and mat are the same, a temporary matrix of the correct size will be allocated; these resources will be released via the memory pool.

This should be improved in the future.

#### type NilMatrixError ¶

type NilMatrixError struct{}

NilMatrixError is returned when an operand to a function was unexpectedly 'nil'.

#### func (NilMatrixError) Error ¶

func (me NilMatrixError) Error() string

#### type Quat ¶

Quat represents a Quaternion, which is an extension of the imaginary numbers; there's all sorts of interesting theory behind it. In 3D graphics we mostly use it as a cheap way of representing rotation since quaternions are cheaper to multiply by, and easier to interpolate than matrices.

A Quaternion has two parts: W, the so-called scalar component, and "V", the vector component. The vector component is considered to be the part in 3D space, while W (loosely interpreted) is its 4D coordinate.

#### func AnglesToQuat ¶

func AnglesToQuat(angle1, angle2, angle3 float32, order RotationOrder) Quat

AnglesToQuat performs a rotation in the specified order. If the order is not a valid RotationOrder, this function will panic

The rotation "order" is more of an axis descriptor. For instance XZX would tell the function to interpret angle1 as a rotation about the X axis, angle2 about the Z axis, and angle3 about the X axis again.

Based off the code for the Matlab function "angle2quat", though this implementation only supports 3 single angles as opposed to multiple angles.

#### func Mat4ToQuat ¶

Mat4ToQuat converts a pure rotation matrix into a quaternion

#### func QuatBetweenVectors ¶

QuatBetweenVectors calculates the rotation between two vectors

#### func QuatIdent ¶

func QuatIdent() Quat

QuatIdent returns the quaternion identity: W=1; V=(0,0,0).

As with all identities, multiplying any quaternion by this will yield the same quaternion you started with.

#### func QuatLerp ¶

QuatLerp is a *L*inear Int*erp*olation between two Quaternions, cheap and simple.

Not excessively useful, but uses can be found.

#### func QuatLookAtV ¶

QuatLookAtV creates a rotation from an eye vector to a center vector

It assumes the front of the rotated object at Z- and up at Y+

#### func QuatNlerp ¶

QuatNlerp is a *Normalized* *L*inear Int*erp*olation between two Quaternions. Cheaper than Slerp and usually just as good. This is literally Lerp with Normalize() called on it.

Unlike Slerp, constant velocity isn't maintained, but it's much faster and Nlerp(q1,q2) and Nlerp(q2,q1) return the same path. You should probably use this more often unless you're suffering from choppiness due to the non-constant velocity problem.

#### func QuatRotate ¶

QuatRotate creates an angle from an axis and an angle relative to that axis.

This is cheaper than HomogRotate3D.

#### func QuatSlerp ¶

QuatSlerp is *S*pherical *L*inear Int*erp*olation, a method of interpolating between two quaternions. This always takes the straightest path on the sphere between the two quaternions, and maintains constant velocity.

However, it's expensive and QuatSlerp(q1,q2) is not the same as QuatSlerp(q2,q1)

#### func (Quat) Add ¶

Add adds two quaternions. It's no more complicated than adding their W and V components.

#### func (Quat) ApproxEqual ¶

ApproxEqual returns whether the quaternions are approximately equal, as if FloatEqual was called on each matching element

#### func (Quat) ApproxEqualFunc ¶

ApproxEqualFunc returns whether the quaternions are approximately equal using the given comparison function, as if the function had been called on each individual element

#### func (Quat) ApproxEqualThreshold ¶

ApproxEqualThreshold returns whether the quaternions are approximately equal with a given tolerence, as if FloatEqualThreshold was called on each matching element with the given epsilon

#### func (Quat) Conjugate ¶

Conjugate returns the conjugate of a quaternion. Equivalent to Quat{q1.W, q1.V.Mul(-1)}.

#### func (Quat) Inverse ¶

Inverse of a quaternion. The inverse is equivalent to the conjugate divided by the square of the length.

This method computes the square norm by directly adding the sum of the squares of all terms instead of actually squaring q1.Len(), both for performance and precision.

#### func (Quat) Len ¶

Len gives the Length of the quaternion, also known as its Norm. This is the same thing as the Len of a Vec4.

#### func (Quat) Mul ¶

Mul multiplies two quaternions. This can be seen as a rotation. Note that Multiplication is NOT commutative, meaning q1.Mul(q2) does not necessarily equal q2.Mul(q1).

#### func (Quat) Normalize ¶

Normalize the quaternion, returning its versor (unit quaternion).

This is the same as normalizing it as a Vec4.

#### func (Quat) OrientationEqual ¶

OrientationEqual returns whether the quaternions represents the same orientation

Different values can represent the same orientation (q == -q) because quaternions avoid singularities and discontinuities involved with rotation in 3 dimensions by adding extra dimensions

#### func (Quat) OrientationEqualThreshold ¶

OrientationEqualThreshold returns whether the quaternions represents the same orientation with a given tolerence

#### func (Quat) Rotate ¶

Rotate a vector by the rotation this quaternion represents. This will result in a 3D vector. Strictly speaking, this is equivalent to q1.v.q* where the "."" is quaternion multiplication and v is interpreted as a quaternion with W 0 and V v. In code: q1.Mul(Quat{0,v}).Mul(q1.Conjugate()), and then retrieving the imaginary (vector) part.

In practice, we hand-compute this in the general case and simplify to save a few operations.

#### type RectangularMatrixError ¶

type RectangularMatrixError struct{}

RectangularMatrixError is returned when a rectangular matrix was expected but not given.

#### func (RectangularMatrixError) Error ¶

func (mse RectangularMatrixError) Error() string

#### type RotationOrder ¶

type RotationOrder int

RotationOrder is the order in which rotations will be transformed for the purposes of AnglesToQuat.

const ( XYX RotationOrder = iota XYZ XZX XZY YXY YXZ YZY YZX ZYZ ZYX ZXZ ZXY )

The RotationOrder constants represent a series of rotations along the given axes for the use of AnglesToQuat.

#### type Vec2 ¶

#### func BezierCurve2D ¶

BezierCurve2D returns the point at point t along an n-control point Bezier curve

t must be in the range 0.0 and 1.0 or this function will panic. Consider [0.0,1.0] to be similar to a percentage, 0.0 is first control point, and the point at 1.0 is the last control point. Any point in between is how far along the path you are between 0 and 1.

This function is not sensitive to the coordinate system of the control points. It will correctly interpolate regardless of whether they're in screen coords, gl coords, or something else entirely

#### func BezierSplineInterpolate2D ¶

BezierSplineInterpolate2D does interpolation over a spline of several bezier curves. Each bezier curve must have a finite range, though the spline may be disjoint. The bezier curves are not required to be in any particular order.

If t is out of the range of all given curves, this function will panic

#### func Circle ¶

Circle generates a circle centered at (0,0) with a given radius. The radii are assumed to be in GL's coordinate sizing.

Technically this draws an ellipse with two axes that match with the X and Y axes, the reason it has a radiusX and radiusY is because GL's coordinate system is proportional to screen width and screen height. So if you have a non-square viewport, a single radius will appear to "squash" the circle in one direction (usually the Y direction), so the X and Y radius allow for a circle to be made. A good way to get the correct radii is with mathgl.ScreenToGLCoords(radius, radius, screenWidth, screenHeight) which will get you the correct proportional GL coords.

The numSlices argument specifies how many triangles you want your circle divided into, setting this number to too low a value may cause problem (and too high will cause it to take a lot of memory and time to compute without much gain in resolution).

This uses discrete triangles, not a triangle fan

#### func CubicBezierCurve2D ¶

CubicBezierCurve2D interpolates the point t on the given bezier curve.

#### func MakeBezierCurve2D ¶

MakeBezierCurve2D generates a bezier curve with controlPoints cPoints. The numPoints argument determines how many "samples" it makes along the line. For instance, a call to this with numPoints 2 will have exactly two points: the start and end points For any points above 2 it will divide it into numPoints-1 chunks (which means it will generate numPoints-2 vertices other than the beginning and end). So for 3 points it will divide it in half, 4 points into thirds, and so on.

This is likely to get rather expensive for anything over perhaps a cubic curve.

#### func QuadraticBezierCurve2D ¶

QuadraticBezierCurve2D interpolates the point t on the given bezier curve.

#### func Rect ¶

Rect generates a 2-triangle rectangle for use with GL_TRIANGLES. The width and height should use GL's proportions (that is, where a width of 1.0 is equivalent to half of the width of the render target); however, the y-coordinates grow downwards, not upwards. That is, it assumes you want the origin of the rectangle with the top-left corner at (0.0,0.0).

Keep in mind that GL's coordinate system is proportional, so width=height will not result in a square unless your viewport is square. If you want to maintain proportionality regardless of screen size, use the results of w,h := ScreenToGLCoordsf(absoluteWidth, absoluteHeight, screenWidth, screenHeight); w,h=w+1,h-1 in the call to this function. (The w+1,h-1 step maps the coordinates to start at 0.0 rather than -1.0)

#### func (Vec2) Add ¶

Add performs element-wise addition between two vectors. It is equivalent to iterating over every element of v1 and adding the corresponding element of v2 to it.

#### func (Vec2) ApproxEqual ¶

ApproxEqual takes in a vector and does an element-wise approximate float comparison as if FloatEqual had been used

#### func (Vec2) ApproxEqualThreshold ¶

ApproxEqualThreshold takes in a threshold for comparing two floats, and uses it to do an element-wise comparison of the vector to another.

#### func (Vec2) ApproxFuncEqual ¶

ApproxFuncEqual takes in a func that compares two floats, and uses it to do an element-wise comparison of the vector to another. This is intended to be used with FloatEqualFunc

#### func (Vec2) Dot ¶

Dot returns the dot product of this vector with another. There are multiple ways to describe this value. One is the multiplication of their lengths and cos(theta) where theta is the angle between the vectors: v1.v2 = |v1||v2|cos(theta).

The other (and what is actually done) is the sum of the element-wise multiplication of all elements. So for instance, two Vec3s would yield v1.x * v2.x + v1.y * v2.y + v1.z * v2.z.

This means that the dot product of a vector and itself is the square of its Len (within the bounds of floating points error).

The dot product is roughly a measure of how closely two vectors are to pointing in the same direction. If both vectors are normalized, the value will be -1 for opposite pointing, one for same pointing, and 0 for perpendicular vectors.

#### func (Vec2) Len ¶

Len returns the vector's length. Note that this is NOT the dimension of the vector (len(v)), but the mathematical length. This is equivalent to the square root of the sum of the squares of all elements. E.G. for a Vec2 it's math.Hypot(v[0], v[1]).

#### func (Vec2) LenSqr ¶

LenSqr returns the vector's square length. This is equivalent to the sum of the squares of all elements.

#### func (Vec2) Mul ¶

Mul performs a scalar multiplication between the vector and some constant value c. This is equivalent to iterating over every vector element and multiplying by c.

#### func (Vec2) Normalize ¶

Normalize normalizes the vector. Normalization is (1/|v|)*v, making this equivalent to v.Scale(1/v.Len()). If the len is 0.0, this function will return an infinite value for all elements due to how floating point division works in Go (n/0.0 = math.Inf(Sign(n))).

Normalization makes a vector's Len become 1.0 (within the margin of floating point error), while maintaining its directionality.

(Can be seen here: http://play.golang.org/p/Aaj7SnbqIp )

#### func (Vec2) OuterProd2 ¶

OuterProd2 does the vector outer product of two vectors. The outer product produces an 2x2 matrix. E.G. a Vec2 * Vec2 = Mat2.

The outer product can be thought of as the "opposite" of the Dot product. The Dot product treats both vectors like matrices oriented such that the left one has N columns and the right has N rows. So Vec3.Vec3 = Mat1x3*Mat3x1 = Mat1 = Scalar.

The outer product orients it so they're facing "outward": Vec2*Vec3 = Mat2x1*Mat1x3 = Mat2x3.

#### func (Vec2) OuterProd3 ¶

OuterProd3 does the vector outer product of two vectors. The outer product produces an 2x3 matrix. E.G. a Vec2 * Vec3 = Mat2x3.

The outer product can be thought of as the "opposite" of the Dot product. The Dot product treats both vectors like matrices oriented such that the left one has N columns and the right has N rows. So Vec3.Vec3 = Mat1x3*Mat3x1 = Mat1 = Scalar.

The outer product orients it so they're facing "outward": Vec2*Vec3 = Mat2x1*Mat1x3 = Mat2x3.

#### func (Vec2) OuterProd4 ¶

OuterProd4 does the vector outer product of two vectors. The outer product produces an 2x4 matrix. E.G. a Vec2 * Vec4 = Mat2x4.

The outer product can be thought of as the "opposite" of the Dot product. The Dot product treats both vectors like matrices oriented such that the left one has N columns and the right has N rows. So Vec3.Vec3 = Mat1x3*Mat3x1 = Mat1 = Scalar.

The outer product orients it so they're facing "outward": Vec2*Vec3 = Mat2x1*Mat1x3 = Mat2x3.

#### func (Vec2) Sub ¶

Sub performs element-wise subtraction between two vectors. It is equivalent to iterating over every element of v1 and subtracting the corresponding element of v2 from it.

#### func (Vec2) X ¶

X is an element access func, it is equivalent to v[n] where n is some valid index. The mappings are XYZW (X=0, Y=1 etc). Benchmarks show that this is more or less as fast as direct acces, probably due to inlining, so use v[0] or v.X() depending on personal preference.

#### type Vec3 ¶

#### func BezierCurve3D ¶

BezierCurve3D same as the 2D version, except the line is in 3D space

#### func BezierSplineInterpolate3D ¶

BezierSplineInterpolate3D does interpolation over a spline of several bezier curves. Each bezier curve must have a finite range, though the spline may be disjoint. The bezier curves are not required to be in any particular order.

If t is out of the range of all given curves, this function will panic

#### func BezierSurface ¶

BezierSurface creates a 2-dimensional Bezier surface of arbitrary degree in 3D Space Like the curve functions, if u or v are not in the range [0.0,1.0] the function will panic, use Clamp[f|d] to ensure it is correct.

The control point matrix must not be jagged, or this will end up panicking from an index out of bounds exception

#### func CubicBezierCurve3D ¶

CubicBezierCurve3D interpolates the point t on the given bezier curve.

#### func CylindricalToCartesian ¶

CylindricalToCartesian converts cylindrical coordinates with radial distance r, azimuth phi, and height z to cartesian coordinates (x,y,z)

Angles are in radians.

#### func MakeBezierCurve3D ¶

MakeBezierCurve3D same as the 2D version, except with the line in 3D space.

#### func Project ¶

func Project(obj Vec3, modelview, projection Mat4, initialX, initialY, width, height int) (win Vec3)

Project transforms a set of coordinates from object space (in obj) to window coordinates (with depth).

Window coordinates are continuous, not discrete (well, as continuous as an IEEE Floating Point can be), so you won't get exact pixel locations without rounding or similar

#### func QuadraticBezierCurve3D ¶

QuadraticBezierCurve3D interpolates the point t on the given bezier curve.

#### func SphericalToCartesian ¶

SphericalToCartesian converts spherical coordinates with radius r, inclination theta, and azimuth phi to cartesian coordinates (x,y,z).

Angles are in radians.

#### func TransformCoordinate ¶

TransformCoordinate multiplies a 3D vector by a transformation given by the homogeneous 4D matrix m, applying any translation. If this transformation is non-affine, it will project this vector onto the plane w=1 before returning the result.

This is similar to saying you're transforming and projecting a point.

This is effectively equivalent to the GLSL code

vec4 r = (m * vec4(v,1.)); r = r/r.w; vec3 newV = r.xyz;

#### func TransformNormal ¶

TransformNormal multiplies a 3D vector by a transformation given by the homogeneous 4D matrix m, NOT applying any translations.

This is similar to saying you're applying a transformation to a direction or normal. Rotation still applies (as does scaling), but translating a direction or normal is meaningless.

This is effectively equivalent to the GLSL code

vec4 r = (m * vec4(v,0.)); vec3 newV = r.xyz

#### func UnProject ¶

func UnProject(win Vec3, modelview, projection Mat4, initialX, initialY, width, height int) (obj Vec3, err error)

UnProject transforms a set of window coordinates to object space. If your MVP (projection.Mul(modelview) matrix is not invertible, this will return an error.

Note that the projection may not be perfect if you use strict pixel locations rather than the exact values given by Projectf. (It's still unlikely to be perfect due to precision errors, but it will be closer)

#### func (Vec3) Add ¶

Add performs element-wise addition between two vectors. It is equivalent to iterating over every element of v1 and adding the corresponding element of v2 to it.

#### func (Vec3) ApproxEqual ¶

ApproxEqual takes in a vector and does an element-wise approximate float comparison as if FloatEqual had been used

#### func (Vec3) ApproxEqualThreshold ¶

ApproxEqualThreshold takes in a threshold for comparing two floats, and uses it to do an element-wise comparison of the vector to another.

#### func (Vec3) ApproxFuncEqual ¶

ApproxFuncEqual takes in a func that compares two floats, and uses it to do an element-wise comparison of the vector to another. This is intended to be used with FloatEqualFunc

#### func (Vec3) Cross ¶

Cross is the vector cross product. This operation is only defined on 3D vectors. It is equivalent to Vec3{v1[1]*v2[2]-v1[2]*v2[1], v1[2]*v2[0]-v1[0]*v2[2], v1[0]*v2[1] - v1[1]*v2[0]}. Another interpretation is that it's the vector whose magnitude is |v1||v2|sin(theta) where theta is the angle between v1 and v2.

The cross product is most often used for finding surface normals. The cross product of vectors will generate a vector that is perpendicular to the plane they form.

Technically, a generalized cross product exists as an "(N-1)ary" operation (that is, the 4D cross product requires 3 4D vectors). But the binary 3D (and 7D) cross product is the most important. It can be considered the area of a parallelogram with sides v1 and v2.

Like the dot product, the cross product is roughly a measure of directionality. Two normalized perpendicular vectors will return a vector with a magnitude of 1.0 or -1.0 and two parallel vectors will return a vector with magnitude 0.0. The cross product is "anticommutative" meaning v1.Cross(v2) = -v2.Cross(v1), this property can be useful to know when finding normals, as taking the wrong cross product can lead to the opposite normal of the one you want.

#### func (Vec3) Dot ¶

Dot returns the dot product of this vector with another. There are multiple ways to describe this value. One is the multiplication of their lengths and cos(theta) where theta is the angle between the vectors: v1.v2 = |v1||v2|cos(theta).

The other (and what is actually done) is the sum of the element-wise multiplication of all elements. So for instance, two Vec3s would yield v1.x * v2.x + v1.y * v2.y + v1.z * v2.z.

This means that the dot product of a vector and itself is the square of its Len (within the bounds of floating points error).

The dot product is roughly a measure of how closely two vectors are to pointing in the same direction. If both vectors are normalized, the value will be -1 for opposite pointing, one for same pointing, and 0 for perpendicular vectors.

#### func (Vec3) Len ¶

Len returns the vector's length. Note that this is NOT the dimension of the vector (len(v)), but the mathematical length. This is equivalent to the square root of the sum of the squares of all elements. E.G. for a Vec2 it's math.Hypot(v[0], v[1]).

#### func (Vec3) LenSqr ¶

LenSqr returns the vector's square length. This is equivalent to the sum of the squares of all elements.

#### func (Vec3) Mul ¶

Mul performs a scalar multiplication between the vector and some constant value c. This is equivalent to iterating over every vector element and multiplying by c.

#### func (Vec3) Normalize ¶

Normalize normalizes the vector. Normalization is (1/|v|)*v, making this equivalent to v.Scale(1/v.Len()). If the len is 0.0, this function will return an infinite value for all elements due to how floating point division works in Go (n/0.0 = math.Inf(Sign(n))).

Normalization makes a vector's Len become 1.0 (within the margin of floating point error), while maintaining its directionality.

(Can be seen here: http://play.golang.org/p/Aaj7SnbqIp )

#### func (Vec3) OuterProd2 ¶

OuterProd2 does the vector outer product of two vectors. The outer product produces an 3x2 matrix. E.G. a Vec3 * Vec2 = Mat3x2.

The outer product orients it so they're facing "outward": Vec2*Vec3 = Mat2x1*Mat1x3 = Mat2x3.

#### func (Vec3) OuterProd3 ¶

OuterProd3 does the vector outer product of two vectors. The outer product produces an 3x3 matrix. E.G. a Vec3 * Vec3 = Mat3.

The outer product orients it so they're facing "outward": Vec2*Vec3 = Mat2x1*Mat1x3 = Mat2x3.

#### func (Vec3) OuterProd4 ¶

OuterProd4 does the vector outer product of two vectors. The outer product produces an 3x4 matrix. E.G. a Vec3 * Vec4 = Mat3x4.

The outer product orients it so they're facing "outward": Vec2*Vec3 = Mat2x1*Mat1x3 = Mat2x3.

#### func (Vec3) Sub ¶

Sub performs element-wise subtraction between two vectors. It is equivalent to iterating over every element of v1 and subtracting the corresponding element of v2 from it.

#### func (Vec3) X ¶

X is an element access func, it is equivalent to v[n] where n is some valid index. The mappings are XYZW (X=0, Y=1 etc). Benchmarks show that this is more or less as fast as direct acces, probably due to inlining, so use v[0] or v.X() depending on personal preference.

#### func (Vec3) Y ¶

Y is an element access func, it is equivalent to v[n] where n is some valid index. The mappings are XYZW (X=0, Y=1 etc). Benchmarks show that this is more or less as fast as direct acces, probably due to inlining, so use v[0] or v.X() depending on personal preference.

#### type Vec4 ¶

#### func (Vec4) Add ¶

Add performs element-wise addition between two vectors. It is equivalent to iterating over every element of v1 and adding the corresponding element of v2 to it.

#### func (Vec4) ApproxEqual ¶

ApproxEqual takes in a vector and does an element-wise approximate float comparison as if FloatEqual had been used

#### func (Vec4) ApproxEqualThreshold ¶

ApproxEqualThreshold takes in a threshold for comparing two floats, and uses it to do an element-wise comparison of the vector to another.

#### func (Vec4) ApproxFuncEqual ¶

ApproxFuncEqual takes in a func that compares two floats, and uses it to do an element-wise comparison of the vector to another. This is intended to be used with FloatEqualFunc

#### func (Vec4) Dot ¶

Dot returns the dot product of this vector with another. There are multiple ways to describe this value. One is the multiplication of their lengths and cos(theta) where theta is the angle between the vectors: v1.v2 = |v1||v2|cos(theta).

The other (and what is actually done) is the sum of the element-wise multiplication of all elements. So for instance, two Vec3s would yield v1.x * v2.x + v1.y * v2.y + v1.z * v2.z.

This means that the dot product of a vector and itself is the square of its Len (within the bounds of floating points error).

The dot product is roughly a measure of how closely two vectors are to pointing in the same direction. If both vectors are normalized, the value will be -1 for opposite pointing, one for same pointing, and 0 for perpendicular vectors.

#### func (Vec4) Len ¶

Len returns the vector's length. Note that this is NOT the dimension of the vector (len(v)), but the mathematical length. This is equivalent to the square root of the sum of the squares of all elements. E.G. for a Vec2 it's math.Hypot(v[0], v[1]).

#### func (Vec4) LenSqr ¶

LenSqr returns the vector's square length. This is equivalent to the sum of the squares of all elements.

#### func (Vec4) Mul ¶

Mul performs a scalar multiplication between the vector and some constant value c. This is equivalent to iterating over every vector element and multiplying by c.

#### func (Vec4) Normalize ¶

Normalize normalizes the vector. Normalization is (1/|v|)*v, making this equivalent to v.Scale(1/v.Len()). If the len is 0.0, this function will return an infinite value for all elements due to how floating point division works in Go (n/0.0 = math.Inf(Sign(n))).

Normalization makes a vector's Len become 1.0 (within the margin of floating point error), while maintaining its directionality.

(Can be seen here: http://play.golang.org/p/Aaj7SnbqIp )

#### func (Vec4) OuterProd2 ¶

OuterProd2 does the vector outer product of two vectors. The outer product produces an 4x2 matrix. E.G. a Vec4 * Vec2 = Mat4x2.

The outer product orients it so they're facing "outward": Vec2*Vec3 = Mat2x1*Mat1x3 = Mat2x3.

#### func (Vec4) OuterProd3 ¶

OuterProd3 does the vector outer product of two vectors. The outer product produces an 4x3 matrix. E.G. a Vec4 * Vec3 = Mat4x3.

The outer product orients it so they're facing "outward": Vec2*Vec3 = Mat2x1*Mat1x3 = Mat2x3.

#### func (Vec4) OuterProd4 ¶

OuterProd4 does the vector outer product of two vectors. The outer product produces an 4x4 matrix. E.G. a Vec4 * Vec4 = Mat4.

The outer product orients it so they're facing "outward": Vec2*Vec3 = Mat2x1*Mat1x3 = Mat2x3.

#### func (Vec4) Quat ¶

Quat reinterprets this vector as a quaternion, with the individual elements staying the same.

#### func (Vec4) Sub ¶

Sub performs element-wise subtraction between two vectors. It is equivalent to iterating over every element of v1 and subtracting the corresponding element of v2 from it.

#### func (Vec4) W ¶

W is an element access func, it is equivalent to v[n] where n is some valid index. The mappings are XYZW (X=0, Y=1 etc). Benchmarks show that this is more or less as fast as direct acces, probably due to inlining, so use v[0] or v.X() depending on personal preference.

#### func (Vec4) X ¶

X is an element access func, it is equivalent to v[n] where n is some valid index. The mappings are XYZW (X=0, Y=1 etc). Benchmarks show that this is more or less as fast as direct acces, probably due to inlining, so use v[0] or v.X() depending on personal preference.

#### func (Vec4) Y ¶

Y is an element access func, it is equivalent to v[n] where n is some valid index. The mappings are XYZW (X=0, Y=1 etc). Benchmarks show that this is more or less as fast as direct acces, probably due to inlining, so use v[0] or v.X() depending on personal preference.

#### type VecN ¶

```
type VecN struct {
// contains filtered or unexported fields
}
```

VecN represents a vector of N elements backed by a slice.

As with MatMxN, this is not for hardcore linear algebra with large dimensions. Use github.com/gonum/matrix or something like BLAS/LAPACK for that. This is for corner cases in 3D math where you require something a little bigger that 4D, but still relatively small.

This VecN uses several sync.Pool objects as a memory pool. The rule is that for any sized vector, the backing slice has CAPACITY (not length) of 2^p where p is Ceil(log_2(N)) -- or in other words, rounding up the base-2 log of the size of the vector. E.G. a VecN of size 17 will have a backing slice of Cap 32.

#### func NewVecNFromData ¶

NewVecNFromData creates a new vector with a backing slice filled with the contents of initial. It is NOT backed by initial, but rather a slice with cap 2^p where p is Ceil(log_2(len(initial))), with the data from initial copied into it.

#### func (*VecN) Add ¶

Add adds vn and addend, storing the result in dst. If dst does not have sufficient size it will be resized Dst may be one of the other arguments. If dst is nil, it will be allocated. The value returned is dst, for easier method chaining

If vn and addend are not the same size, this function will add min(vn.Size(), addend.Size()) elements.

#### func (*VecN) ApproxEqual ¶

ApproxEqual returns whether the two vectors are approximately equal (See FloatEqual).

#### func (*VecN) ApproxEqualFunc ¶

ApproxEqualFunc returns whether the two vectors are approximately equal, given a function which compares two scalar elements.

#### func (*VecN) ApproxEqualThreshold ¶

ApproxEqualThreshold returns whether the two vectors are approximately equal to within the given threshold given by "epsilon" (See ApproxEqualThreshold).

#### func (*VecN) Cross ¶

Cross takes the binary cross product of vn and other, and stores it in dst. If either vn or other are not of size 3 this function will panic

If dst is not of sufficient size, or is nil, a new slice is allocated. Dst is permitted to be one of the other arguments

#### func (*VecN) Dot ¶

Dot computes the dot product of two VecNs, if the two vectors are not of the same length -- this will return NaN.

#### func (VecN) Get ¶

Get the element at index i from the vector. This does not bounds check, and will panic if i is out of range.

#### func (*VecN) Len ¶

Len computes the vector length (also called the Norm) of the vector. Equivalent to math.Sqrt(vn.Dot(vn)) with the appropriate type conversions.

If vn is nil, this returns NaN

#### func (*VecN) LenSqr ¶

#### func (*VecN) Mul ¶

Mul multiplies the vector by some scalar value and stores the result in dst, which will be returned. Dst will be appropriately resized to the size of vn.

The destination can be vn itself and nothing will go wrong.

#### func (*VecN) Normalize ¶

Normalize the vector and stores the result in dst, which will be returned. Dst will be appropraitely resized to the size of vn.

The destination can be vn itself and nothing will go wrong.

This is equivalent to vn.Mul(dst, 1/vn.Len())

#### func (*VecN) OuterProd ¶

OuterProd performs the vector outer product between vn and v2. The outer product is like a "reverse" dot product. Where the dot product aligns both vectors with the "sized" part facing "inward" (Vec3*Vec3=Mat1x3*Mat3x1=Mat1x1=Scalar). The outer product multiplied them with it facing "outward" (Vec3*Vec3=Mat3x1*Mat1x3=Mat3x3).

The matrix dst will be Reshaped to the correct size, if vn or v2 are nil, this returns nil.

#### func (VecN) Raw ¶

Raw returns the raw slice backing the VecN

This may be sent back to the memory pool at any time and you aren't advised to rely on this value

#### func (*VecN) Resize ¶

Resize the underlying slice to the desired amount, reallocating or retrieving from the pool if necessary. The values after a Resize cannot be expected to be related to the values before a Resize.

If the caller is a nil pointer, this returns a value as if NewVecN(n) had been called, otherwise it simply returns the caller.

#### func (*VecN) SetBackingSlice ¶

SetBackingSlice sets the vector's backing slice to the given new one.

#### func (*VecN) Size ¶

Size returns the len of the vector's underlying slice. This is not titled Len because it conflicts the package's convention of calling the Norm the Len.

#### func (*VecN) Sub ¶

Sub subtracts addend from vn, storing the result in dst. If dst does not have sufficient size it will be resized Dst may be one of the other arguments. If dst is nil, it will be allocated. The value returned is dst, for easier method chaining

If vn and addend are not the same size, this function will add min(vn.Size(), addend.Size()) elements.