Skip to main content

Quaternionf

TypeNameInterface Description
Variablesx: number

Function: The X component of the quaternion.

Variablesy: number

Function: The Y component of the quaternion.

Variablesz: number

Function: The Z component of the quaternion.

Variablesw: number

Function: The W component of the quaternion.

Functionsconstructor()

Function: Creates a default quaternion with x, y, z, and w all initialized to 0.

Examples

x: number

let x = q.x;

y: number

let y = q.y;

z: number

let z = q.z;

w: number

let w = q.w;

constructor()

let quat = new Quaternionf();

Use Case

@component()
export class NewBehaviourScript extends APJS.BasicScriptComponent {

onStart() {
let quat = new APJS.Quaternionf();
quat.x = 1;
quat.y = 2;
quat.z = 3;
quat.w = 4;
const result = quat.toString();

}
onUpdate(deltaTime: number) {
}
}
TypeNameInterface Description
Functionsconstructor(x: number, y: number, z: number, w: number)

Function: Creates a quaternion with specified x, y, z, and w values.

Example

let quat = new Quaternionf(1, 0, 0, 0);

Use Case

@component()
export class NewBehaviourScript extends APJS.BasicScriptComponent {

onStart() {
let quat = new APJS.Quaternionf(1,2,3,4);
const result = quat.toString();

}
onUpdate(deltaTime: number) {
}
}
TypeNameInterface Description
Functionsset(x: number, y: number, z: number, w: number): this

Function: Sets the x, y, z, and w components of the quaternion.

Example

let quat = new Quaternionf();
quat.set(1, 0, 0, 0);

Use Case

@component()
export class NewBehaviourScript extends APJS.BasicScriptComponent {

onStart() {
let quat = new APJS.Quaternionf();
quat.set(1, 2, 3, 4);
const result = quat.toString();

}
onUpdate(deltaTime: number) {
}
}
TypeNameInterface Description
Functionsclone(): Quaternion

Function: Clone the current quaternion.

Example

let quat = new Quaternionf(1, 0, 0, 0);
let cloneQuat = quat.clone();

Use Case

@component()
export class NewBehaviourScript extends APJS.BasicScriptComponent {

onStart() {
let quat = new APJS.Quaternionf(1,2,3,4);
let cloneQuat = quat.clone();
const result = cloneQuat.toString();

}
onUpdate(deltaTime: number) {
}
}
TypeNameInterface Description
Functionsdot(other: Quaternion): number

Function: Calculate the dot product of the current quaternion and another quaternion.

Example

let quat1 = new Quaternionf(1, 0, 0, 0);
let quat2 = new Quaternionf(0, 1, 0, 0);
let dotProduct = quat1.dot(quat2);

Use Case

@component()
export class NewBehaviourScript extends APJS.BasicScriptComponent {

onStart() {
let quat1 = new APJS.Quaternionf(1,2,3,4);
let quat2 = new APJS.Quaternionf(1,2,3,4);
const result = quat2.dot(quat1);

}
onUpdate(deltaTime: number) {
}
}
TypeNameInterface Description
Functionsequals(other: Quaternion): boolean

Function: Checks whether the current quaternion is equal to another quaternion.

Example

let quat1 = new Quaternionf(1, 0, 0, 0);
let quat2 = new Quaternionf(1, 0, 0, 0);
console.log(quat1.equals(quat2)); // true

Use Case

@component()
export class NewBehaviourScript extends APJS.BasicScriptComponent {

onStart() {
let quat1 = new APJS.Quaternionf(1,2,3,4);
let quat2 = new APJS.Quaternionf(1,2,3,4);
const result = quat2.equals(quat1);

}
onUpdate(deltaTime: number) {
}
}
TypeNameInterface Description
FunctionsgetAngle(): number

Function: Obtains the rotation angle represented by a quaternion.

FunctionsgetAxis(): Vector3f

Function: Get the rotation axis represented by a quaternion.

Examples

getAngle(): number

let quat = new Quaternionf(1, 0, 0, 0);
let angle = quat.getAngle();

getAxis(): Vector3f

let quat = new Quaternionf(1, 0, 0, 0);
let axis = quat.getAxis();

Use Case

@component()
export class NewBehaviourScript extends APJS.BasicScriptComponent {

onStart() {
let quat1 = new APJS.Quaternionf(1,2,3,4);
const result = `Angle: ${quat.getAngle()}\nAxis: ${quat.getAxis()}`;

}
onUpdate(deltaTime: number) {
}
}
TypeNameInterface Description
Functionsinverse(): this

Function: Invert the current quaternion.

Example

let quat = new Quaternionf(1, 0, 0, 0);
quat.invert();

Use Case

@component()
export class NewBehaviourScript extends APJS.BasicScriptComponent {

onStart() {
let quat0 = new APJS.Quaternionf(1,2,3,4);
quat0.inverse();
const result = `inverse: ${quat0.toString()}`;

}
onUpdate(deltaTime: number) {
}
}
TypeNameInterface Description
Functionsmultiply(other: Quaternion): this

Function: Multiply the current quaternion by another quaternion.

Example

let quat1 = new Quaternionf(1, 0, 0, 0);
let quat2 = new Quaternionf(0, 1, 0, 0);
quat1.multiply(quat2);

Use Case

@component()
export class NewBehaviourScript extends APJS.BasicScriptComponent {

onStart() {
let quat0 = new APJS.Quaternionf(1,2,3,4);
let quat1 = new APJS.Quaternionf(1,2,3,4);
quat0.multiply(quat1);
const result = ` ${quat0.toString()}`;

}
onUpdate(deltaTime: number) {
}
}
TypeNameInterface Description
FunctionsmultiplyVector(other: Vector3f): Vector3f

Function: Multiply the current quaternion by a three-dimensional vector.

Example

let quat = new Quaternionf(1, 0, 0, 0);
let vec = new Vector3f(1, 2, 3);
let resultVec = quat.multiplyVec3(vec);

Use Case

@component()
export class NewBehaviourScript extends APJS.BasicScriptComponent {

onStart() {
let quat0 = new APJS.Quaternionf(1,2,3,4);
let quat1 = new APJS.Quaternionf(1,2,3,4);
quat0.multiplyVector(quat1);
const result = ` ${quat0.toString()}`;

}
onUpdate(deltaTime: number) {
}
}
TypeNameInterface Description
Functionsnormalize(): this

Function: Normalize the current quaternion so that its length is 1.

Example

let quat = new Quaternionf(1, 2, 3, 4);
quat.normalize();

Use Case

@component()
export class NewBehaviourScript extends APJS.BasicScriptComponent {

onStart() {
let quat0 = new APJS.Quaternionf(1,2,3,4);
quat0.normalize();
const result = ` ${quat0.toString()}`;

}
onUpdate(deltaTime: number) {
}
}
TypeNameInterface Description
FunctionstoEulerAngles(): Vector3f

Function: Convert the current quaternion to Euler angles.

Example

let quat = new Quaternionf(1, 0, 0, 0);
let eulerAngles = quat.toEulerAngles();

Use Case

@component()
export class NewBehaviourScript extends APJS.BasicScriptComponent {

onStart() {
let quat0 = new APJS.Quaternionf(1,2,3,4);
let euler = quat0.toEulerAngles();
const result = ` ${euler.toString()}`;

}
onUpdate(deltaTime: number) {
}
}
TypeNameInterface Description
FunctionstoString(): string

Function: Returns the string representation of the current quaternion.

Example

let quat = new Quaternionf(1, 0, 0, 0);
console.log(quat.toString()); // "(1, 0, 0, 0)"

Use Case

@component()
export class NewBehaviourScript extends APJS.BasicScriptComponent {

onStart() {
let quat0 = new APJS.Quaternionf(1,2,3,4);

const result = ` ${quat0.toString()}`;

}
onUpdate(deltaTime: number) {
}
}
TypeNameInterface Description
Static FunctionsmakeFromAngleAxis(angle: number, axis: Vector3f): Quaternion

Function: Create a quaternion based on the rotation angle and rotation axis.

Example

let angle = Math.PI / 2;
let axis = new Vector3f(0, 1, 0);
let quat = Quaternionf.makeFromAngleAxis(angle, axis);

Use Case

@component()
export class NewBehaviourScript extends APJS.BasicScriptComponent {

onStart() {
let quat0 = new APJS.Quaternionf.makeFromAngleAxis(1,new APJS.Vector3f(2,3,4));
const result = ` ${quat0.toString()}`;

}
onUpdate(deltaTime: number) {
}
}
TypeNameInterface Description
Static FunctionsmakeFromEulerAngles(vec: Vector3f): Quaternion

Function: Create a quaternion from Euler angles.

Example

let eulerVec = new Vector3f(Math.PI / 2, 0, 0);
let quat = Quaternionf.makeFromEuler(eulerVec);

Use Case

@component()
export class NewBehaviourScript extends APJS.BasicScriptComponent {

onStart() {
const DegreeToRadian = Math.PI / 180;

let quat = APJS.Quaternionf.makeFromEulerAngles(this.euler.multiplyScalar(DegreeToRadian));
const result = ` ${quat.toString()}`;

}
onUpdate(deltaTime: number) {
}
}
TypeNameInterface Description
Static FunctionsangleBetween(a: Quaternion, b: Quaternion): number

Function: Calculate the angle between two quaternions.

Example

let quat1 = new Quaternionf(1, 0, 0, 0);
let quat2 = new Quaternionf(0, 1, 0, 0);
let angle = Quaternionf.angleBetween(quat1, quat2);

Use Case

@component()
export class NewBehaviourScript extends APJS.BasicScriptComponent {

onStart() {
let quat0 = new APJS.Quaternionf(1,2,3,4);
let quat1 = new APJS.Quaternionf(2,4,3,4);
const result = APJS.Quaternionf.angleBetween(quat0, quat1);
}
onUpdate(deltaTime: number) {
}
}
TypeNameInterface Description
Static Functionsidentity(): Quaternion

Function: Returns a quaternion representing a unit quaternion.

Example

let identityQuat = Quaternionf.identity();

Use Case

@component()
export class NewBehaviourScript extends APJS.BasicScriptComponent {

onStart() {
let quat0 = APJS.Quaternionf.identity();
const result = `Angle: ${quat0.toString()}`;

}
onUpdate(deltaTime: number) {
}
}
TypeNameInterface Description
Static Functionsslerp(a: Quaternion, b: Quaternion, t: number): Quaternion

Function: Calculate the spherical linear interpolation between two quaternions.

Example

let quat1 = new Quaternionf(1, 0, 0, 0);
let quat2 = new Quaternionf(0, 1, 0, 0);
let slerpQuat = Quaternionf.slerp(quat1, quat2, 0.5);

Use Case

@component()
export class NewBehaviourScript extends APJS.BasicScriptComponent {

onStart() {
let quat0 = new APJS.Quaternionf(1,2,3,4);
let quat1 = new APJS.Quaternionf(2,4,3,4);
var quat = APJS.Quaternionf.slerp(quat0, quat1, 0.5)
}
onUpdate(deltaTime: number) {
}
}
TypeNameInterface Description
Static FunctionslookAtRotate(start: Vector3f, up: Vector3f): Quaternion

Function: Create a quaternion based on the forward vector and the up vector.

Example

let forward = new Vector3f(0, 0, -1);
let up = new Vector3f(0, 1, 0);
let quat = Quaternionf.lookAt(forward, up);

Use Case

@component()
export class NewBehaviourScript extends APJS.BasicScriptComponent {

onStart() {
let forward = new Vector3f(0, 0, -1);
let up = new Vector3f(0, 1, 0);
let quat = Quaternionf.lookAt(forward, up);

}
onUpdate(deltaTime: number) {
}
}
TypeNameInterface Description
Static FunctionsrotationFromTo(from: Vector3f, to: Vector3f): Quaternion

Function: Create a quaternion representing rotation based on two vectors.

Example

let from = new Vector3f(1, 0, 0);
let to = new Vector3f(0, 1, 0);
let quat = Quaternionf.rotationFromTo(from, to);

Use Case

@component()
export class NewBehaviourScript extends APJS.BasicScriptComponent {

onStart() {
let vfrom = new APJS.Vector3f(1,2,3);
let vTo = new APJS.Vector3f(2,2,3);
var quat = APJS.Quaternionf.rotationFromTo(vfrom, vTo);
const result = ` ${quat.toString()}`;

}
onUpdate(deltaTime: number) {
}
}
Copyright © 2025 TikTok. All rights reserved.
About TikTokHelp CenterCareersContactLegalCookies