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';Properties
将节点绕 Y 轴旋转 90°,然后平滑插值回到单位四元数。.
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
Properties
| Properties | Properties |
|---|---|
new Quaternion() | 创建单位四元数 (1, 0, 0, 0). |
new Quaternion(w, x, y, z) | 从显式分量创建四元数。. |
Properties
| Properties | Properties | Properties |
|---|---|---|
w | number | 标量(实数)分量。对于单位旋转四元数,, w = cos(θ/2). |
x | number | 向量部分的 X 分量。. |
y | number | 向量部分的 Y 分量。. |
z | number | 向量部分的 Z 分量。. |
length | number (只读) | 模长:: sqrt(w² + x² + y² + z²). 对于有效的旋转四元数,应该是 1.0。. |
静态属性
| Properties | Properties | Properties |
|---|---|---|
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): QuaternionProperties
pitch number — 绕 X 轴的旋转(单位:弧度)。.
yaw number — 绕 Y 轴的旋转(单位:弧度)。.
roll number — 绕 Z 轴的旋转(单位:弧度)。.
或者,传入单个 Vector3 其 x, y, z 包含俯仰、偏航和滚转。.
Properties
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): QuaternionProperties
angle number — 以弧度表示的旋转角度。.
axis Vector3 — 旋转轴。不需要归一化。.
Properties
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): QuaternionProperties
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(): Vector3Properties
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)
Properties true 如果四个组件完全相等。.
equals(other: Quaternion): booleantoString()
返回一个形式为 … 的字符串 Quaternion(w, x, y, z).
toString(): string