math

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2022 License: BSD-2-Clause Imports: 1 Imported by: 3

Documentation

Index

Constants

View Source
const (
	MinNormal = Real(1.1754943508222875e-38) // 1 / 2**(127 - 1)
	MinValue  = Real(math.SmallestNonzeroFloat64)
	MaxValue  = Real(math.MaxFloat64)
)

Variables

View Source
var (
	InfPos = Real(math.Inf(1))
	InfNeg = Real(math.Inf(-1))
	NaN    = Real(math.NaN())
)

Functions

func RealEqual

func RealEqual(a, b Real) bool

RealEqual tests the two Real numbers for equality, which really means that it tests whether or not the difference between the two is smaller than Epsilon.

func RealIsNaN

func RealIsNaN(a Real) bool

RealIsNaN returns true if the value is Not a Number.

Types

type Matrix3

type Matrix3 [9]Real

Matrix3 is a 3x3 matrix of floats in column-major order.

func (*Matrix3) Add

func (m *Matrix3) Add(m2 *Matrix3)

Add adds the values of a 3x3 matrix to this matrix.

func (*Matrix3) Determinant

func (m *Matrix3) Determinant() Real

Determinant calculates the determinant of a matrix which is a measure of a square matrix's singularity and invertability, among other things.

func (*Matrix3) Invert

func (m *Matrix3) Invert() Matrix3

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

func (*Matrix3) MulMatrix3

func (m1 *Matrix3) MulMatrix3(m2 *Matrix3) Matrix3

MulMatrix3 multiplies a 3x3 matrix by another 3x3 matrix.

func (*Matrix3) MulVector3

func (m *Matrix3) MulVector3(v *Vector3) Vector3

MulVector3 multiplies a 3x3 matrix by a vector.

func (*Matrix3) MulWith

func (m *Matrix3) MulWith(s Real)

MulWith multiplies a 3x3 matrix by a scalar value.

func (*Matrix3) SetBlockInertiaTensor

func (m *Matrix3) SetBlockInertiaTensor(halfSize *Vector3, mass Real)

SetBlockInertiaTensor sets the value of the matrix as an inertia tensor of a rectangular block aligned with the body's coordinate system with the given axis half sizes and mass.

func (*Matrix3) SetComponents

func (m *Matrix3) SetComponents(v1 *Vector3, v2 *Vector3, v3 *Vector3)

SetComponents sets the matrix vales based off of the three vectors given. Each vector should be arranged as a column in the matrix and should then be passed in order.

func (*Matrix3) SetIdentity

func (m *Matrix3) SetIdentity()

SetIdentity loads the matrix with its identity.

func (*Matrix3) SetInertiaTensorCoeffs

func (m *Matrix3) SetInertiaTensorCoeffs(ix, iy, iz, ixy, ixz, iyz Real)

SetInertiaTensorCoeffs sets the value of the matrix from inertia tensor values.

func (*Matrix3) TransformTranspose

func (m *Matrix3) TransformTranspose(v *Vector3) Vector3

TransformTranspose transforms the given vector by the transpose of this matrix

func (*Matrix3) Transpose

func (m *Matrix3) Transpose() Matrix3

Transpose produces the transpose of this matrix.

type Matrix3x4

type Matrix3x4 [12]Real

Matrix3x4 is a 3x4 matrix of floats in column-major order that can be used to hold a rotation and translation in 3D space where the 4th row would have been [0 0 0 1]

func (*Matrix3x4) GetAxis

func (m *Matrix3x4) GetAxis(colNumber int) Vector3

func (*Matrix3x4) MulMatrix3x4

func (m *Matrix3x4) MulMatrix3x4(o *Matrix3x4) Matrix3x4

Mul3x4 multiplies a 3x4 matrix by another 3x4 matrix. This operation is meant to mimic a 4x4 * 4x4 operation where the last row is {0, 0, 0, 1}.

func (*Matrix3x4) MulVector3

func (m *Matrix3x4) MulVector3(v *Vector3) Vector3

MulVector3 transforms the given vector by the matrix and returns the result.

func (*Matrix3x4) SetAsTransform

func (m *Matrix3x4) SetAsTransform(pos *Vector3, rot *Quat)

SetAsTransform sets the 3x4 matrix to be a transform matrix based on the position and orientation passed in.

func (*Matrix3x4) SetIdentity

func (m *Matrix3x4) SetIdentity()

SetIdentity loads the matrix with its identity.

func (*Matrix3x4) TransformInverse

func (m *Matrix3x4) TransformInverse(v *Vector3) Vector3

TransformInverse transforms the vector by the transformational inverse of this matrix. NOTE: will not work on matrixes with scale or shears.

type Matrix4

type Matrix4 [16]Real

Matrix4 is a 4x4 matrix of floats in column-major order.

func (*Matrix4) SetIdentity

func (m *Matrix4) SetIdentity()

SetIdentity loads the matrix with its identity.

type Quat

type Quat Vector4

Quat is the type of a quaternion (w,x,y,z).

func QuatBetweenVectors

func QuatBetweenVectors(s, d *Vector3) Quat

QuatBetweenVectors calculates the rotation between two vectors. Note: this was modified from the go-gl/mathgl library.

func QuatFromAxis

func QuatFromAxis(angle, x, y, z Real) Quat

QuatFromAxis creates an quaternion from an axis and an angle.

func (*Quat) AddScaledVector

func (q *Quat) AddScaledVector(v *Vector3, scale Real)

AddScaledVector adds the given vector to this quaternion, scaled by the given amount.

func (*Quat) Conjugated

func (q *Quat) Conjugated() Quat

Conjugated returns the conjugate of a quaternion. Equivalent to Quat{w,-x,-y,-z}.

func (*Quat) Dot

func (q *Quat) Dot(q2 *Quat) Real

Dot calculates the dot product between two quaternions, equivalent to if this was a Vector4

func (*Quat) Inverse

func (q *Quat) Inverse()

Inverse calculates the 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 percision.

func (*Quat) Len

func (q *Quat) Len() Real

Len returns the length of the quaternion.

func (*Quat) LookAt

func (q *Quat) LookAt(eye, center, up *Vector3)

LookAt sets the quaternion to the orientation needed to look at a 'center' from the 'eye' position with 'up' as a reference vector for the up direction. Note: this was modified from the go-gl/mathgl library.

func (*Quat) Mul

func (q *Quat) Mul(q2 *Quat)

Mul multiplies the quaternion by another quaternion.

func (*Quat) Normalize

func (q *Quat) Normalize()

Normalize normalizes the quaternion.

func (*Quat) Rotate

func (q *Quat) Rotate(v *Vector3) Vector3

Rotate rotates a vector by the rotation this quaternion represents.

func (*Quat) Scale

func (q *Quat) Scale(c Real)

Scale scales every element of the quaternion by some constant factor.

func (*Quat) SetIdentity

func (q *Quat) SetIdentity()

SetIdentity loads the quaternion with its identity.

type Real

type Real float64

Real is the type of float used in the library.

const Epsilon Real = 1e-7

Espilon is used to test equality of the floats and represents how close two Reals can be and still test positive for equality.

func DegToRad

func DegToRad(angle Real) Real

DegToRad converts degrees to radians

func RadToDeg

func RadToDeg(angle Real) Real

RadToDeg converts radians to degrees

func RealAbs

func RealAbs(a Real) Real

RealAbs is an absolute value wrapper for the Real type.

func RealCos

func RealCos(a Real) Real

RealCos is a cos function wrapper for the Real type.

func RealSin

func RealSin(a Real) Real

RealSin is a sin function wrapper for the Real type.

func RealSqrt

func RealSqrt(a Real) Real

RealSqrt is a square root wrapper for the Real type.

type Vector3

type Vector3 [3]Real

Vector3 is a vector of three floats.

func (*Vector3) Add

func (v *Vector3) Add(v2 *Vector3)

Add adds a vector to another vector.

func (*Vector3) AddScaled

func (v *Vector3) AddScaled(v2 *Vector3, scale Real)

Add adds a vector, scaled by a Real, to another vector.

func (*Vector3) Clear

func (v *Vector3) Clear()

Clear sets the vector to {0.0, 0.0, 0.0}.

func (*Vector3) ComponentProduct

func (v *Vector3) ComponentProduct(v2 *Vector3)

ComponentProduct performs a component-wise product with another vector.

func (*Vector3) Cross

func (v *Vector3) Cross(v2 *Vector3) Vector3

Cross returns the cross product of this vector with another.

func (*Vector3) Dot

func (v *Vector3) Dot(v2 *Vector3) Real

Dot returns the dot product of this vector with another.

func (*Vector3) Magnitude

func (v *Vector3) Magnitude() Real

Magnitude returns the magnitude of the vector.

func (*Vector3) MulWith

func (v *Vector3) MulWith(r Real)

MulWith multiplies a vector by a Real number.

func (*Vector3) Normalize

func (v *Vector3) Normalize()

Normalize sets the vector the normalized value.

func (*Vector3) Set

func (v *Vector3) Set(v2 *Vector3)

Set sets the vector equal to the values of the second vector.

func (*Vector3) SquareMagnitude

func (v *Vector3) SquareMagnitude() Real

SquareMagnitude returns the magitude of the vector, squared.

func (*Vector3) Sub

func (v *Vector3) Sub(v2 *Vector3)

Sub subtracts a second vector from this vector.

type Vector4

type Vector4 [4]Real

Vector4 is a vector of four floats.

func (*Vector4) MulWith

func (v *Vector4) MulWith(r Real)

MulWith multiplies a vector by a Real number.

Jump to

Keyboard shortcuts

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