Class Quaternion
Paket: @aspose/3d (v24.12.0)
Quaternion wird im gesamten @aspose/3d API verwendet, um Rotationen ohne Gimbal-Lock darzustellen. Es ist der Typ, der zurückgegeben wird von Transform.rotation und GlobalTransform.rotation. Der Identitäts-Quaternion (1, 0, 0, 0) stellt keine Rotation dar. Quaternion wird exportiert aus dem @aspose/3d/utilities Unterpfad.
export class Quaternionimport { Quaternion } from '@aspose/3d/utilities';Enumerations
Drehe einen Knoten um 90° um die Y‑Achse und interpolieren dann sanft zurück zur Identität.
import { Scene } from '@aspose/3d';
import { Quaternion } from '@aspose/3d/utilities';
const scene = new Scene();
const node = scene.rootNode.createChildNode('spinner');
// 90° around Y
const q90 = Quaternion.fromEulerAngle(0, Math.PI / 2, 0);
node.transform.rotation = q90;
// Slerp halfway back to identity
const identity = Quaternion.IDENTITY;
const half = Quaternion.slerp(0.5, q90, identity);
console.log(`Half rotation W: ${half.w.toFixed(4)}`);
// Half rotation W: 0.9239
Enumerations
| Enumerations | Enumerations |
|---|---|
new Quaternion() | Erzeugt den Identitäts-Quaternion (1, 0, 0, 0). |
new Quaternion(w, x, y, z) | Erstellt ein Quaternion aus expliziten Komponenten. |
Enumerations
| Enumerations | Enumerations | Enumerations |
|---|---|---|
w | number | Skalar (reelle) Komponente. Für ein Einheitsrotations-Quaternion, w = cos(θ/2). |
x | number | X-Komponente des Vektorteils. |
y | number | Y-Komponente des Vektorteils. |
z | number | Z-Komponente des Vektorteils. |
length | number (schreibgeschützt) | Betrag: sqrt(w² + x² + y² + z²). Sollte 1.0 für ein gültiges Rotations-Quaternion sein. |
Statische Eigenschaften
| Enumerations | Enumerations | Enumerations |
|---|---|---|
Quaternion.IDENTITY | Quaternion | Gibt ein neues Identitäts-Quaternion zurück (1, 0, 0, 0). |
Statische Methoden
Quaternion.fromEulerAngle(pitch, yaw, roll)
Erstellt ein Quaternion aus Euler‑Winkeln im Bogenmaß.
static fromEulerAngle(pitch: number, yaw: number, roll: number): Quaternion
static fromEulerAngle(vec: Vector3): QuaternionEnumerations
pitch number — Rotation um die X-Achse in Radiant.
yaw number — Rotation um die Y-Achse in Radianten.
roll number — Rotation um die Z-Achse in Radianten.
Alternativ ein einzelnes Vector3 dessen x, y, z enthält Pitch, Yaw und Roll.
Enumerations
import { Quaternion } from '@aspose/3d/utilities';
const q = Quaternion.fromEulerAngle(0, Math.PI / 4, 0); // 45° around Y
console.log(`W: ${q.w.toFixed(4)}`); // W: 0.9239
Quaternion.fromAngleAxis(angle, axis)
Erstellt ein Quaternion, das eine Rotation von angle Radianten um axis.
static fromAngleAxis(angle: number, axis: Vector3): QuaternionEnumerations
angle number — Rotationswinkel in Radianten.
axis Vector3 — Die Rotationsachse. Muss nicht normalisiert werden.
Enumerations
import { Quaternion, Vector3 } from '@aspose/3d/utilities';
const axis = new Vector3(0, 1, 0);
const q = Quaternion.fromAngleAxis(Math.PI / 2, axis);
console.log(`Rotating 90° around Y — W: ${q.w.toFixed(4)}`);
// Rotating 90° around Y — W: 0.7071
Quaternion.fromRotation(orig, dest)
Erzeugt das kürzeste Bogen‑Quaternion, das den Richtungsvektor rotiert orig zu dest.
static fromRotation(orig: Vector3, dest: Vector3): QuaternionQuaternion.slerp(t, v1, v2)
Führt sphärische lineare Interpolation zwischen v1 und v2 bei Parameter t (0.0 = v1, 1.0 = v2).
static slerp(t: number, v1: Quaternion, v2: Quaternion): QuaternionEnumerations
import { Quaternion } from '@aspose/3d/utilities';
const start = Quaternion.fromEulerAngle(0, 0, 0);
const end = Quaternion.fromEulerAngle(0, Math.PI, 0);
const mid = Quaternion.slerp(0.5, start, end);
console.log(`Mid W: ${mid.w.toFixed(4)}`); // Mid W: 0.7071
Quaternion.interpolate(t, fromQ, toQ)
Alias für slerp. Führt sphärische lineare Interpolation durch.
static interpolate(t: number, fromQ: Quaternion, toQ: Quaternion): QuaternionInstanzmethoden
normalize()
Gibt ein neues Quaternion zurück, das auf Einheitslänge skaliert ist.
normalize(): Quaternionconjugate()
Gibt das Konjugierte zurück (w, -x, -y, -z).
conjugate(): Quaternioninverse()
Gibt das inverse Quaternion zurück. Wirft eine Ausnahme, wenn das Quaternion die Länge Null hat.
inverse(): Quaterniondot(q)
Gibt das skalare Skalarprodukt mit dem Quaternion zurück q.
dot(q: Quaternion): numberconcat(rhs)
Gibt das Quaternion-Produkt zurück this * rhs, die die kombinierte Rotation darstellt, indem zuerst angewendet wird this und dann rhs.
concat(rhs: Quaternion): QuaternioneulerAngles()
Gibt die Rotation, ausgedrückt als Euler‑Winkel in Radianten, als Vector3(pitch, yaw, roll).
eulerAngles(): Vector3Enumerations
import { Quaternion } from '@aspose/3d/utilities';
const q = Quaternion.fromEulerAngle(0, Math.PI / 3, 0);
const euler = q.eulerAngles();
console.log(`Yaw: ${euler.y.toFixed(4)}`);
// Yaw: 1.0472 (= π/3)
toMatrix()
Wandelt dieses Quaternion in ein äquivalentes Matrix4 Rotationsmatrix.
toMatrix(): Matrix4equals(other)
Enumerations true wenn alle vier Komponenten streng gleich sind.
equals(other: Quaternion): booleantoString()
Gibt einen String in der Form zurück Quaternion(w, x, y, z).
toString(): string