# quaternion

package
Version: v0.0.0-...-20a26e3 Latest Latest

Go to latest
Published: Jul 28, 2021 License: MIT

## Documentation ¶

### Overview ¶

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

### 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) float32`

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]float32`

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 float32) T`

FromAxisAngle returns a quaternion representing a rotation around and axis.

#### func FromEulerAngles ¶

`func FromEulerAngles(yHead, xPitch, zRoll float32) T`

FromEulerAngles returns a quaternion representing Euler angle rotations.

#### func FromVec4 ¶

`func FromVec4(v *vec4.T) T`

FromVec4 converts a vec4.T into a quaternion.

#### func FromXAxisAngle ¶

`func FromXAxisAngle(angle float32) T`

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

#### func FromYAxisAngle ¶

`func FromYAxisAngle(angle float32) T`

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

#### func FromZAxisAngle ¶

`func FromZAxisAngle(angle float32) 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)`

#### func Slerp ¶

`func Slerp(a, b *T, t float32) 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 float32)`

AxisAngle extracts the rotation in 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 float32) 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() float32`

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 (quat *T) String() string`

#### func (*T) Vec4 ¶

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

Vec4 converts the quaternion into a vec4.T.