Quaternion
Paket: @aspose/3d (v24.12.0)
Quaternion digunakan di seluruh @aspose/3d API untuk merepresentasikan rotasi tanpa gimbal lock. Ini adalah tipe yang dikembalikan oleh Transform.rotation dan GlobalTransform.rotation. Quaternion identitas (1, 0, 0, 0) mewakili tidak ada rotasi. Quaternion dieksport dari @aspose/3d/utilities sub-path.
export class Quaternionimport { Quaternion } from '@aspose/3d/utilities';BoundingBoxExtent
Putar sebuah node 90° di sekitar sumbu Y dan kemudian interpolasi secara halus kembali ke identitas.
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
BoundingBoxExtent
| Name | Type | Access | Description |
|---|---|---|---|
w | number | Read/Write | Gets the w. |
x | number | Read/Write | Gets the x. |
y | number | Read/Write | Gets the y. |
z | number | Read/Write | Gets the z. |
length | number | Read | Gets the length. |
BoundingBoxExtent
| Signature | Description |
|---|---|
constructor() | Initializes a quaternion with the given w, x, y, and z components |
constructor(w: number, x: number, y: number, z: number) | |
constructor(w: number, x: number, y: number, z: number) | |
IDENTITY() → Quaternion | Returns the identity quaternion representing no rotation |
normalize() → Quaternion | Returns a unit‑length version of this quaternion |
conjugate() → Quaternion | Returns the conjugate of the quaternion |
inverse() → Quaternion | Returns the multiplicative inverse of the quaternion |
dot(q: Quaternion) → number | Computes the dot product with another quaternion |
concat(rhs: Quaternion) → Quaternion | Returns the concatenation (multiplication) of this quaternion with another |
eulerAngles() → Vector3 | Returns a Vector3 of Euler angles representing the rotation |
fromEulerAngle(pitch: number, yaw: number, roll: number) → Quaternion | Overload accepts a Vector3 or numeric pitch with yaw and roll |
fromEulerAngle(vec: Vector3) → Quaternion | |
| `fromEulerAngle(pitch: Vector3 | number, yaw: number, roll: number) → Quaternion` |
fromAngleAxis(a: number, axis: Vector3) → Quaternion | Creates a quaternion from a rotation angle and axis vector |
fromRotation(orig: Vector3, dest: Vector3) → Quaternion | Builds a quaternion that rotates from one direction vector to another |
interpolate(t: number, fromQ: Quaternion, toQ: Quaternion) → Quaternion | Linearly interpolates between two quaternions using parameter t |
slerp(t: number, v1: Quaternion, v2: Quaternion) → Quaternion | Performs spherical linear interpolation between two quaternions at t |
toString() → string | Returns a string representation of the quaternion components |
equals(other: Quaternion) → boolean | Checks whether another quaternion has identical component values |
toMatrix() → Matrix4 | Converts the quaternion into a 4×4 rotation matrix |
Properti Statis
| BoundingBoxExtent | BoundingBoxExtent | BoundingBoxExtent |
|---|---|---|
Quaternion.IDENTITY | Quaternion | Mengembalikan quaternion identitas baru (1, 0, 0, 0). |
Metode Statis
Quaternion.fromEulerAngle(pitch, yaw, roll)
Membuat quaternion dari sudut Euler dalam radian.
static fromEulerAngle(pitch: number, yaw: number, roll: number): Quaternion
static fromEulerAngle(vec: Vector3): QuaternionBoundingBoxExtent
pitch number — Rotasi sekitar sumbu X dalam radian.
yaw number — Rotasi sekitar sumbu Y dalam radian.
roll number — Rotasi sekitar sumbu Z dalam radian.
Sebagai alternatif, berikan satu Vector3 yang x, y, z menyimpan pitch, yaw, dan roll.
BoundingBoxExtent
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)
Membuat quaternion yang mewakili rotasi sebesar `angle` radian di sekitar `axis`.
```typescript
static fromAngleAxis(angle: number, axis: Vector3): QuaternionBoundingBoxExtent
angle number — Sudut rotasi dalam radian.
axis Vector3 — Sumbu rotasi. Tidak perlu dinormalisasi.
BoundingBoxExtent
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)
Membuat quaternion busur terpendek yang memutar vektor arah orig menjadi dest.
static fromRotation(orig: Vector3, dest: Vector3): QuaternionQuaternion.slerp(t, v1, v2)
Melakukan interpolasi linier sferis antara v1 dan v2 pada parameter t (0.0 = v1, 1.0 = v2).
static slerp(t: number, v1: Quaternion, v2: Quaternion): QuaternionBoundingBoxExtent
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 untuk `slerp`. Melakukan interpolasi linier sferis.
```typescript
static interpolate(t: number, fromQ: Quaternion, toQ: Quaternion): QuaternionMetode Instansi
normalize()
Mengembalikan quaternion baru yang diskalakan ke panjang satu.
normalize(): Quaternionconjugate()
Mengembalikan konjugat (w, -x, -y, -z).
conjugate(): Quaternioninverse()
Mengembalikan quaternion invers. Melempar pengecualian jika quaternion memiliki panjang nol.
inverse(): Quaterniondot(q)
Mengembalikan hasil perkalian titik skalar dengan quaternion q.
dot(q: Quaternion): numberconcat(rhs)
Mengembalikan hasil perkalian quaternion this * rhs, yang mewakili rotasi gabungan dengan pertama menerapkan this dan kemudian rhs.
concat(rhs: Quaternion): QuaternioneulerAngles()
Mengembalikan rotasi yang diekspresikan sebagai sudut Euler dalam radian sebagai sebuah Vector3(pitch, yaw, roll).
eulerAngles(): Vector3BoundingBoxExtent
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()
Mengonversi quaternion ini menjadi sebuah `Matrix4` matriks rotasi.
```typescript
toMatrix(): Matrix4equals(other)
BoundingBoxExtent true jika keempat komponen secara ketat sama.
equals(other: Quaternion): booleantoString()
Mengembalikan string dalam bentuk Quaternion(w, x, y, z).
toString(): string