vmath

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: May 26, 2020 License: MIT Imports: 5 Imported by: 9

README

vmath GoDoc

vmath is a standalone vector math library for go, supporting both float32 and int types.

Matrices are stored in column major order.

This library provides 2D, 3D and 4D vector and matrix types with an extensive set of operations and utility functions.
Vectors are both provided for float32 and int.

Additional support for quaternions is also provided.

vmath aims to provide all functionality needed for graphics development (eg. using OpenGL) in a highly performant matter. It therefore also offers basic functionality related to spatial calculations.

Related functionality from the standard math package that go only provides for float64 is available for the float32 type in this package.

This library is inspired by glm, which is typically used by C or C++ projects.

Alternative go packages:

MathGL provides similar functionality for float32 and float64 types, but does not support int.
Besides int vectors, this package is missing some features like geometric utility functions, float32 versions for functionality available in the math package, and a few methods that you might or might not need.

Azul3D is a game engine written in go, that contains its own math functions in the sub-package github.com/azul3d/engine/lmath.
However, Azul3D uses float64 and is also missing some key features (like 2x2 matrices and int vector support).
Furthermore, the subpackage is not intended to be used as a standalone library and Azul3D is also no longer maintained.

Contributions

Feel free to submit bug reports or pull requests for new features, examples or unit tests.

Documentation

Index

Constants

View Source
const Epsilon = 1.0E-6

Epsilon is the default epsilon value for float comparisons.

Variables

This section is empty.

Functions

func AngleDiff

func AngleDiff(fromRad, toRad float32) float32

AngleDiff compares to angles and returns their distance in the range ]-PI, PI].

func CartesianToSpherical

func CartesianToSpherical(pos Vec3f) (float32, float32, float32)

CartesianToSpherical converts cartesian coordinates into spherical coordinates. Returns the radius, azimuth (angle on XY-plane) and inclination.

func Clampf

func Clampf(v, min, max float32) float32

Clampf returns the value v clamped to the range of [min, max].

func Clampi

func Clampi(v, min, max int) int

Clampi returns the value v clamped to the range of [min, max].

func EqualEps

func EqualEps(a, b, epsilon float32) bool

Equalf compares two floats for equality, using the given epsilon as the relative tolerance. Performs a relative difference comparison (see https://floating-point-gui.de/errors/comparison/ and https://stackoverflow.com/q/4915462/2224996)

func Equalf

func Equalf(a, b float32) bool

Equalf compares two floats for equality. Uses the default Epsilon as relative tolerance.

func IsPointOnLeft

func IsPointOnLeft(a, b Vec2f, point Vec2f) bool

IsPointOnLeft returns true if the give point lies to the left of line a->b; If the point lies directly on the line, false is returned.

func IsPointOnLine

func IsPointOnLine(a, b Vec2f, point Vec2f) bool

IsPointOnLine returns true if the give point lies to the line a->b; Uses the default Epsilon as relative tolerance.

func IsPointOnLineEps

func IsPointOnLineEps(a, b Vec2f, point Vec2f, eps float32) bool

IsPointOnLine returns true if the give point lies to the line a->b; Uses the given Epsilon as relative tolerance.

func Lerp

func Lerp(a, b, t float32) float32

Lerp performs a linear interpolation between a and b. The parameter t should be in range [0, 1].

func NormalizeDegrees

func NormalizeDegrees(deg float32) float32

NormalizeDegrees returns the angle in degrees in the range [0, 360[.

func NormalizeRadians

func NormalizeRadians(rad float32) float32

NormalizeRadians returns the angle in radians in the range [0, 2*PI[.

func PointToLineDistance2D

func PointToLineDistance2D(a, b, point Vec2f) float32

PointToLineDistance2D returns the distance between a point and an infinitely long line passing through a and b.

func PointToLineSegmentDistance2D

func PointToLineSegmentDistance2D(a, b, point Vec2f) float32

PointToLineSegmentDistance2D returns the distance between a point and a line segment between a and b.

func ToDegrees

func ToDegrees(rad float32) float32

ToDegrees converts radians into degrees.

func ToRadians

func ToRadians(deg float32) float32

ToRadians converts degrees into radians.

func Wrapf

func Wrapf(v, min, max float32) float32

Wrapf returns the value v in the range of [min, max[ by wrapping it around.

func Wrapi

func Wrapi(v, min, max int) int

Wrapi returns the value v in the range of [min, max[ by wrapping it around.

Types

type Mat2f

type Mat2f [4]float32

Mat2f is a 2x2 float32 matrix. Values are stored in column major order: [<col0>, <col1>]

func Ident2f

func Ident2f() Mat2f

Ident2f returns the 2x2 identity matrix

func Mat2fFromCols

func Mat2fFromCols(col0, col1 Vec2f) Mat2f

Mat2fFromCols creates a new 2x2 matrix from column vectors.

func Mat2fFromRows

func Mat2fFromRows(row0, row1 Vec2f) Mat2f

Mat2fFromRows creates a new 2x2 matrix from row vectors.

func (Mat2f) Add

func (m Mat2f) Add(other Mat2f) Mat2f

Add performs a component-wise addition.

func (Mat2f) AddScalar

func (m Mat2f) AddScalar(s float32) Mat2f

AddScalar performs a component-wise scalar addition.

func (Mat2f) Cell

func (m Mat2f) Cell(row, col int) float32

Cell returns the element at the given row and column.

func (Mat2f) Col

func (m Mat2f) Col(col int) Vec2f

Col returns a vector with the requested column.

func (Mat2f) Cols

func (m Mat2f) Cols() (col0, col1 Vec2f)

Cols returns vectors representing all columns.

func (Mat2f) Det

func (m Mat2f) Det() float32

Det returns the determinant.

func (Mat2f) Diag

func (m Mat2f) Diag() Vec2f

Diag returns the matrix's diagonal values.

func (Mat2f) Equal

func (m Mat2f) Equal(other Mat2f) bool

Equal compares two matrices component-wise. Uses the default Epsilon as relative tolerance.

func (Mat2f) EqualEps

func (m Mat2f) EqualEps(other Mat2f, epsilon float32) bool

Equal compares two matrices component-wise, using the given epsilon as a relative tolerance.

func (Mat2f) Index

func (m Mat2f) Index(row, col int) int

Index returns the cell index with the given row and column.

func (Mat2f) Inverse

func (m Mat2f) Inverse() (Mat2f, bool)

Inverse calculates the inverse matrix. If the matrix cannot be inverted (singular), the identity matrix and false is returned.

func (Mat2f) Mat3f

func (m Mat2f) Mat3f() Mat3f

Mat3f extends the matrix to 3x3. The diagonal cell is set to 1, all other values are 0.

func (Mat2f) Mat4f

func (m Mat2f) Mat4f() Mat4f

Mat4f extends the matrix to 4x4. The diagonal cells are set to 1, all other values are 0.

func (Mat2f) Mul

func (m Mat2f) Mul(other Mat2f) Mat2f

Mul performs a matrix multiplication.

func (Mat2f) MulScalar

func (m Mat2f) MulScalar(s float32) Mat2f

Mul performs a component-wise scalar multiplication.

func (Mat2f) MulVec

func (m Mat2f) MulVec(v Vec2f) Vec2f

MulVec multiples the matrix with a vector.

func (Mat2f) Row

func (m Mat2f) Row(row int) Vec2f

Row returns a vector with the requested row.

func (Mat2f) Rows

func (m Mat2f) Rows() (row0, row1 Vec2f)

Rows returns vectors representing all rows.

func (*Mat2f) Set

func (m *Mat2f) Set(row, col int, v float32)

Set sets a cell value.

func (*Mat2f) SetCol

func (m *Mat2f) SetCol(col int, v Vec2f)

SetCol sets the values within a specific column.

func (*Mat2f) SetRow

func (m *Mat2f) SetRow(row int, v Vec2f)

SetRow sets the values within a specific row.

func (Mat2f) String

func (m Mat2f) String() string

func (Mat2f) Sub

func (m Mat2f) Sub(other Mat2f) Mat2f

Sub performs a component-wise subtraction.

func (Mat2f) SubScalar

func (m Mat2f) SubScalar(s float32) Mat2f

SubScalar performs a component-wise scalar subtraction.

func (Mat2f) Transpose

func (m Mat2f) Transpose() Mat2f

Transpose returns the transposed matrix. Transposing converts between column-major and row-major order.

type Mat3f

type Mat3f [9]float32

Mat3f is a 3x3 float32 matrix. Values are stored in column major order: [<col0>, <col1>, <col2>]

0, 3, 6 1, 4, 7 2, 5, 8

func Ident3f

func Ident3f() Mat3f

Ident3f returns the 3x3 identity matrix.

func Mat3fFromCols

func Mat3fFromCols(col0, col1, col2 Vec3f) Mat3f

Mat3fFromCols creates a new 3x3 matrix from column vectors.

func Mat3fFromRows

func Mat3fFromRows(row0, row1, row2 Vec3f) Mat3f

Mat3fFromCols creates a new 3x3 matrix from row vectors.

func (Mat3f) Add

func (m Mat3f) Add(other Mat3f) Mat3f

Add performs a component-wise addition.

func (Mat3f) AddScalar

func (m Mat3f) AddScalar(s float32) Mat3f

AddScalar performs a component-wise scalar addition.

func (Mat3f) Cell

func (m Mat3f) Cell(row, col int) float32

Cell returns the element at the given row and column.

func (Mat3f) Col

func (m Mat3f) Col(col int) Vec3f

Row returns a vector with the requested column.

func (Mat3f) Cols

func (m Mat3f) Cols() (col0, col1, col2 Vec3f)

Cols returns vectors representing all columns.

func (Mat3f) Det

func (m Mat3f) Det() float32

Det returns the determinant.

func (Mat3f) Diag

func (m Mat3f) Diag() Vec3f

Diag returns the matrix's diagonal values.

func (Mat3f) Equal

func (m Mat3f) Equal(other Mat3f) bool

Equal compares two matrices component-wise. Uses the default Epsilon as relative tolerance.

func (Mat3f) EqualEps

func (m Mat3f) EqualEps(other Mat3f, epsilon float32) bool

Equal compares two matrices component-wise, using the given epsilon as a relative tolerance.

func (Mat3f) Index

func (m Mat3f) Index(row, col int) int

Index returns the cell index with the given row and column.

func (Mat3f) Inverse

func (m Mat3f) Inverse() (Mat3f, bool)

Inverse calculates the inverse matrix. If the matrix cannot be inverted (singular), the identity matrix and false is returned.

func (Mat3f) InverseTranspose

func (m Mat3f) InverseTranspose() (Mat3f, bool)

InverseTranspose inverts and transposes the matrix in a single step. If the matrix cannot be inverted (singular), the identity matrix and false is returned.

func (Mat3f) Mat2f

func (m Mat3f) Mat2f() Mat2f

Mat2f shrinks the matrix to 2x2. The right column and bottom row are removed.

func (Mat3f) Mat4f

func (m Mat3f) Mat4f() Mat4f

Mat4f extends the matrix to 4x4. The diagonal cell is set to 1, all other values are 0.

func (Mat3f) Mul

func (m Mat3f) Mul(other Mat3f) Mat3f

Mul performs a matrix multiplication.

func (Mat3f) MulScalar

func (m Mat3f) MulScalar(s float32) Mat3f

MulScalar performs a component-wise scalar multiplication.

func (Mat3f) MulVec

func (m Mat3f) MulVec(v Vec3f) Vec3f

MulVec multiples the matrix with a vector.

func (Mat3f) Row

func (m Mat3f) Row(row int) Vec3f

Row returns a vector with the requested row.

func (Mat3f) Rows

func (m Mat3f) Rows() (row0, row1, row2 Vec3f)

Rows returns vectors representing all rows.

func (*Mat3f) Set

func (m *Mat3f) Set(row, col int, v float32)

Set sets a cell value.

func (*Mat3f) SetCol

func (m *Mat3f) SetCol(col int, v Vec3f)

SetCol sets the values within a specific column.

func (*Mat3f) SetRow

func (m *Mat3f) SetRow(row int, v Vec3f)

SetRow sets the values within a specific row.

func (Mat3f) String

func (m Mat3f) String() string

func (Mat3f) Sub

func (m Mat3f) Sub(other Mat3f) Mat3f

Sub performs a component-wise subtraction.

func (Mat3f) SubScalar

func (m Mat3f) SubScalar(s float32) Mat3f

SubScalar performs a component-wise scalar subtraction.

func (Mat3f) Transpose

func (m Mat3f) Transpose() Mat3f

Transpose returns the transposed matrix. Transposing converts between column-major and row-major order.

type Mat4f

type Mat4f [16]float32

Mat4f is a 4x4 float32 matrix. Values are stored in column major order: [<col0>, <col1>, <col2>, <col4>]

0, 4, 8, 12, 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15

func Frustum

func Frustum(left, right, bottom, top float32, near, far float32) Mat4f

Frustum returns a frustum matrix.

func Ident4f

func Ident4f() Mat4f

Ident4f returns the 4x4 identity matrix.

func LookAt

func LookAt(eye, target, up Vec3f) Mat4f

LookAt returns a transformation matrix for a viewer, looking towards the target, with a defined upwards vector.

func Mat4fFromCols

func Mat4fFromCols(col0, col1, col2, col3 Vec4f) Mat4f

Mat4fFromCols creates a new 4x4 matrix from column vectors.

func Mat4fFromRotation

func Mat4fFromRotation(axis Vec3f, rad float32) Mat4f

Mat4fFromRotation creates a new 4x4 matrix, representing a rotation around a given axis.

func Mat4fFromRotationTranslation

func Mat4fFromRotationTranslation(rot Quat, trans Vec3f) Mat4f

Mat4fFromRotationTranslation creates a new 4x4 matrix, representing a rotation and translation.

func Mat4fFromRotationTranslationScale

func Mat4fFromRotationTranslationScale(rot Quat, trans, scale Vec3f) Mat4f

Mat4fFromRotationTranslationScale creates a new 4x4 matrix, representing a rotation, translation and scaling.

func Mat4fFromRotationTranslationScaleOrigin

func Mat4fFromRotationTranslationScaleOrigin(rot Quat, trans, scale, orig Vec3f) Mat4f

Mat4fFromRotationTranslationScale creates a new 4x4 matrix, representing a rotation, translation and scaling. Rotation and scaling is performed around the given origin.

func Mat4fFromRows

func Mat4fFromRows(row0, row1, row2, row3 Vec4f) Mat4f

Mat4fFromRows creates a new 4x4 matrix from row vectors.

func Mat4fFromScaling

func Mat4fFromScaling(scaling Vec3f) Mat4f

Mat4fFromScaling returns a 4x4 matrix with the given scaling.

func Mat4fFromTranslation

func Mat4fFromTranslation(translation Vec3f) Mat4f

Mat4fFromTranslation returns the 4x4 matrix with the given translation vector.

func Mat4fFromXRotation

func Mat4fFromXRotation(rad float32) Mat4f

Mat4fFromXRotation returns the 4x4 matrix with a rotation around the X-axis.

func Mat4fFromYRotation

func Mat4fFromYRotation(rad float32) Mat4f

Mat4fFromYRotation returns the 4x4 matrix with a rotation around the Y-axis.

func Mat4fFromZRotation

func Mat4fFromZRotation(rad float32) Mat4f

Mat4fFromZRotation returns the 4x4 matrix with a rotation around the Z-axis.

func Ortho

func Ortho(left, right, bottom, top float32, near, far float32) Mat4f

Ortho returns an orthographic projection matrix.

func Perspective

func Perspective(fovY, aspectRatio, near, far float32) Mat4f

Perspective returns a perspective projection matrix. The field-of-view is in radians.

func UnOrtho

func UnOrtho(left, right, bottom, top float32, near, far float32) Mat4f

UnOrtho returns an orthographic unprojection matrix.

func (Mat4f) Add

func (m Mat4f) Add(other Mat4f) Mat4f

Add performs a component-wise addition.

func (Mat4f) AddScalar

func (m Mat4f) AddScalar(s float32) Mat4f

AddScalar performs a component-wise scalar addition.

func (Mat4f) Cell

func (m Mat4f) Cell(row, col int) float32

Cell returns the element at the given row and column.

func (Mat4f) Col

func (m Mat4f) Col(col int) Vec4f

Col returns a vector with the requested column.

func (Mat4f) Cols

func (m Mat4f) Cols() (col0, col1, col2, col3 Vec4f)

Cols returns vectors representing all columns.

func (Mat4f) Det

func (m Mat4f) Det() float32

Det returns the determinant.

func (Mat4f) Diag

func (m Mat4f) Diag() Vec4f

Diag returns the matrix's diagonal values.

func (Mat4f) Equal

func (m Mat4f) Equal(other Mat4f) bool

Equal compares two matrices component-wise. Uses the default Epsilon as relative tolerance.

func (Mat4f) EqualEps

func (m Mat4f) EqualEps(other Mat4f, epsilon float32) bool

Equal compares two matrices component-wise, using the given epsilon as a relative tolerance.

func (Mat4f) Index

func (m Mat4f) Index(row, col int) int

Index returns the cell index with the given row and column.

func (Mat4f) Inverse

func (m Mat4f) Inverse() (Mat4f, bool)

Inverse calculates the inverse matrix. If the matrix cannot be inverted (singular), the identity matrix and false is returned.

func (Mat4f) InverseAffine

func (m Mat4f) InverseAffine() (Mat4f, bool)

InverseAffine calculates the inverse of an affine matrix. If the matrix cannot be inverted (singular), the identity matrix and false is returned.

func (Mat4f) InverseTranspose

func (m Mat4f) InverseTranspose() (Mat4f, bool)

InverseTranspose inverts and transposes the matrix in a single step. If the matrix cannot be inverted (singular), the identity matrix and false is returned.

func (Mat4f) IsAffine

func (m Mat4f) IsAffine() bool

IsAffine checks if this is an affine matrix.

func (Mat4f) Mat2f

func (m Mat4f) Mat2f() Mat2f

Mat2f shrinks the matrix to 2x2. The right columns and bottom rows are removed.

func (Mat4f) Mat3f

func (m Mat4f) Mat3f() Mat3f

Mat3f shrinks the matrix to 3x3. The right column and bottom row are removed.

func (Mat4f) Mul

func (m Mat4f) Mul(other Mat4f) Mat4f

Mul performs a matrix multiplication.

func (Mat4f) MulScalar

func (m Mat4f) MulScalar(s float32) Mat4f

MulScalar performs a component-wise scalar multiplication.

func (Mat4f) MulVec

func (m Mat4f) MulVec(v Vec4f) Vec4f

MulVec multiples the matrix with a vector.

func (Mat4f) RotateX

func (m Mat4f) RotateX(rad float32) Mat4f

RotateX rotates the matrix around the X-axis.

func (Mat4f) RotateY

func (m Mat4f) RotateY(rad float32) Mat4f

RotateY rotates the matrix around the Y-axis.

func (Mat4f) RotateZ

func (m Mat4f) RotateZ(rad float32) Mat4f

RotateZ rotates the matrix around the Z-axis.

func (Mat4f) Rotation

func (m Mat4f) Rotation() Quat

Rotation returns a quaternion with the rotation of the matrix.

func (Mat4f) Row

func (m Mat4f) Row(row int) Vec4f

Row returns a vector with the requested row.

func (Mat4f) Rows

func (m Mat4f) Rows() (row0, row1, row2, row3 Vec4f)

Rows returns vectors representing all rows.

func (Mat4f) Scale

func (m Mat4f) Scale(scaling Vec3f) Mat4f

Scale scales the matrix.

func (Mat4f) Scaling

func (m Mat4f) Scaling() Vec3f

Scaling returns the scaling of the matrix.

func (*Mat4f) Set

func (m *Mat4f) Set(row, col int, v float32)

Set sets a cell value.

func (*Mat4f) SetCol

func (m *Mat4f) SetCol(col int, v Vec4f)

SetCol sets the values within a specific column.

func (Mat4f) SetMat3f

func (m Mat4f) SetMat3f(other Mat3f) Mat4f

SetMat3f sets the upper-left 3x3 matrix.

func (*Mat4f) SetRow

func (m *Mat4f) SetRow(row int, v Vec4f)

SetRow sets the values within a specific row.

func (Mat4f) SetScaling

func (m Mat4f) SetScaling(scaling Vec3f) Mat4f

SetScaling sets the scaling of the matrix.

func (Mat4f) SetTranslation

func (m Mat4f) SetTranslation(translation Vec3f) Mat4f

SetTranslation sets the translation vector of the matrix.

func (Mat4f) String

func (m Mat4f) String() string

func (Mat4f) Sub

func (m Mat4f) Sub(other Mat4f) Mat4f

Sub performs a component-wise subtraction.

func (Mat4f) SubScalar

func (m Mat4f) SubScalar(s float32) Mat4f

SubScalar performs a component-wise scalar subtraction.

func (Mat4f) Translate

func (m Mat4f) Translate(translation Vec3f) Mat4f

Translate translates the matrix by the given vector.

func (Mat4f) Translation

func (m Mat4f) Translation() Vec3f

Translation returns the translation vector of the matrix.

func (Mat4f) Transpose

func (m Mat4f) Transpose() Mat4f

Transpose returns the transposed matrix. Transposing converts between column-major and row-major order.

type MatStack4f

type MatStack4f struct {
	// contains filtered or unexported fields
}

MatStack4f represents a stack of 4x4 matrices.

func NewMatStack4f

func NewMatStack4f() *MatStack4f

NewMatStack4f creates a new matrix stack containing only the identity matrix.

func (*MatStack4f) MulLeft

func (m *MatStack4f) MulLeft(mat Mat4f)

MulLeft multiplies the given matrix with the top element and overwrites the top element with the result.

func (*MatStack4f) MulRight

func (m *MatStack4f) MulRight(mat Mat4f)

MulRight multiplies the top element with the given matrix.

func (*MatStack4f) Pop

func (m *MatStack4f) Pop() error

Pop removes the current top element from the stack. Returns an error if the stack contains only one element.

func (*MatStack4f) Push

func (m *MatStack4f) Push()

Push stores the current top on the stack by duplicating it.

func (*MatStack4f) PushIdent

func (m *MatStack4f) PushIdent()

PushIdent is equivalent to Push(), SetIdent().

func (*MatStack4f) PushMulLeft

func (m *MatStack4f) PushMulLeft(mat Mat4f)

PushMulLeft is equivalent to Push(), MulLeft().

func (*MatStack4f) PushMulRight

func (m *MatStack4f) PushMulRight(mat Mat4f)

PushMulRight is equivalent to Push(), MulRight().

func (*MatStack4f) PushSet

func (m *MatStack4f) PushSet(mat Mat4f)

PushSet is equivalent to Push(), Set().

func (*MatStack4f) Set

func (m *MatStack4f) Set(mat Mat4f)

Set overwrites the top element with a new matrix.

func (*MatStack4f) SetIdent

func (m *MatStack4f) SetIdent()

SetIdent overwrites the top element with the identity matrix.

func (MatStack4f) Size

func (m MatStack4f) Size() int

Size returns the current size of the matrix stack

func (MatStack4f) Top

func (m MatStack4f) Top() Mat4f

Top returns the current top element without modifying the stack.

type Quat

type Quat struct {
	W       float32
	X, Y, Z float32
}

Quat represents a Quaternion.

func IdentQuat

func IdentQuat() Quat

IdentQuat returns the identity quaternion.

func QuatFromAxisAngle

func QuatFromAxisAngle(axis Vec3f, rad float32) Quat

QuatFromAxisAngle returns a quaternion representing a rotation around a given axis.

func QuatFromEuler

func QuatFromEuler(yaw, pitch, roll float32) Quat

QuatFromEuler returns a quaternion based on the given euler rotations. Axis: yaw: Z, pitch: Y, roll: X

func (Quat) Add

func (q Quat) Add(other Quat) Quat

Add performs component-wise addition.

func (Quat) AddScalar

func (q Quat) AddScalar(s float32) Quat

AddScalar performs component-wise scalar addition.

func (Quat) Angle

func (q Quat) Angle() float32

Angle returns the quaternion's rotation angle around its axis.

func (Quat) AngleTo

func (q Quat) AngleTo(other Quat) float32

AngleTo returns the angle between two quaternions by comparing one of their axis.

func (Quat) Axis

func (q Quat) Axis() Vec3f

Axis returns the quaternion's rotation axis. The returned axis is not normalized. If there is no rotation, the axis can be zero.

func (Quat) AxisRotation

func (q Quat) AxisRotation() (Vec3f, float32)

AxisRotation returns the quaternion's rotation angle and axis.

func (Quat) Conjugate

func (q Quat) Conjugate() Quat

Conjugate returns the conjugated quaternion. This is a rotation with the same angle, but the axis is mirrored.

func (Quat) Div

func (q Quat) Div(other Quat) Quat

Div performs component-wise division.

func (Quat) DivScalar

func (q Quat) DivScalar(s float32) Quat

DivScalar performs component-wise scalar division.

func (Quat) Dot

func (q Quat) Dot(other Quat) float32

Dot performs a dot product with another quaternion.

func (Quat) Equals

func (q Quat) Equals(other Quat) bool

Equals compares two quaternions. Uses the default Epsilon as relative tolerance.

func (Quat) EqualsEps

func (q Quat) EqualsEps(other Quat, epsilon float32) bool

EqualsEps compares two quaternions, using the given epsilon as a relative tolerance.

func (Quat) Forward

func (q Quat) Forward() Vec3f

Forward returns the forward-vector in the quaternion's coordinate system.

func (Quat) Inverse

func (q Quat) Inverse() Quat

Inverse returns the inverse quaternion. This is the rotation around the same axis, but in the opposite direction.

func (Quat) Length

func (q Quat) Length() float32

Length returns the quaternion's length.

func (Quat) Lerp

func (q Quat) Lerp(other Quat, t float32) Quat

Lerp performs a linear interpolation to another quaternion. The parameter t should be in range [0, 1].

func (Quat) Mat4f

func (q Quat) Mat4f() Mat4f

Mat4f returns a homogeneous 3D rotation matrix based on the quaternion.

func (Quat) Mul

func (q Quat) Mul(other Quat) Quat

Mul performs component-wise multiplication.

func (Quat) MulScalar

func (q Quat) MulScalar(s float32) Quat

MulScalar performs component-wise scalar multiplication.

func (Quat) Normalize

func (q Quat) Normalize() Quat

Normalize the quaternion. The quaternion must be non-zero.

func (Quat) Right

func (q Quat) Right() Vec3f

Right returns the right-vector in the quaternion's coordinate system.

func (Quat) Rotate added in v0.2.1

func (q Quat) Rotate(other Quat) Quat

Rotate multiplies two quaternions, performing a rotation.

func (Quat) RotateVec

func (q Quat) RotateVec(v Vec3f) Vec3f

RotateVec rotates a vector.

func (Quat) RotateX

func (q Quat) RotateX(rad float32) Quat

RotateX rotates the quaternion with a given angle round its X axis.

func (Quat) RotateY

func (q Quat) RotateY(rad float32) Quat

RotateY rotates the quaternion with a given angle round its Y axis.

func (Quat) RotateZ

func (q Quat) RotateZ(rad float32) Quat

RotateZ rotates the quaternion with a given angle round its Y axis.

func (Quat) Slerp

func (q Quat) Slerp(other Quat, t float32) Quat

Slerp performs a spherical linear interpolation to another quaternion. The parameter t should be in range [0, 1].

func (Quat) SquareLength

func (q Quat) SquareLength() float32

SquareLength returns the quaternion's squared length.

func (Quat) String

func (q Quat) String() string

func (Quat) Sub

func (q Quat) Sub(other Quat) Quat

Sub performs component-wise subtraction.

func (Quat) SubScalar

func (q Quat) SubScalar(s float32) Quat

SubScalar performs component-wise scalar subtraction.

func (Quat) ToEuler

func (q Quat) ToEuler() (yaw, pitch, roll float32)

ToEuler converts the quaternion into euler rotations. Axis: yaw: Z, pitch: Y, roll: X

func (Quat) Up

func (q Quat) Up() Vec3f

Right returns the up-vector in the quaternion's coordinate system.

func (Quat) Vec4f

func (q Quat) Vec4f() Vec4f

Vec4f returns the quaternion as a vector representation.

type Rectf

type Rectf struct {
	Min Vec2f
	Max Vec2f
}

Rectf represents a 2D, axis-aligned rectangle.

func RectfFromCorners

func RectfFromCorners(c1, c2 Vec2f) Rectf

RectfFromCorners creates a new rectangle given two opposite corners. If necessary, coordinates are swapped to create a normalized rectangle.

func RectfFromEdges

func RectfFromEdges(left, right, bottom, top float32) Rectf

RectfFromEdges creates a new rectangle with the given edge positions. If necessary, edges are swapped to create a normalized rectangle.

func RectfFromPosSize

func RectfFromPosSize(pos, size Vec2f) Rectf

RectfFromPosSize creates a new rectangle with the given size and position. Negative dimensions are inverted to create a normalized rectangle.

func (Rectf) Add

func (r Rectf) Add(v Vec2f) Rectf

Add moves the rectangle with the given vector by adding it to the min- and max- components.

func (Rectf) Area

func (r Rectf) Area() float32

Area returns the rectangle's area.

func (Rectf) Bottom

func (r Rectf) Bottom() float32

Bottom returns the rectangle's bottom position (smaller Y).

func (Rectf) ContainsPoint

func (r Rectf) ContainsPoint(point Vec2f) bool

ContainsPoint checks if a given point resides within the rectangle. If the point is on an edge, it is also considered to be contained within the rectangle.

func (Rectf) ContainsRectf

func (r Rectf) ContainsRectf(other Rectf) bool

ContainsRectf checks if this rectangle completely contains another rectangle.

func (Rectf) Intersects

func (r Rectf) Intersects(other Rectf) bool

Intersects checks if this rectangle intersects another rectangle. Touching rectangles where floats are exactly equal are not considered to intersect.

func (Rectf) Left

func (r Rectf) Left() float32

Left returns the rectangle's left position (smaller X).

func (Rectf) Merge

func (r Rectf) Merge(other Rectf) Rectf

Merge returns a rectangle that contains both smaller rectangles.

func (Rectf) Normalize

func (r Rectf) Normalize() Rectf

Normalize ensures that the Min position is smaller than the Max position in every dimension.

func (Rectf) PointDistance

func (r Rectf) PointDistance(pos Vec2f) float32

PointDistance returns the distance between the rectangle and a point. If the point is contained within the rectangle, 0 is returned. Otherwise, the distance between the point and the nearest edge or corner is returned.

func (Rectf) Recti

func (r Rectf) Recti() Recti

Recti returns an integer representation of the rectangle. Decimals are truncated.

func (Rectf) Right

func (r Rectf) Right() float32

Right returns the rectangle's right position (bigger X).

func (Rectf) Round

func (r Rectf) Round() Recti

Round returns an integer representation of the rectangle. Decimals are rounded.

func (Rectf) SetPos

func (r Rectf) SetPos(pos Vec2f)

SetPos changes the rectangle position by modifying min, but keeps the rectangle's size.

func (Rectf) SetSize

func (r Rectf) SetSize(size Vec2f)

SetSize changes the rectangle size by keeping the min-position.

func (Rectf) Size

func (r Rectf) Size() Vec2f

Size returns the rectangle's dimensions.

func (Rectf) SquarePointDistance

func (r Rectf) SquarePointDistance(pos Vec2f) float32

SquarePointDistance returns the squared distance between the rectangle and a point. If the point is contained within the rectangle, 0 is returned. Otherwise, the squared distance between the point and the nearest edge or corner is returned.

func (Rectf) String

func (r Rectf) String() string

func (Rectf) Sub

func (r Rectf) Sub(v Vec2f) Rectf

Sub moves the rectangle with the given vector by subtracting it to the min- and max- components.

func (Rectf) Top

func (r Rectf) Top() float32

Top returns the rectangle's top position (bigger Y).

type Recti

type Recti struct {
	Min Vec2i
	Max Vec2i
}

Recti represents a 2D, axis-aligned rectangle.

func RectiFromCorners

func RectiFromCorners(c1, c2 Vec2i) Recti

RectiFromCorners creates a new rectangle given two opposite corners.

func RectiFromEdges

func RectiFromEdges(left, right, bottom, top int) Recti

RectfFromEdges creates a new rectangle with the given edge positions.

func RectiFromPosSize

func RectiFromPosSize(pos, size Vec2i) Recti

RectiFromPosSize creates a new rectangle with the given size and position. Negative dimensions are correctly inverted.

func (Recti) Add

func (r Recti) Add(v Vec2i) Recti

Add moves the rectangle with the given vector by adding it to the min- and max- components.

func (Recti) Area

func (r Recti) Area() int

Area returns the rectangle's area.

func (Recti) Bottom

func (r Recti) Bottom() int

Bottom returns the rectangle's bottom position (smaller Y).

func (Recti) ContainsPoint

func (r Recti) ContainsPoint(point Vec2i) bool

Contains checks if a given point resides within the rectangle. If the point is on an edge, it is also considered to be contained within the rectangle.

func (Recti) ContainsRecti

func (r Recti) ContainsRecti(other Recti) bool

ContainsRecti checks if this rectangle completely contains another rectangle.

func (Recti) Left

func (r Recti) Left() int

Left returns the rectangle's left position (smaller X).

func (Recti) Merge

func (r Recti) Merge(other Recti) Recti

Merge returns a rectangle that contains both smaller rectangles.

func (Recti) Normalize

func (r Recti) Normalize() Recti

Normalize ensures that the Min position is smaller than the Max position in every dimension.

func (Recti) Overlaps

func (r Recti) Overlaps(other Recti) bool

Overlaps checks if this rectangle overlaps another rectangle. Touching rectangles where floats are exactly equal are not considered to overlap.

func (Recti) OverlapsOrTouches

func (r Recti) OverlapsOrTouches(other Recti) bool

OverlapsOrTouches checks if this rectangle overlaps or touches another rectangle.

func (Recti) PointDistance

func (r Recti) PointDistance(pos Vec2i) float32

PointDistance returns the distance between the rectangle and a point. If the point is contained within the rectangle, 0 is returned. Otherwise, the distance between the point and the nearest edge or corner is returned.

func (Recti) Rectf

func (r Recti) Rectf() Rectf

Rectf returns a float representation of the rectangle.

func (Recti) Right

func (r Recti) Right() int

Right returns the rectangle's right position (bigger X).

func (Recti) SetPos

func (r Recti) SetPos(pos Vec2i)

SetPos changes the rectangle position by modifying min, but keeps the rectangle's size.

func (Recti) SetSize

func (r Recti) SetSize(size Vec2i)

SetSize changes the rectangle size by keeping the min-position.

func (*Recti) Size

func (r *Recti) Size() Vec2i

Size returns the rectangle's dimensions.

func (Recti) SquarePointDistance

func (r Recti) SquarePointDistance(pos Vec2i) int

SquarePointDistance returns the squared distance between the rectangle and a point. If the point is contained within the rectangle, 0 is returned. Otherwise, the squared distance between the point and the nearest edge or corner is returned.

func (Recti) String

func (r Recti) String() string

func (Recti) Sub

func (r Recti) Sub(v Vec2i) Recti

Sub moves the rectangle with the given vector by subtracting it to the min- and max- components.

func (Recti) Top

func (r Recti) Top() int

Top returns the rectangle's top position (bigger Y).

type Vec2f

type Vec2f [2]float32

func AngleToVector

func AngleToVector(rad float32, length float32) Vec2f

AngleToVector returns a 2D vector with the given length and angle to the x-axis.

func PolarToCartesian2D

func PolarToCartesian2D(distance, rad float32) Vec2f

PolarToCartesian2D converts length and angle into a 2D position.

func (Vec2f) Abs

func (v Vec2f) Abs() Vec2f

Abs returns a vector with the components turned into absolute values.

func (Vec2f) Add

func (v Vec2f) Add(other Vec2f) Vec2f

Add performs component-wise addition.

func (Vec2f) AddScalar

func (v Vec2f) AddScalar(s float32) Vec2f

AddScalar performs a component-wise scalar addition.

func (Vec2f) Angle

func (v Vec2f) Angle(other Vec2f) float32

Angle returns the angle relative to another vector.

func (Vec2f) Clamp

func (v Vec2f) Clamp(min, max float32) Vec2f

Clamp clamps each component to the range of [min, max].

func (Vec2f) Distance

func (v Vec2f) Distance(other Vec2f) float32

Distance returns the euclidean distance to another position.

func (Vec2f) Div

func (v Vec2f) Div(other Vec2f) Vec2f

Div performs a component-wise division.

func (Vec2f) DivScalar

func (v Vec2f) DivScalar(s float32) Vec2f

DivScalar performs a scalar division.

func (Vec2f) Dot

func (v Vec2f) Dot(other Vec2f) float32

Dot performs a dot product with another vector.

func (Vec2f) Equal

func (v Vec2f) Equal(other Vec2f) bool

Equal compares two vectors component-wise. Uses the default Epsilon as relative tolerance.

func (Vec2f) EqualEps

func (v Vec2f) EqualEps(other Vec2f, epsilon float32) bool

EqualEps compares two vectors component-wise, using the given epsilon as a relative tolerance.

func (Vec2f) FlatAngle

func (v Vec2f) FlatAngle() float32

FlatAngle returns the angle of a vector in radians. This is the angle between the vector and the x-axis.

func (Vec2f) Format

func (v Vec2f) Format(format string) string

Format the vector to a string.

func (Vec2f) IsCollinear

func (v Vec2f) IsCollinear(other Vec2f) bool

IsCollinear returns true if the given vector is collinear (pointing in the same direction). Uses the given Epsilon as relative tolerance.

func (Vec2f) IsCollinearEps

func (v Vec2f) IsCollinearEps(other Vec2f, eps float32) bool

IsCollinearEps returns true if the given vector is collinear (pointing in the same direction). Uses the given Epsilon as relative tolerance.

func (Vec2f) IsOrthogonal

func (v Vec2f) IsOrthogonal() bool

IsOrthogonal returns true if the vector is horizontal or vertical (one of its components is zero).

func (Vec2f) IsParallel

func (v Vec2f) IsParallel(other Vec2f) bool

IsParallel returns true if the given vector is parallel. Vectors that point in opposite directions are also parallel. Uses the default Epsilon as relative tolerance.

func (Vec2f) IsParallelEps

func (v Vec2f) IsParallelEps(other Vec2f, eps float32) bool

IsParallel returns true if the given vector is parallel. Vectors that point in opposite directions are also parallel. Uses the given Epsilon as relative tolerance.

func (Vec2f) IsZero

func (v Vec2f) IsZero() bool

IsZero returns true if all components are zero. Uses the default Epsilon as relative tolerance.

func (Vec2f) Length

func (v Vec2f) Length() float32

Length returns the vector's length.

func (Vec2f) Lerp

func (v Vec2f) Lerp(other Vec2f, t float32) Vec2f

Lerp performs a linear interpolation between two vectors. The parameter t should be in range [0, 1].

func (Vec2f) MagCross

func (v Vec2f) MagCross(other Vec2f) float32

MagCross returns the length of the cross product vector. This is equal to the magnitude of a 3D cross product vector, with the Z position implicitly set to zero. It represents twice the signed area between the two vectors.

func (Vec2f) Mul

func (v Vec2f) Mul(other Vec2f) Vec2f

Mul performs a component-wise multiplication.

func (Vec2f) MulScalar

func (v Vec2f) MulScalar(s float32) Vec2f

MulScalar performs a scalar multiplication.

func (Vec2f) Negate

func (v Vec2f) Negate() Vec2f

Negate inverts all components.

func (Vec2f) NormalVec

func (v Vec2f) NormalVec(onLeft bool) Vec2f

NormalVec returns a normal vector on the 2D plane that is either on the left or right hand side.

func (Vec2f) Normalize

func (v Vec2f) Normalize() Vec2f

Normalize the vector. Its length will be 1 afterwards. If the vector's length is zero, a zero vector will be returned.

func (Vec2f) Project

func (v Vec2f) Project(other Vec2f) Vec2f

Project returns a vector representing the projection of vector v onto "other".

func (Vec2f) Rotate

func (v Vec2f) Rotate(rad float32) Vec2f

Rotate rotates the vector on the 2D plane.

func (Vec2f) Round

func (v Vec2f) Round() Vec2i

Round returns an integer representation of the vector. Decimals are rounded.

func (Vec2f) Split

func (v Vec2f) Split() (x, y float32)

Split returns the vector's components.

func (Vec2f) SquareDistance

func (v Vec2f) SquareDistance(other Vec2f) float32

SquareDistance returns the squared euclidean distance to another position.

func (Vec2f) SquareLength

func (v Vec2f) SquareLength() float32

SquareLength returns the vector's squared length.

func (Vec2f) String

func (v Vec2f) String() string

func (Vec2f) Sub

func (v Vec2f) Sub(other Vec2f) Vec2f

Sub performs component-wise subtraction.

func (Vec2f) SubScalar

func (v Vec2f) SubScalar(s float32) Vec2f

SubScalar performs a component-wise scalar subtraction.

func (Vec2f) Vec2i

func (v Vec2f) Vec2i() Vec2i

Vec2i returns an integer representation of the vector. Decimals are truncated.

func (Vec2f) Vec3f

func (v Vec2f) Vec3f(z float32) Vec3f

Vec3f creates a 3D vector.

func (Vec2f) Vec4f

func (v Vec2f) Vec4f(z, w float32) Vec4f

Vec4f creates a 4D vector.

func (Vec2f) X

func (v Vec2f) X() float32

X returns the vector's first component. Performance is equivalent to using v[0].

func (Vec2f) Y

func (v Vec2f) Y() float32

Y returns the vector's second component. Performance is equivalent to using v[1].

type Vec2i

type Vec2i [2]int

func (Vec2i) Abs

func (v Vec2i) Abs() Vec2i

Abs returns a vector with the components turned into absolute values.

func (Vec2i) Add

func (v Vec2i) Add(other Vec2i) Vec2i

Add performs component-wise addition between two vectors.

func (Vec2i) AddScalar

func (v Vec2i) AddScalar(s int) Vec2i

AddScalar performs a component-wise scalar addition.

func (Vec2i) AddScalarf

func (v Vec2i) AddScalarf(s float32) Vec2f

AddScalarf performs a scalar addition.

func (Vec2i) Clamp

func (v Vec2i) Clamp(min, max int) Vec2i

Clamp clamps each component to the range of [min, max].

func (Vec2i) Distance

func (v Vec2i) Distance(other Vec2i) float32

Distance returns the euclidean distance to another position.

func (Vec2i) Div

func (v Vec2i) Div(other Vec2i) Vec2i

Div performs a component-wise division. Decimals are truncated.

func (Vec2i) DivScalar

func (v Vec2i) DivScalar(s int) Vec2i

DivScalar performs a scalar division. Decimals are truncated.

func (Vec2i) DivScalarf

func (v Vec2i) DivScalarf(s float32) Vec2f

DivScalarf performs a scalar division.

func (Vec2i) Dot

func (v Vec2i) Dot(other Vec2i) int

Dot performs a dot product with another vector.

func (Vec2i) Equal

func (v Vec2i) Equal(other Vec2i) bool

Equal compares two vectors component-wise.

func (Vec2i) Format

func (v Vec2i) Format(format string) string

Format the vector to a string.

func (Vec2i) IsCollinear

func (v Vec2i) IsCollinear(other Vec2i) bool

IsCollinear returns true if the given vector is collinear (pointing in the same direction).

func (Vec2i) IsOrthogonal

func (v Vec2i) IsOrthogonal() bool

IsOrthogonal returns true if the vector is horizontal or vertical (one of its components is zero).

func (Vec2i) IsParallel

func (v Vec2i) IsParallel(other Vec2i) bool

IsParallel returns true if the given vector is parallel. Vectors that point in opposite directions are also parallel (but not collinear).

func (Vec2i) IsZero

func (v Vec2i) IsZero() bool

IsZero returns true if all components are zero.

func (Vec2i) Length

func (v Vec2i) Length() float32

Length returns the vector's length.

func (Vec2i) MagCross

func (v Vec2i) MagCross(other Vec2i) int

MagCross returns the length of the cross product vector. This is equal to the magnitude of a 3D cross product vector, with the Z position implicitly set to zero. It represents twice the signed area between the two vectors.

func (Vec2i) Mul

func (v Vec2i) Mul(other Vec2i) Vec2i

Mul performs a component-wise multiplication.

func (Vec2i) MulScalar

func (v Vec2i) MulScalar(s int) Vec2i

MulScalar performs a scalar multiplication.

func (Vec2i) MulScalarf

func (v Vec2i) MulScalarf(s float32) Vec2f

MulScalar performs a scalar multiplication.

func (Vec2i) Negate

func (v Vec2i) Negate() Vec2i

Negate inverts all components.

func (Vec2i) NormalVec

func (v Vec2i) NormalVec(onLeft bool) Vec2i

NormalVec returns a normal vector on the 2D plane that is either on the left or right hand side.

func (Vec2i) Project

func (v Vec2i) Project(other Vec2i) Vec2f

Project returns a vector representing the projection of vector v onto "other".

func (Vec2i) Split

func (v Vec2i) Split() (x, y int)

Split returns the vector's components.

func (Vec2i) SquareDistance

func (v Vec2i) SquareDistance(other Vec2i) int

SquareDistance returns the squared euclidean distance to another position.

func (Vec2i) SquareLength

func (v Vec2i) SquareLength() int

SquareLength returns the vector's squared length.

func (Vec2i) String

func (v Vec2i) String() string

func (Vec2i) Sub

func (v Vec2i) Sub(other Vec2i) Vec2i

Sub performs component-wise subtraction between two vectors.

func (Vec2i) SubScalar

func (v Vec2i) SubScalar(s int) Vec2i

SubScalar performs a component-wise scalar subtraction.

func (Vec2i) SubScalarf

func (v Vec2i) SubScalarf(s float32) Vec2f

SubScalarf performs a scalar subtraction.

func (Vec2i) Vec2f

func (v Vec2i) Vec2f() Vec2f

Vec2f returns a float representation of the vector.

func (Vec2i) Vec3i

func (v Vec2i) Vec3i(z int) Vec3i

Vec3i creates a 3D vector.

func (Vec2i) Vec4i

func (v Vec2i) Vec4i(z, w int) Vec4i

Vec4i creates a 4D vector.

func (Vec2i) X

func (v Vec2i) X() int

X returns the vector's first component. Performance is equivalent to using v[0].

func (Vec2i) Y

func (v Vec2i) Y() int

Y returns the vector's second component. Performance is equivalent to using v[1].

type Vec3f

type Vec3f [3]float32

func SphericalToCartesian

func SphericalToCartesian(radius, azimuth, inclination float32) Vec3f

SphericalToCartesian converts spherical coordinates into cartesian coordinates.

func (Vec3f) Abs

func (v Vec3f) Abs() Vec3f

Abs returns a vector with the components turned into absolute values.

func (Vec3f) Add

func (v Vec3f) Add(other Vec3f) Vec3f

Add performs component-wise addition.

func (Vec3f) AddScalar

func (v Vec3f) AddScalar(s float32) Vec3f

AddScalar performs a component-wise scalar addition.

func (Vec3f) Angle

func (v Vec3f) Angle(other Vec3f) float32

Angle returns the angle between two vectors in radians.

func (Vec3f) Clamp

func (v Vec3f) Clamp(min, max float32) Vec3f

Clamp clamps each component to the range of [min, max].

func (Vec3f) Cross

func (v Vec3f) Cross(other Vec3f) Vec3f

Cross performs a cross product with another vector.

func (Vec3f) Distance

func (v Vec3f) Distance(other Vec3f) float32

Distance returns the euclidean distance to another position.

func (Vec3f) Div

func (v Vec3f) Div(other Vec3f) Vec3f

Div performs a component-wise division.

func (Vec3f) DivScalar

func (v Vec3f) DivScalar(s float32) Vec3f

DivScalar performs a scalar division.

func (Vec3f) Dot

func (v Vec3f) Dot(other Vec3f) float32

Dot performs a dot product with another vector.

func (Vec3f) Equal

func (v Vec3f) Equal(other Vec3f) bool

Equal compares two vectors component-wise. Uses the default Epsilon as relative tolerance.

func (Vec3f) EqualEps

func (v Vec3f) EqualEps(other Vec3f, epsilon float32) bool

EqualEps compares two vectors component-wise, using the given epsilon as a relative tolerance.

func (Vec3f) Format

func (v Vec3f) Format(format string) string

Format the vector to a string.

func (Vec3f) IsCollinear

func (v Vec3f) IsCollinear(other Vec3f) bool

IsCollinear returns true if the given vector is collinear (pointing in the same direction). Uses the given Epsilon as relative tolerance.

func (Vec3f) IsCollinearEps

func (v Vec3f) IsCollinearEps(other Vec3f, eps float32) bool

IsCollinearEps returns true if the given vector is collinear (pointing in the same direction). Uses the given Epsilon as relative tolerance.

func (Vec3f) IsOrthogonal

func (v Vec3f) IsOrthogonal() bool

IsOrthogonal returns true if the vector is parallel to the X, Y or Z axis (one of its components is zero).

func (Vec3f) IsParallel

func (v Vec3f) IsParallel(other Vec3f) bool

IsParallel returns true if the given vector is parallel. Vectors that point in opposite directions are also parallel. Uses the default Epsilon as relative tolerance.

func (Vec3f) IsParallelEps

func (v Vec3f) IsParallelEps(other Vec3f, eps float32) bool

IsParallel returns true if the given vector is parallel. Vectors that point in opposite directions are also parallel. Uses the given Epsilon as relative tolerance.

func (Vec3f) IsZero

func (v Vec3f) IsZero() bool

IsZero returns true if all components are zero. Uses the default Epsilon as relative tolerance.

func (Vec3f) Length

func (v Vec3f) Length() float32

Length returns the vector's length.

func (Vec3f) Lerp

func (v Vec3f) Lerp(other Vec3f, t float32) Vec3f

Lerp performs a linear interpolation between two vectors. The parameter t should be in range [0, 1].

func (Vec3f) Mul

func (v Vec3f) Mul(other Vec3f) Vec3f

Mul performs a component-wise multiplication.

func (Vec3f) MulScalar

func (v Vec3f) MulScalar(s float32) Vec3f

MulScalar performs a scalar multiplication.

func (Vec3f) Negate

func (v Vec3f) Negate() Vec3f

Negate inverts all components.

func (Vec3f) Normalize

func (v Vec3f) Normalize() Vec3f

Normalize the vector. Its length will be 1 afterwards. If the vector's length is zero, a zero vector will be returned.

func (Vec3f) Project

func (v Vec3f) Project(other Vec3f) Vec3f

Project returns a vector representing the projection of vector v onto "other".

func (Vec3f) RotateX

func (v Vec3f) RotateX(origin Vec3f, rad float32) Vec3f

RotateX rotates a point around the X-axis.

func (Vec3f) RotateY

func (v Vec3f) RotateY(origin Vec3f, rad float32) Vec3f

RotateY rotates a point around the Y-axis.

func (Vec3f) RotateZ

func (v Vec3f) RotateZ(origin Vec3f, rad float32) Vec3f

RotateZ rotates a point around the Z-axis.

func (Vec3f) RotationTo

func (v Vec3f) RotationTo(dest Vec3f) Quat

RotationTo returns the shortest rotation to the destination vector.

func (Vec3f) Round

func (v Vec3f) Round() Vec3i

Round returns an integer representation of the vector. Decimals are rounded.

func (Vec3f) Split

func (v Vec3f) Split() (x, y, z float32)

Split returns the vector's components.

func (Vec3f) SquareDistance

func (v Vec3f) SquareDistance(other Vec3f) float32

SquareDistance returns the squared euclidean distance to another position.

func (Vec3f) SquareLength

func (v Vec3f) SquareLength() float32

SquareLength returns the vector's squared length.

func (Vec3f) String

func (v Vec3f) String() string

func (Vec3f) Sub

func (v Vec3f) Sub(other Vec3f) Vec3f

Sub performs component-wise subtraction.

func (Vec3f) SubScalar

func (v Vec3f) SubScalar(s float32) Vec3f

SubScalar performs a component-wise scalar subtraction.

func (Vec3f) Vec3i

func (v Vec3f) Vec3i() Vec3i

Vec3i returns an integer representation of the vector. Decimals are truncated.

func (Vec3f) Vec4f

func (v Vec3f) Vec4f(w float32) Vec4f

Vec4f creates a 4D vector.

func (Vec3f) X

func (v Vec3f) X() float32

X returns the vector's first component. Performance is equivalent to using v[0].

func (Vec3f) XY

func (v Vec3f) XY() Vec2f

XY returns a 2D vector with the X and Y components.

func (Vec3f) Y

func (v Vec3f) Y() float32

Y returns the vector's second component. Performance is equivalent to using v[1].

func (Vec3f) Z

func (v Vec3f) Z() float32

Z returns the vector's third component. Performance is equivalent to using v[2].

type Vec3i

type Vec3i [3]int

func (Vec3i) Abs

func (v Vec3i) Abs() Vec3i

Abs returns a vector with the components turned into absolute values.

func (Vec3i) Add

func (v Vec3i) Add(other Vec3i) Vec3i

Add performs component-wise addition between two vectors.

func (Vec3i) AddScalar

func (v Vec3i) AddScalar(s int) Vec3i

AddScalar performs a component-wise scalar addition.

func (Vec3i) AddScalarf

func (v Vec3i) AddScalarf(s float32) Vec3f

AddScalarf performs a scalar addition.

func (Vec3i) Clamp

func (v Vec3i) Clamp(min, max int) Vec3i

Clamp clamps each component to the range of [min, max].

func (Vec3i) Cross

func (v Vec3i) Cross(other Vec3i) Vec3i

Cross performs a cross product with another vector.

func (Vec3i) Distance

func (v Vec3i) Distance(other Vec3i) float32

Distance returns the euclidean distance to another position.

func (Vec3i) Div

func (v Vec3i) Div(other Vec3i) Vec3i

Div performs a component-wise division.

func (Vec3i) DivScalar

func (v Vec3i) DivScalar(s int) Vec3i

DivScalar performs a scalar division.

func (Vec3i) DivScalarf

func (v Vec3i) DivScalarf(s float32) Vec3f

DivScalarf performs a scalar division.

func (Vec3i) Dot

func (v Vec3i) Dot(other Vec3i) int

Dot performs a dot product with another vector.

func (Vec3i) Equal

func (v Vec3i) Equal(other Vec3i) bool

Equal compares two vectors component-wise.

func (Vec3i) Format

func (v Vec3i) Format(format string) string

Format the vector to a string.

func (Vec3i) IsCollinear

func (v Vec3i) IsCollinear(other Vec3i) bool

IsCollinear returns true if the given vector is collinear (pointing in the same direction). Uses the given Epsilon as relative tolerance.

func (Vec3i) IsOrthogonal added in v0.2.0

func (v Vec3i) IsOrthogonal() bool

IsOrthogonal returns true if the vector is parallel to the X, Y or Z axis (one of its components is zero).

func (Vec3i) IsParallel

func (v Vec3i) IsParallel(other Vec3i) bool

IsParallel returns true if the given vector is parallel. Vectors that point in opposite directions are also parallel (but not collinear).

func (Vec3i) IsZero

func (v Vec3i) IsZero() bool

IsZero returns true if all components are zero.

func (Vec3i) Length

func (v Vec3i) Length() float32

Length returns the vector's length.

func (Vec3i) Mul

func (v Vec3i) Mul(other Vec3i) Vec3i

Mul performs a component-wise multiplication.

func (Vec3i) MulScalar

func (v Vec3i) MulScalar(s int) Vec3i

MulScalar performs a scalar multiplication.

func (Vec3i) MulScalarf

func (v Vec3i) MulScalarf(s float32) Vec3f

MulScalar performs a scalar multiplication.

func (Vec3i) Negate

func (v Vec3i) Negate() Vec3i

Negate inverts all components.

func (Vec3i) Split

func (v Vec3i) Split() (x, y, z int)

Split returns the vector's components.

func (Vec3i) SquareDistance

func (v Vec3i) SquareDistance(other Vec3i) int

SquareDistance returns the squared euclidean distance to another position.

func (Vec3i) SquareLength

func (v Vec3i) SquareLength() int

SquareLength returns the vector's squared length.

func (Vec3i) String

func (v Vec3i) String() string

func (Vec3i) Sub

func (v Vec3i) Sub(other Vec3i) Vec3i

Sub performs component-wise subtraction between two vectors.

func (Vec3i) SubScalar

func (v Vec3i) SubScalar(s int) Vec3i

SubScalar performs a component-wise scalar subtraction.

func (Vec3i) SubScalarf

func (v Vec3i) SubScalarf(s float32) Vec3f

SubScalarf performs a scalar subtraction.

func (Vec3i) Vec3f

func (v Vec3i) Vec3f() Vec3f

Vec2f returns a float representation of the vector.

func (Vec3i) Vec4i

func (v Vec3i) Vec4i(w int) Vec4i

Vec4i creates a 4D vector.

func (Vec3i) X

func (v Vec3i) X() int

X returns the vector's first component. Performance is equivalent to using v[0].

func (Vec3i) XY

func (v Vec3i) XY() Vec2i

XY returns a 2D vector with the X and Y components.

func (Vec3i) Y

func (v Vec3i) Y() int

Y returns the vector's second component. Performance is equivalent to using v[1].

func (Vec3i) Z

func (v Vec3i) Z() int

Z returns the vector's third component. Performance is equivalent to using v[2].

type Vec4f

type Vec4f [4]float32

func (Vec4f) Abs

func (v Vec4f) Abs() Vec4f

Abs returns a vector with the components turned into absolute values.

func (Vec4f) Add

func (v Vec4f) Add(other Vec4f) Vec4f

Add performs component-wise addition.

func (Vec4f) AddScalar

func (v Vec4f) AddScalar(s float32) Vec4f

AddScalar performs a component-wise scalar addition.

func (Vec4f) Clamp

func (v Vec4f) Clamp(min, max float32) Vec4f

Clamp clamps each component to the range of [min, max].

func (Vec4f) Distance

func (v Vec4f) Distance(other Vec4f) float32

Distance returns the euclidean distance to another position.

func (Vec4f) Div

func (v Vec4f) Div(other Vec4f) Vec4f

Div performs a component-wise division.

func (Vec4f) DivScalar

func (v Vec4f) DivScalar(s float32) Vec4f

DivScalar performs a scalar division.

func (Vec4f) Dot

func (v Vec4f) Dot(other Vec4f) float32

Dot performs a dot product with another vector.

func (Vec4f) Equal

func (v Vec4f) Equal(other Vec4f) bool

Equal compares two vectors component-wise. Uses the default Epsilon as relative tolerance.

func (Vec4f) EqualEps

func (v Vec4f) EqualEps(other Vec4f, epsilon float32) bool

EqualEps compares two vectors component-wise, using the given epsilon as a relative tolerance.

func (Vec4f) Format

func (v Vec4f) Format(format string) string

Format the vector to a string.

func (Vec4f) IsZero

func (v Vec4f) IsZero() bool

IsZero returns true if all components are zero. Uses the default Epsilon as relative tolerance.

func (Vec4f) Length

func (v Vec4f) Length() float32

Length returns the vector's length.

func (Vec4f) Lerp

func (v Vec4f) Lerp(other Vec4f, t float32) Vec4f

Lerp performs a linear interpolation between two vectors. The parameter t should be in range [0, 1].

func (Vec4f) Mul

func (v Vec4f) Mul(other Vec4f) Vec4f

Mul performs a component-wise multiplication.

func (Vec4f) MulScalar

func (v Vec4f) MulScalar(s float32) Vec4f

MulScalar performs a scalar multiplication.

func (Vec4f) Negate

func (v Vec4f) Negate() Vec4f

Negate inverts all components.

func (Vec4f) Normalize

func (v Vec4f) Normalize() Vec4f

Normalize the vector. Its length will be 1 afterwards. If the vector's length is zero, a zero vector will be returned.

func (Vec4f) Project

func (v Vec4f) Project(other Vec4f) Vec4f

Project returns a vector representing the projection of vector v onto "other".

func (Vec4f) Round

func (v Vec4f) Round() Vec4i

Round returns an integer representation of the vector. Decimals are rounded.

func (Vec4f) Split

func (v Vec4f) Split() (x, y, z, w float32)

Split returns the vector's components.

func (Vec4f) SquareDistance

func (v Vec4f) SquareDistance(other Vec4f) float32

SquareDistance returns the squared euclidean distance to another position.

func (Vec4f) SquareLength

func (v Vec4f) SquareLength() float32

SquareLength returns the vector's squared length.

func (Vec4f) String

func (v Vec4f) String() string

func (Vec4f) Sub

func (v Vec4f) Sub(other Vec4f) Vec4f

Sub performs component-wise subtraction.

func (Vec4f) SubScalar

func (v Vec4f) SubScalar(s float32) Vec4f

SubScalar performs a component-wise scalar subtraction.

func (Vec4f) Vec4i

func (v Vec4f) Vec4i() Vec4i

Vec4i returns an integer representation of the vector. Decimals are truncated.

func (Vec4f) W

func (v Vec4f) W() float32

W returns the vector's fourth component. Performance is equivalent to using v[3].

func (Vec4f) X

func (v Vec4f) X() float32

X returns the vector's first component. Performance is equivalent to using v[0].

func (Vec4f) XY

func (v Vec4f) XY() Vec2f

XY returns a 2D vector with the X and Y components.

func (Vec4f) XYZ

func (v Vec4f) XYZ() Vec3f

XYZ returns a 3D vector with the X, Y and Z components.

func (Vec4f) Y

func (v Vec4f) Y() float32

Y returns the vector's second component. Performance is equivalent to using v[1].

func (Vec4f) Z

func (v Vec4f) Z() float32

Z returns the vector's third component. Performance is equivalent to using v[2].

type Vec4i

type Vec4i [4]int

func (Vec4i) Abs

func (v Vec4i) Abs() Vec4i

Abs returns a vector with the components turned into absolute values.

func (Vec4i) Add

func (v Vec4i) Add(other Vec4i) Vec4i

Add performs component-wise addition between two vectors.

func (Vec4i) AddScalar

func (v Vec4i) AddScalar(s int) Vec4i

AddScalar performs a component-wise scalar addition.

func (Vec4i) Clamp

func (v Vec4i) Clamp(min, max int) Vec4i

Clamp clamps each component to the range of [min, max].

func (Vec4i) Distance

func (v Vec4i) Distance(other Vec4i) float32

Distance returns the euclidean distance to another position.

func (Vec4i) Div

func (v Vec4i) Div(other Vec4i) Vec4i

Div performs a component-wise division.

func (Vec4i) DivScalar

func (v Vec4i) DivScalar(s int) Vec4i

DivScalar performs a scalar division.

func (Vec4i) Dot

func (v Vec4i) Dot(other Vec4i) int

Dot performs a dot product with another vector.

func (Vec4i) Equal

func (v Vec4i) Equal(other Vec4i) bool

Equal compares two vectors component-wise.

func (Vec4i) Format

func (v Vec4i) Format(format string) string

Format the vector to a string.

func (Vec4i) IsZero

func (v Vec4i) IsZero() bool

IsZero returns true if all components are zero.

func (Vec4i) Length

func (v Vec4i) Length() float32

Length returns the vector's length.

func (Vec4i) Mul

func (v Vec4i) Mul(other Vec4i) Vec4i

Mul performs a component-wise multiplication.

func (Vec4i) MulScalar

func (v Vec4i) MulScalar(s int) Vec4i

MulScalar performs a scalar multiplication.

func (Vec4i) Negate

func (v Vec4i) Negate() Vec4i

Negate inverts all components.

func (Vec4i) Split

func (v Vec4i) Split() (x, y, z, w int)

Split returns the vector's components.

func (Vec4i) SquareDistance

func (v Vec4i) SquareDistance(other Vec4i) int

SquareDistance returns the squared euclidean distance to another position.

func (Vec4i) SquareLength

func (v Vec4i) SquareLength() int

SquareLength returns the vector's squared length.

func (Vec4i) String

func (v Vec4i) String() string

func (Vec4i) Sub

func (v Vec4i) Sub(other Vec4i) Vec4i

Sub performs component-wise subtraction between two vectors.

func (Vec4i) SubScalar

func (v Vec4i) SubScalar(s int) Vec4i

SubScalar performs a component-wise scalar subtraction.

func (Vec4i) Vec4f

func (v Vec4i) Vec4f() Vec4f

Vec2f returns a float representation of the vector.

func (Vec4i) W

func (v Vec4i) W() int

W returns the vector's fourth component. Performance is equivalent to using v[3].

func (Vec4i) X

func (v Vec4i) X() int

X returns the vector's first component. Performance is equivalent to using v[0].

func (Vec4i) XY

func (v Vec4i) XY() Vec2i

XY returns a 2D vector with the X and Y components.

func (Vec4i) XYZ

func (v Vec4i) XYZ() Vec3i

XYZ returns a 3D vector with the X, Y and Z components.

func (Vec4i) Y

func (v Vec4i) Y() int

Y returns the vector's second component. Performance is equivalent to using v[1].

func (Vec4i) Z

func (v Vec4i) Z() int

Z returns the vector's third component. Performance is equivalent to using v[2].

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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