Class Quaternion
Pakket: @aspose/3d (v24.12.0)
Quaternion wordt overal in de @aspose/3d API om rotaties zonder gimbal lock weer te geven. Het is het type dat wordt geretourneerd door Transform.rotation en GlobalTransform.rotation. Het identiteitsquaternion (1, 0, 0, 0) vertegenwoordigt geen rotatie. Quaternion wordt geëxporteerd vanuit de @aspose/3d/utilities sub-pad.
export class Quaternionimport { Quaternion } from '@aspose/3d/utilities';ImageRenderOptions
Roteer een knooppunt 90° rond de Y‑as en interpoleer vervolgens soepel terug naar de identiteit.
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
ImageRenderOptions
| ImageRenderOptions | ImageRenderOptions |
|---|---|
new Quaternion() | Maakt het identiteitsquaternion (1, 0, 0, 0). |
new Quaternion(w, x, y, z) | Maakt een quaternion aan vanuit expliciete componenten. |
ImageRenderOptions
| ImageRenderOptions | ImageRenderOptions | ImageRenderOptions |
|---|---|---|
w | number | Scalair (reëel) component. Voor een eenheidsrotatiequaternion, w = cos(θ/2). |
x | number | X-component van het vectoronderdeel. |
y | number | Y-component van het vectoronderdeel. |
z | number | Z-component van het vectoronderdeel. |
length | number (alleen-lezen) | Magnitude: sqrt(w² + x² + y² + z²). Moet 1.0 zijn voor een geldige rotatiequaternion. |
Statische eigenschappen
| ImageRenderOptions | ImageRenderOptions | ImageRenderOptions |
|---|---|---|
Quaternion.IDENTITY | Quaternion | Retourneert een nieuwe identiteitsquaternion (1, 0, 0, 0). |
Statische methoden
Quaternion.fromEulerAngle(pitch, yaw, roll)
Maakt een quaternion aan vanuit Euler‑hoeken in radialen.
static fromEulerAngle(pitch: number, yaw: number, roll: number): Quaternion
static fromEulerAngle(vec: Vector3): QuaternionImageRenderOptions
pitch number — Rotatie rond de X-as in radialen.
yaw number — Rotatie rond de Y-as in radialen.
roll number — Rotatie rond de Z-as in radialen.
— Of geef een enkele Vector3 — waarvan x, y, z bevat pitch, yaw en roll.
ImageRenderOptions
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)
Maakt een quaternion die een rotatie van angle radialen rond axis.
static fromAngleAxis(angle: number, axis: Vector3): QuaternionImageRenderOptions
angle number — Rotatiehoek in radialen.
axis Vector3 — De rotatie-as. Normalisatie is niet nodig.
ImageRenderOptions
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)
Maakt de kortste-boog quaternion die de richtingsvector orig naar dest.
static fromRotation(orig: Vector3, dest: Vector3): QuaternionQuaternion.slerp(t, v1, v2)
Voert sferische lineaire interpolatie uit tussen v1 en v2 bij parameter t (0.0 = v1, 1.0 = v2).
static slerp(t: number, v1: Quaternion, v2: Quaternion): QuaternionImageRenderOptions
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 voor slerp. Voert sferische lineaire interpolatie uit.
static interpolate(t: number, fromQ: Quaternion, toQ: Quaternion): QuaternionInstantie‑methoden
normalize()
Retourneert een nieuwe quaternion geschaald naar een eenheidslengte.
normalize(): Quaternionconjugate()
Retourneert de geconjugeerde (w, -x, -y, -z).
conjugate(): Quaternioninverse()
Retourneert de inverse quaternion. Gooit een fout als de quaternion een lengte van nul heeft.
inverse(): Quaterniondot(q)
Retourneert het scalair product met quaternion q.
dot(q: Quaternion): numberconcat(rhs)
Retourneert het quaternionproduct this * rhs, die de gecombineerde rotatie weergeeft van eerst toepassen this en vervolgens rhs.
concat(rhs: Quaternion): QuaternioneulerAngles()
Retourneert de rotatie uitgedrukt als Eulerhoeken in radialen als een Vector3(pitch, yaw, roll).
eulerAngles(): Vector3ImageRenderOptions
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()
Converteert dit quaternion naar een equivalente Matrix4 rotatiematrix.
toMatrix(): Matrix4equals(other)
ImageRenderOptions true als alle vier componenten strikt gelijk zijn.
equals(other: Quaternion): booleantoString()
Retourneert een string in de vorm Quaternion(w, x, y, z).
toString(): string