quaternion

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: May 25, 2025 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const PixelsPerRadian = 150

Variables

View Source
var DualIdentity = Dual{Real: Identity}

DualIdentity returns the Dual Quaternion that induces zero translation and zero rotation when multiplied with another Dual Quaternion.

View Source
var Identity = Quat{0, 0, 0, 1}

Identity is the Identity quaternion

Functions

This section is empty.

Types

type Dual

type Dual struct{ Real, Dual Quat }

Dual is a concatenated Translation*Rotation. A point transformed with it, first has rotation applied and then translation. This behavior is identical to the order a homogenous matrix would perform the operation.

func DQ

func DQ(tx, ty, tz float64, r Quat) Dual

DQ is shorthand for Translate(x,y,z).Rotate(r).

func (Dual) Add

func (lhs Dual) Add(rhs Dual) Dual

func (Dual) Conjugate

func (dq Dual) Conjugate() Dual

func (Dual) Dot

func (lhs Dual) Dot(rhs Dual) float64

func (Dual) Equal

func (lhs Dual) Equal(rhs Dual) bool

func (Dual) Matrix

func (dq Dual) Matrix() matrix.Matrix

Matrix will return a matrix with 4 rows and 4 columns, the top left 3x3 matrix contains the rotation and the top right 3x1 vector contains the translation. It takes 38 muls, 28 adds to derive a homogenous matrix from the dual quaternion.

func (Dual) Mul

func (lhs Dual) Mul(rhs Dual) Dual

Mul multiplies two dual quaternions. Uses 3 quaternion muls and 1 quaternion add. In total this uses 48 muls and 40 adds.

func (Dual) Normalize

func (dq Dual) Normalize() Dual

func (Dual) Rotate

func (dq Dual) Rotate(r Quat) Dual

func (Dual) Rotation

func (dq Dual) Rotation() Quat

func (Dual) Scale

func (dq Dual) Scale(scale float64) Dual

func (Dual) String

func (dq Dual) String() string

func (Dual) Transform

func (dq Dual) Transform(x, y, z float64) (float64, float64, float64)

Transform will transform a vector in the space described by the dual quaternion and transform that into the parent space. This takes 37 muls, 27 adds. By comparison a homogenous matrix transform takes 9 muls and 9 adds but needs to have the Matrix extracted first.

func (Dual) Translate

func (dq Dual) Translate(tx, ty, tz float64) Dual

func (Dual) Translation

func (dq Dual) Translation() (x, y, z float64)

Translation will extract the translation vector from the Dual quaternion. To extract the translation 19 muls, 12 adds are needed

type Quat

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

Quat is used for computing quaterion multiplications. This creates more natural mouse rotations.

Attribution: adapted from http://glprogramming.com/codedump/godecho/quaternion.html

func AxisAngle

func AxisAngle(x, y, z, angle float64) Quat

AxisAngle returns a quaternion representing a rotation about an axis. The axis is defined by the vector (x, y, z) and the rotation angle is specified in radians. If the axis vector is zero, the function returns the Identity quaternion.

func Q

func Q(x, y, z, w float64) Quat

func RotX

func RotX(angle float64) Quat

func RotY

func RotY(angle float64) Quat

func RotZ

func RotZ(angle float64) Quat

func (Quat) Add

func (lhs Quat) Add(rhs Quat) Quat

Add returns the sum of two quaternions. This takes 4 adds.

func (Quat) Conjugate

func (q Quat) Conjugate() Quat

func (Quat) Dot

func (lhs Quat) Dot(rhs Quat) float64

Dot returns the quaternion dot product (inner product) of the target (q) and r. (For two normalized quaternions, this will be 1 if they’re equal, -1 if they’re opposite and 0 if they’re perpendicular.)

func (Quat) Equal

func (lhs Quat) Equal(rhs Quat) bool

func (Quat) Length

func (q Quat) Length() float64

func (Quat) Matrix

func (q Quat) Matrix() matrix.Matrix

Matrix will return a matrix with 4 rows and 4 columns, the top left 3x3 matrix contains the rotation. Computing the 4x4 homogeneous matrix from the quaternion takes 18 muls and 12 adds

func (Quat) Mul

func (lhs Quat) Mul(rhs Quat) Quat

Mul calculates the Hamilton product of 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). This operation takes 16 muls and 12 adds or an alternative implemnentation can do it in 9 muls and 27 adds. It's not known whether adds on modern x86 cpu's are still faster than muls.

func (Quat) Normalize

func (q Quat) Normalize() Quat

func (Quat) RotX

func (q Quat) RotX(angle float64) Quat

RotX multiplies a quaternion with a Rotation around the x-axis. q' = qqX

func (Quat) RotY

func (q Quat) RotY(angle float64) Quat

RotY multiplies a quaternion with a Rotation around the y-axis. q' = qqY

func (Quat) RotZ

func (q Quat) RotZ(angle float64) Quat

RotZ multiplies a quaternion with a Rotation around the z-axis. q' = qqZ

func (Quat) Scale

func (q Quat) Scale(scale float64) Quat

func (Quat) String

func (q Quat) String() string

func (Quat) Transform

func (q Quat) Transform(vx, vy, vz float64) (x, y, z float64)

Transform will perform q*v*q' on the passed in vector. This takes 18 muls, 12 adds to compute.

Jump to

Keyboard shortcuts

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