mathf

package
v0.0.0-...-af59c4b Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2019 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const Epsilon = 0.00000001

Epsilon is a calculation precision

Variables

View Source
var GravitationalConstant float64 = 6.673e-11

GravitationalConstant is approximately 6.674×10−11 m3*kg^−1*s^−2

Functions

func Clamp

func Clamp(v float64, min float64, max float64) float64

func CloseEquals

func CloseEquals(a float64, b float64) bool

func CloseZero

func CloseZero(x float64) bool

func ToDegress

func ToDegress(radians float64) float64

func ToRadians

func ToRadians(degrees float64) float64

Types

type Mat3

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

Mat3 is a 3x3 matrix.

func Mat3FromQuaternion

func Mat3FromQuaternion(q *Quaternion) *Mat3

Mat3FromQuaternion creates a matrix from the given Quaternion

func NewIdentityMat3

func NewIdentityMat3() *Mat3

NewIdentityMat3 creates a new Identity Matrix

func NewMat3

func NewMat3(e1 float64, e2 float64, e3 float64,
	e4 float64, e5 float64, e6 float64,
	e7 float64, e8 float64, e9 float64) *Mat3

NewMat3 creates a matrix with the given components

func NewZeroMat3

func NewZeroMat3() *Mat3

NewZeroMat3 creats a Matrix with zero components

func (*Mat3) Clone

func (mat *Mat3) Clone() *Mat3

Clone this matrix a new object

func (*Mat3) Element

func (mat *Mat3) Element(i int) float64

Element returns element at i

func (*Mat3) Elements

func (mat *Mat3) Elements() []float64

Elements creates the components for the matrix

func (*Mat3) GetTrace

func (mat *Mat3) GetTrace(v *Vec3) *Vec3

GetTrace returns the matrix diagonal elements

func (*Mat3) Multiply

func (mat *Mat3) Multiply(other *Mat3) *Mat3

Multiply Matrix multiplication

func (*Mat3) MultiplyVec

func (mat *Mat3) MultiplyVec(v *Vec3) *Vec3

MultiplyVec multiplicat given vector with Matrix

func (*Mat3) Scale

func (mat *Mat3) Scale(v *Vec3) *Mat3

Scale each column of the matrix

func (*Mat3) ScaleMultiply

func (mat *Mat3) ScaleMultiply(scale float64) *Mat3

ScaleMultiply Matrix-scalar multiplication

func (*Mat3) SetTrace

func (mat *Mat3) SetTrace(v *Vec3)

SetTrace sets the matrix diagonal elements from a Vec3

func (*Mat3) String

func (mat *Mat3) String() string

func (*Mat3) Transpose

func (mat *Mat3) Transpose() *Mat3

Transpose the matrix

type Quaternion

type Quaternion struct {
	X float64
	Y float64
	Z float64
	W float64
}

A Quaternion describes a rotation in 3D space. The Quaternion is mathematically defined as Q = x*i + y*j + z*k + w, where (i,j,k) are imaginary basis vectors. (x,y,z) can be seen as a vector related to the axis of rotation, while the real multiplier, w, is related to the amount of rotation.

func NewQuaternion

func NewQuaternion(x float64, y float64, z float64, w float64) *Quaternion

NewQuaternion creates a new quaternion with given values

func NewZeroQuaternion

func NewZeroQuaternion() *Quaternion

NewZeroQuaternion creates a new zero quaternion [0,0,0,1]

func QuaternionFromAxisAngle

func QuaternionFromAxisAngle(axis *Vec3, angle float64) *Quaternion

QuaternionFromAxisAngle creates the quaternion components from an axis and an angle

func QuaternionFromEuler

func QuaternionFromEuler(vec *Vec3) *Quaternion

QuaternionFromEuler creates the quaternion from the given euler angels

func QuaternionFromVectors

func QuaternionFromVectors(u *Vec3, v *Vec3) *Quaternion

QuaternionFromVectors creates a quaternion from the given two vectors.The resulting rotation will be the needed rotation to rotate u to v.

func (*Quaternion) Add

func (quaternion *Quaternion) Add(other *Quaternion) *Quaternion

func (*Quaternion) Clone

func (quaternion *Quaternion) Clone() *Quaternion

Clone this quaternion to new instance

func (*Quaternion) Conjugate

func (quaternion *Quaternion) Conjugate() *Quaternion

Conjugate calculates the quaternion conjugate

func (*Quaternion) Integrate

func (quaternion *Quaternion) Integrate(angularVelocity *Vec3, dt float64, angularFactor *Vec3) *Quaternion

Integrate rotate an absolute orientation quaternion given an angular velocity and a time step.

func (*Quaternion) Inverse

func (quaternion *Quaternion) Inverse() *Quaternion

Inverse calculates the inverse quaternion rotation.

func (*Quaternion) Length

func (quaternion *Quaternion) Length() float64

func (*Quaternion) Multiply

func (quaternion *Quaternion) Multiply(other *Quaternion) *Quaternion

Multiply this quaternion by the given

func (*Quaternion) MultiplyVec

func (quaternion *Quaternion) MultiplyVec(vec *Vec3) *Vec3

MultiplyVec multiply the quaternion by a vector

func (*Quaternion) Normalize

func (quaternion *Quaternion) Normalize() *Quaternion

Normalize the quaternion

func (*Quaternion) Set

func (quaternion *Quaternion) Set(x float64, y float64, z float64, w float64) *Quaternion

Set the value of the quaternion

func (*Quaternion) Slerp

func (quaternion *Quaternion) Slerp(toQuaternion *Quaternion, t float64) *Quaternion

Slerp performs a spherical linear interpolation between two quat

func (*Quaternion) String

func (quaternion *Quaternion) String() string

func (*Quaternion) ToAxisAngle

func (quaternion *Quaternion) ToAxisAngle() (*Vec3, float64)

ToAxisAngle converts the quaternion to axis/angle representation.

func (*Quaternion) ToEuler

func (quaternion *Quaternion) ToEuler() *Vec3

ToEuler convert the quaternion to euler angle representation, Order: YZX

type Range

type Range struct {
	Min float64
	Max float64
}

func NewRange

func NewRange(min float64, max float64) *Range

type Vec3

type Vec3 struct {
	X float64 `json:"x"`
	Y float64 `json:"y"`
	Z float64 `json:"z"`
}

Vec3 is a 3-dimensional vector

func ClampVec3

func ClampVec3(vec *Vec3, min float64, max float64) *Vec3

func NewUnitX

func NewUnitX() *Vec3

NewUnitX creates the vector (1,0,0)

func NewUnitY

func NewUnitY() *Vec3

NewUnitY creates the vector (0,1,0)

func NewUnitZ

func NewUnitZ() *Vec3

NewUnitZ creates the vector (0,0,1)

func NewVec3

func NewVec3(x float64, y float64, z float64) *Vec3

NewVec3 create a vector with theiven values

func NewZeroVec3

func NewZeroVec3() *Vec3

NewZeroVec3 creates a zero vector

func (*Vec3) Add

func (vec *Vec3) Add(x float64) *Vec3

func (*Vec3) AddVec

func (vec *Vec3) AddVec(other *Vec3) *Vec3

AddVec the given vector to this vector and retuns a new vector.

func (*Vec3) AlmostEquals

func (vec *Vec3) AlmostEquals(other *Vec3, precision float64) bool

AlmostEquals check if a vector equals is almost equal to another one.

func (*Vec3) AlmostZero

func (vec *Vec3) AlmostZero(precision float64) bool

AlmostZero check if a vector is almost zero

func (*Vec3) AngleTo

func (vec *Vec3) AngleTo(other *Vec3) float64

func (*Vec3) Clone

func (vec *Vec3) Clone() *Vec3

Clone create a copy of this vector

func (*Vec3) Cross

func (vec *Vec3) Cross(other *Vec3) *Vec3

Cross calculate the cross product

func (*Vec3) DistanceTo

func (vec *Vec3) DistanceTo(other *Vec3) float64

DistanceTo calculate distance from this point to another point

func (*Vec3) Divide

func (vec *Vec3) Divide(scale float64) *Vec3

func (*Vec3) DivideVec

func (vec *Vec3) DivideVec(other *Vec3) *Vec3

func (*Vec3) Dot

func (vec *Vec3) Dot(other *Vec3) float64

Dot calculate dot product

func (*Vec3) IsAntiparallelTo

func (vec *Vec3) IsAntiparallelTo(other *Vec3, precision float64) bool

IsAntiparallelTo check if the vector is anti-parallel to another vector.

func (*Vec3) Length

func (vec *Vec3) Length() float64

Length calculate the length of the vector

func (*Vec3) Lerp

func (vec *Vec3) Lerp(other *Vec3, t float64) *Vec3

Lerp do a linear interpolation between two vectors

func (*Vec3) Multiply

func (vec *Vec3) Multiply(scale float64) *Vec3

Multiply all the components of the vector with a scalar.

func (*Vec3) MultiplyVec

func (vec *Vec3) MultiplyVec(other *Vec3) *Vec3

MultiplyVec multiply the vector with an other vector, component-wise

func (*Vec3) Negate

func (vec *Vec3) Negate() *Vec3

Negate make the vector point in the opposite direction.

func (*Vec3) Normalize

func (vec *Vec3) Normalize() *Vec3

Normalize the vector. Note that this changes the values in the vector.

func (*Vec3) Set

func (vec *Vec3) Set(x float64, y float64, z float64) *Vec3

Set the given values to this vector

func (*Vec3) SetVec

func (vec *Vec3) SetVec(other *Vec3) *Vec3

SetVec set the given values from the given vector

func (*Vec3) SqrtDistanceTo

func (vec *Vec3) SqrtDistanceTo(other *Vec3) float64

SqrtDistanceTo calculate squared distance from this point to another point

func (*Vec3) SqrtLength

func (vec *Vec3) SqrtLength() float64

SqrtLength calculate the squared length of the vector.

func (*Vec3) String

func (vec *Vec3) String() string

func (*Vec3) Subtract

func (vec *Vec3) Subtract(x float64) *Vec3

func (*Vec3) SubtractVec

func (vec *Vec3) SubtractVec(other *Vec3) *Vec3

SubtractVec the given vector from this vector and retuns a new vector.

func (*Vec3) Tangents

func (vec *Vec3) Tangents(t1 *Vec3, t2 *Vec3)

Tangents compute two artificial tangents to the vector

func (*Vec3) Unit

func (vec *Vec3) Unit() *Vec3

Unit returns the version of this vector that is of length 1.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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