Class Quaternion
חבילה: @aspose/3d (v24.12.0)
Quaternion משמשת ברחבי @aspose/3d API לייצוג סיבובים ללא נעילת גימבל. זהו הסוג שמוחזר על‑ידי Transform.rotation ו GlobalTransform.rotation. הקוואטרניון הזהות (1, 0, 0, 0) מייצג חוסר סיבוב. Quaternion מייוצא מה‑ @aspose/3d/utilities תת‑נתיב.
export class Quaternionimport { Quaternion } from '@aspose/3d/utilities';ColladaSaveOptions
סובב צומת ב‑90° סביב ציר ה‑Y ולאחר מכן בצע אינטרפולציה חלקה חזרה לזהות.
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
ColladaSaveOptions
| ColladaSaveOptions | ColladaSaveOptions |
|---|---|
new Quaternion() | יוצר את הקוואטרניון הזהות (1, 0, 0, 0). |
new Quaternion(w, x, y, z) | יוצר קוואטרניון מרכיבים מפורשים. |
ColladaSaveOptions
| ColladaSaveOptions | ColladaSaveOptions | ColladaSaveOptions |
|---|---|---|
w | number | רכיב סקלרי (אמיתי). עבור קוואטרניון סיבוב יחיד, w = cos(θ/2). |
x | number | רכיב X של חלק הווקטור. |
y | number | רכיב Y של חלק הווקטור. |
z | number | רכיב Z של חלק הווקטור. |
length | number (קריאה בלבד) | גודל: sqrt(w² + x² + y² + z²). צריך להיות 1.0 עבור קווטרני סיבוב תקף. |
מאפיינים סטטיים
| ColladaSaveOptions | ColladaSaveOptions | ColladaSaveOptions |
|---|---|---|
Quaternion.IDENTITY | Quaternion | מחזיר קווטרני זהות חדש (1, 0, 0, 0). |
שיטות סטטיות
Quaternion.fromEulerAngle(pitch, yaw, roll)
יוצר קוואטורני מזוויות אוילר ברדיאנים.
static fromEulerAngle(pitch: number, yaw: number, roll: number): Quaternion
static fromEulerAngle(vec: Vector3): QuaternionColladaSaveOptions
pitch number — סיבוב סביב ציר X ברדיאנים.
yaw number — סיבוב סביב ציר Y ברדיאנים.
roll number — סיבוב סביב ציר Z ברדיאנים.
לחלופין, העבר ערך יחיד Vector3 שלו x, y, z מחזיקים ב‑pitch, yaw ו‑roll.
ColladaSaveOptions
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)
יוצר קווטרניון המייצג סיבוב של angle רדיאנים סביב axis.
static fromAngleAxis(angle: number, axis: Vector3): QuaternionColladaSaveOptions
angle number — זווית סיבוב ברדיאנים.
axis Vector3 — ציר הסיבוב. אינו צריך להיות מנורמל.
ColladaSaveOptions
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)
יוצר את קווטרניון הקשת הקצרה ביותר שמסובב את וקטור הכיוון orig ל‑ dest.
static fromRotation(orig: Vector3, dest: Vector3): QuaternionQuaternion.slerp(t, v1, v2)
מבצע אינטרפולציה קוונטית ספירלית ליניארית בין v1 ו‑ v2 בפרמטר t (0.0 = v1, 1.0 = v2).
static slerp(t: number, v1: Quaternion, v2: Quaternion): QuaternionColladaSaveOptions
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)
כינוי ל slerp. מבצע אינטרפולציה קוייתית ספירלית.
static interpolate(t: number, fromQ: Quaternion, toQ: Quaternion): Quaternionמתודות של המופע
normalize()
מחזיר קווטרניון חדש שמקנה אורך יחידה.
normalize(): Quaternionconjugate()
מחזיר את הקונוגט (w, -x, -y, -z).
conjugate(): Quaternioninverse()
מחזיר את הקווטרניון ההפוך. זורק שגיאה אם לקווטרניון יש אורך אפס.
inverse(): Quaterniondot(q)
מחזיר את מכפלת הנקודה הסקלרית עם קווטרניון q.
dot(q: Quaternion): numberconcat(rhs)
מחזיר את מכפלת הקווטרניון this * rhs, המייצג את הסיבוב המשולב של תחילה יישום this ואז rhs.
concat(rhs: Quaternion): QuaternioneulerAngles()
מחזיר את הסיבוב המיוצג בזוויות אוילר ברדיאנים כ Vector3(pitch, yaw, roll).
eulerAngles(): Vector3ColladaSaveOptions
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()
ממיר קווטרניון זה ל Matrix4 מטריצת סיבוב.
toMatrix(): Matrix4equals(other)
ColladaSaveOptions true אם כל ארבעת הרכיבים שווים בדיוק.
equals(other: Quaternion): booleantoString()
מחזיר מחרוזת בצורת Quaternion(w, x, y, z).
toString(): string