Class Quaternion
Pakiet: @aspose/3d (v24.12.0)
Quaternion jest używany w całym @aspose/3d API do reprezentowania obrotów bez blokady gimbal. Jest to typ zwracany przez Transform.rotation oraz GlobalTransform.rotation. Tożsamość kwaternionu (1, 0, 0, 0) reprezentuje brak obrotu. Quaternion jest eksportowany z @aspose/3d/utilities podścieżki.
export class Quaternionimport { Quaternion } from '@aspose/3d/utilities';Example
Obróć węzeł o 90° wokół osi Y, a następnie płynnie interpoluj z powrotem do jednostki.
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
Example
| Example | Example |
|---|---|
new Quaternion() | Tworzy tożsamość kwaternionu (1, 0, 0, 0). |
new Quaternion(w, x, y, z) | Tworzy kwaternion z jawnych składników. |
Example
| Example | Example | Example |
|---|---|---|
w | number | Skalar (rzeczywisty) składnik. Dla jednostkowego kwaternionu obrotu, w = cos(θ/2). |
x | number | Składnik X części wektorowej. |
y | number | Składnik Y części wektorowej. |
z | number | Składnik Z części wektorowej. |
length | number (tylko do odczytu) | Moduł: sqrt(w² + x² + y² + z²). Powinien wynosić 1,0 dla prawidłowego kwaternionu obrotu. |
Wszystkie wyliczenia w @aspose/3d: ProjectionType, LightType, TextureMapping, BooleanOperation, VertexElementType, MappingMode, ReferenceMode
| Example | Example | Example |
|---|---|---|
Quaternion.IDENTITY | Quaternion | Zwraca nowy kwaternion jednostkowy (1, 0, 0, 0). |
Metody statyczne
Quaternion.fromEulerAngle(pitch, yaw, roll)
Tworzy quaternion z kątów Eulera podanych w radianach.
static fromEulerAngle(pitch: number, yaw: number, roll: number): Quaternion
static fromEulerAngle(vec: Vector3): QuaternionExample
pitch number — Obrót wokół osi X w radianach.
yaw number — Rotacja wokół osi Y w radianach.
roll number — Rotacja wokół osi Z w radianach.
Alternatywnie, przekaż pojedynczy Vector3 którego x, y, z przechowują pitch, yaw i roll.
Example
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)
Tworzy kwaternion reprezentujący obrót o angle radiany wokół axis.
static fromAngleAxis(angle: number, axis: Vector3): QuaternionExample
angle number — Kąt obrotu w radianach.
axis Vector3 — Oś obrotu. Nie wymaga normalizacji.
Example
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)
Tworzy kwaternion najkrótszego łuku, który obraca wektor kierunku orig do dest.
static fromRotation(orig: Vector3, dest: Vector3): QuaternionQuaternion.slerp(t, v1, v2)
Wykonuje sferyczną interpolację liniową pomiędzy v1 i v2 przy parametrze t (0.0 = v1, 1.0 = v2).
static slerp(t: number, v1: Quaternion, v2: Quaternion): QuaternionExample
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 dla slerp. Wykonuje sferyczną interpolację liniową.
static interpolate(t: number, fromQ: Quaternion, toQ: Quaternion): QuaternionMetody instancji
normalize()
Zwraca nowy kwaternion skalowany do jednostkowej długości.
normalize(): Quaternionconjugate()
Zwraca sprzężenie (w, -x, -y, -z).
conjugate(): Quaternioninverse()
Zwraca odwrotny kwaternion. Rzuca wyjątek, jeśli kwaternion ma zerową długość.
inverse(): Quaterniondot(q)
Zwraca skalarny iloczyn ze kwaternionem q.
dot(q: Quaternion): numberconcat(rhs)
Zwraca iloczyn kwaternionowy this * rhs, reprezentujący połączony obrót, najpierw stosując this a następnie rhs.
concat(rhs: Quaternion): QuaternioneulerAngles()
Zwraca obrót wyrażony jako kąty Eulera w radianach jako Vector3(pitch, yaw, roll).
eulerAngles(): Vector3Example
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()
Konwertuje ten kwaternion na równoważny Matrix4 macierz obrotu.
toMatrix(): Matrix4equals(other)
Example true jeśli wszystkie cztery składowe są ściśle równe.
equals(other: Quaternion): booleantoString()
Zwraca ciąg znaków w formie Quaternion(w, x, y, z).
toString(): string