Documentation
¶
Overview ¶
Package Quaternion provides a unit quaternion used for representing 3D rotations.
Index ¶
- Variables
- func AngleBetween(q, other IJKX) Angle.Radians
- func AngleInRadians(q IJKX) Angle.Radians
- func AsArray(vec IJKX) [4]Float.X
- func AsBasis(q IJKX) Basis.XYZ
- func Axis(q IJKX) Vector3.XYZ
- func Dot(q, other IJKX) Float.X
- func EulerAngles(order Angle.Order, q IJKX) Angle.Euler3D
- func IsApproximatelyEqual(q, other IJKX) bool
- func IsFinite(q IJKX) bool
- func IsNormalized(q IJKX) bool
- func Length(q IJKX) Float.X
- func LengthSquared(q IJKX) Float.X
- type IJKX
- func Add(a, b IJKX) IJKX
- func AddX[X Int.Any | Float.Any](a IJKX, b X) IJKX
- func Div(a, b IJKX) IJKX
- func DivX[X Int.Any | Float.Any](a IJKX, b X) IJKX
- func Euler(e Angle.Euler3D) IJKX
- func Exponential(q IJKX) IJKX
- func Inverse(q IJKX) IJKX
- func Log(q IJKX) IJKX
- func Mul(a, b IJKX) IJKX
- func MulX[X Int.Any | Float.Any](a IJKX, b X) IJKX
- func Neg(v IJKX) IJKX
- func New() IJKX
- func Normalized(q IJKX) IJKX
- func Slerp[X Float.Any](a, b IJKX, weight X) IJKX
- func Slerpni[X Float.Any](a, b IJKX, weight X) IJKX
- func SphericalCubicInterpolate[X Float.Any](a, b, pre_a, post_b IJKX, weight X) IJKX
- func SphericalCubicInterpolateInTime[X Float.Any](a, b, pre_a, post_b IJKX, weight, b_t, pre_a_t, post_b_t X) IJKX
- func Sub(a, b IJKX) IJKX
- func SubX[X Int.Any | Float.Any](a IJKX, b X) IJKX
Constants ¶
This section is empty.
Variables ¶
var Identity = IJKX{X: 1}
Identity quaternion, representing no rotation. This has the same rotation as [Basis.Identity].
If a Vector3 is rotated (multiplied) by this quaternion, it does not change.
Functions ¶
func AngleBetween ¶
AngleTo Returns the angle between this quaternion and to. This is the magnitude of the angle you would need to rotate by to get from one to the other.
Note: The magnitude of the floating-point error for this method is abnormally high, so methods such as [IsApproximatelyZero] will not work reliably.
func AngleInRadians ¶
AngleInRadians returns the angle of the rotation represented by this quaternion.
Note: The quaternion must be normalized.
func EulerAngles ¶
EulerAngles returns the quaternion's rotation in the form of Euler angles. The Euler order depends on the order parameter, for example using the YXZ convention: since this method decomposes, first Z, then X, and Y last. See the EulerOrder enum for possible values. The returned vector contains the rotation angles in the format (X angle, Y angle, Z angle).
func IsApproximatelyEqual ¶
IsApproximatelyEqual returns true if this quaternion and to are approximately equal, by running IsApproximatelyEqual on each component.
func IsFinite ¶
IsFinite returns true if this quaternion is finite, by calling IsFinite on each component.
func IsNormalized ¶
IsNormalized returns whether the quaternion is normalized or not.
func LengthSquared ¶
LengthSquared returns the length of the quaternion, squared.
Types ¶
type IJKX ¶
type IJKX = struct { I Float.X // I component of the quaternion. This is the value along the "imaginary" i axis. J Float.X // J component of the quaternion. This is the value along the "imaginary" j axis. K Float.X // K component of the quaternion. This is the value along the "imaginary" k axis. X Float.X // X component of the quaternion. This is the value along the "real" axis. }
The Quaternion built-in Variant type is a 4D data structure that represents rotation in the form of a Hamilton convention quaternion. Compared to the Basis type which can store both rotation and scale, quaternions can only store rotation.
A Quaternion is composed by 4 floating-point components: x, i, j, and k. These components are very compact in memory, and because of this some operations are more efficient and less likely to cause floating-point errors. Methods such as [Angle], Axis, and Slerp are faster than their Basis counterparts.
For a great introduction to quaternions, see this video by 3Blue1Brown. You do not need to know the math behind quaternions, as this package provides several helper methods that handle it for you. These include Slerp and SphericalCubicInterpolate, as well as Mul.
Note: Quaternions must be normalized before being used for rotation (see normalized).
Note: Similarly to Vector2 and Vector3, the components of a quaternion use 32-bit precision by default, unlike float which is always 64-bit. If double precision is needed, compile with the Go build tag 'precision_double'.
func Exponential ¶
Exponential returns the exponential of this quaternion. The rotation axis of the result is the normalized rotation axis of this quaternion, the angle of the result is the length of the vector part of this quaternion.
func Log ¶
Log returns the logarithm of this quaternion. Multiplies this quaternion's rotation axis by its rotation angle, and stores the result in the returned quaternion's vector part (x, y, and z). The returned quaternion's real part (w) is always 0.0.
func Normalized ¶
Normalized returns a copy of the quaternion, normalized to unit length.
func Slerp ¶
Slerp returns the result of the spherical linear interpolation between this quaternion and to by amount weight.
Note: Both quaternions must be normalized.
func Slerpni ¶
Slerpni returns the result of the spherical linear interpolation between this quaternion and to by amount weight, but without checking if the rotation path is not bigger than 90 degrees.
func SphericalCubicInterpolate ¶
SphericalCubicInterpolate performs a spherical cubic interpolation between quaternions pre_a, this vector, b, and post_b, by the given amount weight.
func SphericalCubicInterpolateInTime ¶
func SphericalCubicInterpolateInTime[X Float.Any](a, b, pre_a, post_b IJKX, weight, b_t, pre_a_t, post_b_t X) IJKX
SphericalCubicInterpolateInTime performs a spherical cubic interpolation between quaternions pre_a, this vector, b, and post_b, by the given amount weight.
It can perform smoother interpolation than spherical_cubic_interpolate by the time values.