quaternion

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2023 License: MIT Imports: 4 Imported by: 1

Documentation

Overview

Package quaternion contains a float64 unit-quaternion type T and functions.

Index

Constants

This section is empty.

Variables

View Source
var (
	// Zero holds a zero quaternion.
	Zero = T{}

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

Functions

func Dot

func Dot(a, b *T) float64

Dot returns the dot product of two quaternions.

func IsShortestRotation

func IsShortestRotation(a, b *T) bool

IsShortestRotation returns if the rotation from a to b is the shortest possible rotation. (there are two directions to rotate from the orientation of quat to the orientation of other) See T.SetShortestRotation

Types

type T

type T [4]float64 // [0, 1, 2, 3] => x, y, z, w

T represents a orientatin/rotation as a unit quaternion. See http://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation

func FromAxisAngle

func FromAxisAngle(axis *vec3.T, angle float64) T

FromAxisAngle returns a quaternion representing a rotation around an axis.

func FromEulerAngles

func FromEulerAngles(yHead, xPitch, zRoll float64) T

FromEulerAngles returns a quaternion representing Euler angle rotations.

func FromRotationAxes added in v0.0.3

func FromRotationAxes(xAxis, yAxis, zAxis vec3.T) T

FromRotationAxes returns a quaternion from the columns of a 3x3 rotation matrix.

func FromVec4

func FromVec4(v *vec4.T) T

FromVec4 converts a vec4.T into a quaternion.

func FromXAxisAngle

func FromXAxisAngle(angle float64) T

FromXAxisAngle returns a quaternion representing a rotation around the x axis.

func FromYAxisAngle

func FromYAxisAngle(angle float64) T

FromYAxisAngle returns a quaternion representing a rotation around the y axis.

func FromZAxisAngle

func FromZAxisAngle(angle float64) T

FromZAxisAngle returns a quaternion representing a rotation around the z axis.

func Mul

func Mul(a, b *T) T

Mul multiplies two quaternions.

func Mul3

func Mul3(a, b, c *T) T

Mul3 multiplies three quaternions.

func Mul4

func Mul4(a, b, c, d *T) T

Mul4 multiplies four quaternions.

func Parse

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

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

func Slerp

func Slerp(a, b *T, t float64) T

Slerp returns the spherical linear interpolation quaternion between a and b at t (0,1). See http://en.wikipedia.org/wiki/Slerp

func Vec3Diff

func Vec3Diff(a, b *vec3.T) T

Vec3Diff returns the rotation quaternion between two vectors.

func (*T) AxisAngle

func (quat *T) AxisAngle() (axis vec3.T, angle float64)

AxisAngle extracts the rotation from a normalized quaternion in the form of an axis and a rotation angle.

func (*T) Invert

func (quat *T) Invert() *T

Invert inverts the quaterion.

func (*T) Inverted

func (quat *T) Inverted() T

Inverted returns an inverted copy of the quaternion.

func (*T) IsUnitQuat

func (quat *T) IsUnitQuat(tolerance float64) bool

IsUnitQuat returns if the quaternion is within tolerance of the unit quaternion.

func (*T) Negate

func (quat *T) Negate() *T

Negate negates the quaternion.

func (*T) Negated

func (quat *T) Negated() T

Negated returns a negated copy of the quaternion.

func (*T) Norm

func (quat *T) Norm() float64

Norm returns the norm value of the quaternion.

func (*T) Normalize

func (quat *T) Normalize() *T

Normalize normalizes to a unit quaternation.

func (*T) Normalized

func (quat *T) Normalized() T

Normalized returns a copy normalized to a unit quaternation.

func (*T) RotateVec3

func (quat *T) RotateVec3(v *vec3.T)

RotateVec3 rotates v by the rotation represented by the quaternion.

func (*T) RotatedVec3

func (quat *T) RotatedVec3(v *vec3.T) vec3.T

RotatedVec3 returns a rotated copy of v.

func (*T) SetShortestRotation

func (quat *T) SetShortestRotation(other *T) *T

SetShortestRotation negates the quaternion if it does not represent the shortest rotation from quat to the orientation of other. (there are two directions to rotate from the orientation of quat to the orientation of other) See IsShortestRotation()

func (T) String

func (q T) String() string

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

func (T) ToEuler added in v0.0.4

func (q T) ToEuler() (rotX, rotY, rotZ float64)

ToEuler converts a quaternion to Euler angles. Currently, only XYZ order is supported.

func (*T) Vec4

func (quat *T) Vec4() vec4.T

Vec4 converts the quaternion into a vec4.T.

Jump to

Keyboard shortcuts

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