Quaternion
Pacote: @aspose/3d (v24.12.0)
Quaternion é usado ao longo de todo o @aspose/3d API para representar rotações sem bloqueio de cardan. É o tipo retornado por Transform.rotation e GlobalTransform.rotation. O quaternion de identidade (1, 0, 0, 0) representa nenhuma rotação. Quaternion é exportado do @aspose/3d/utilities subcaminho.
export class Quaternionimport { Quaternion } from '@aspose/3d/utilities';Example
Gire um nó 90° ao redor do eixo Y e então interpole suavemente de volta à identidade.
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
| 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. |
Example
| 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 |
Referência da classe Light
| Example | Example | Example |
|---|---|---|
Quaternion.IDENTITY | Quaternion | Retorna um novo quaternion identidade (1, 0, 0, 0). |
Métodos estáticos
Quaternion.fromEulerAngle(pitch, yaw, roll)
Cria um quaternion a partir de ângulos de Euler em radianos.
static fromEulerAngle(pitch: number, yaw: number, roll: number): Quaternion
static fromEulerAngle(vec: Vector3): QuaternionExample
pitch number — Rotação ao redor do eixo X em radianos.
yaw number — Rotação ao redor do eixo Y em radianos.
roll number — Rotação ao redor do eixo Z em radianos.
Alternativamente, passe um único Vector3 cujo x, y, z contém pitch, yaw e roll.
Example
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)
Cria um quaternion que representa uma rotação de `angle` radianos ao redor de `axis`.
```typescript
static fromAngleAxis(angle: number, axis: Vector3): QuaternionExample
angle number — Ângulo de rotação em radianos.
axis Vector3 — O eixo de rotação. Não precisa ser normalizado.
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)
Cria o quaternion de arco mais curto que rotaciona o vetor de direção orig para dest.
static fromRotation(orig: Vector3, dest: Vector3): QuaternionQuaternion.slerp(t, v1, v2)
Executa interpolação linear esférica entre v1 e v2 no parâmetro t (0.0 = v1, 1.0 = v2).
static slerp(t: number, v1: Quaternion, v2: Quaternion): QuaternionExample
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 de `slerp`. Executa interpolação linear esférica.
```typescript
static interpolate(t: number, fromQ: Quaternion, toQ: Quaternion): QuaternionMétodos de Instância
normalize()
Retorna um novo quaternion escalado para comprimento unitário.
normalize(): Quaternionconjugate()
Retorna o conjugado (w, -x, -y, -z).
conjugate(): Quaternioninverse()
Retorna o quaternion inverso. Lança exceção se o quaternion tem comprimento zero.
inverse(): Quaterniondot(q)
Retorna o produto escalar com quaternion q.
dot(q: Quaternion): numberconcat(rhs)
Retorna o produto quaternion this * rhs, representando a rotação combinada de primeiro aplicar this e então rhs.
concat(rhs: Quaternion): QuaternioneulerAngles()
Retorna a rotação expressa como ângulos de Euler em radianos como um Vector3(pitch, yaw, roll).
eulerAngles(): Vector3Example
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()
Converte este quaternion para um equivalente `Matrix4` matriz de rotação.
```typescript
toMatrix(): Matrix4equals(other)
Example true se todos os quatro componentes forem estritamente iguais.
equals(other: Quaternion): booleantoString()
Retorna uma string no formato Quaternion(w, x, y, z).
toString(): string