@xloxlolex/quaternion-math
v1.1.0
Published
Fast and easy-to-use Quaternion Math library powered by TypeScript
Downloads
16
Maintainers
Readme
TypeScript Quaternion Math
Fast and easy-to-use Quaternion Math library powered by TypeScript
Installation
Install @xloxlolex/quaternion-math with npm
mkdir my-project
cd my-project
npm install @xloxlolex/quaternion-math
Usage
Import
import { Quaternion } from '@xloxlolex/quaternion-math';
Constructor
// Creates a new Quaternion with given x, y, z and w components.
// All components are optional and, if not specified, will be set to Quaternion.identity by default.
Quaternion(x?: number, y?: number, z?: number, w?: number);
Static Variables
Quaternion.identity; // Quaternion(0, 0, 0, 1).
Static Methods
// Create a Quaternion from Euler angles.
Quaternion.Euler(v: Vector3): Quaternion;
// Normalizes a Quaternion.
Quaternion.Normalize(q: Quaternion): Quaternion;
// Returns the angle in degrees from one Quaternion to another.
Quaternion.Angle(from: Quaternion, to: Quaternion): number;
// Returns a copy of a Quaternion with its magnitude clamped to maxLength.
Quaternion.ClampMagnitude(quaternion: Quaternion, maxLength: number): Quaternion;
// Rotates a Quaternion towards another with a max degree of maxDegreesDelta.
Quaternion.RotateTowards(from: Quaternion, to: Quaternion, maxDegreesDelta: number): Quaternion;
// Spherical Linear Interpolation between two Quaternions. If t is lower than 0, return "from". If t is greater than 1, return "to".
Quaternion.Slerp(from: Quaternion, to: Quaternion, t: number): Quaternion;
// Spherical Linear Interpolation between two Quaternions.
Quaternion.SlerpUnclamped(from: Quaternion, to: Quaternion, t: number): Quaternion;
// Rotates a point with a given rotation.
Quaternion.RotatePoint(rotation: Quaternion, point: Vector3): Vector3;
// The dot product between two Quaternions.
Quaternion.Dot(lhs: Quaternion, rhs: Quaternion): number;
// Returns the length of a given Quaternion.
Quaternion.Magnitude(quaternion: Quaternion): number;
// Add two Quaternions.
Quaternion.Add(lhs: Quaternion, rhs: Quaternion): Quaternion;
// Subtract two Quaternions.
Quaternion.Subtract(lhs: Quaternion, rhs: Quaternion): Quaternion;
// Combines rotations lhs and rhs.
Quaternion.Multiply(lhs: Quaternion, rhs: Quaternion): Quaternion;
// Divides two Quaternions (lhs / rhs).
Quaternion.Divide(lhs: Quaternion, rhs: Quaternion): Quaternion;
// Checks whether the lhs and the rhs Quaternions are the same.
Quaternion.Equals(lhs: Quaternion, rhs: Quaternion): Quaternion;
Public Variables
var quaternion = new Quaternion();
quaternion.x; // X component of the Quaternion.
quaternion.y; // Y component of the Quaternion.
quaternion.z; // Z component of the Quaternion.
quaternion.w; // W component of the Quaternion.
quaternion.normalized; // Returns this Quaternion with a magnitude of 1 (Read Only).
quaternion.magnitude; // Returns the length of this Quaternion.
quaternion.sqrMagnitude; // Returns the squared length of this Quaternion.
quaternion.conjugate; // Returns the conjugate of this Quaternion.
quaternion.inverse; // Returns the inverse of this Quaternion.
quaternion.eulerAngles; // Returns the Euler angles representation of this Quaternion.
Public Methods
var quaternion = new Quaternion();
// Add a Quaternion to this Quaternion.
quaternion.Add(other: Quaternion): void;
// Subtract a Quaternion from this Quaternion.
quaternion.Subtract(other: Quaternion): void;
// Combines rotations between this Quaternion and another.
quaternion.Multiply(other: Quaternion): void;
// Divides two Quaternions (this / other).
quaternion.Divide(other: Quaternion): void;
// Checks whether this Quaternion and another are the same.
quaternion.Equals(other: Quaternion): boolean;
Dependencies
Authors
License
Support
For support, email [email protected].