Quaternion
Paquete: @aspose/3d (v24.12.0)
Quaternion se utiliza a lo largo del @aspose/3d API para representar rotaciones sin bloqueo de cardán. Es el tipo devuelto por Transform.rotation y GlobalTransform.rotation. El cuaternión de identidad (1, 0, 0, 0) representa ninguna rotación. Quaternion se exporta desde el @aspose/3d/utilities sub‑ruta.
export class Quaternionimport { Quaternion } from '@aspose/3d/utilities';ColladaSaveOptions
Gira un nodo 90° alrededor del eje Y y luego interpola suavemente de regreso a la identidad.
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
| 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. |
ColladaSaveOptions
| 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 |
Propiedades estáticas
| ColladaSaveOptions | ColladaSaveOptions | ColladaSaveOptions |
|---|---|---|
Quaternion.IDENTITY | Quaternion | Devuelve un nuevo cuaternión identidad (1, 0, 0, 0). |
Métodos estáticos
Quaternion.fromEulerAngle(pitch, yaw, roll)
Crea un cuaternión a partir de ángulos de Euler en radianes.
static fromEulerAngle(pitch: number, yaw: number, roll: number): Quaternion
static fromEulerAngle(vec: Vector3): QuaternionColladaSaveOptions
pitch number — Rotación alrededor del eje X en radianes.
yaw number — Rotación alrededor del eje Y en radianes.
roll number — Rotación alrededor del eje Z en radianes.
Alternativamente, pase un único Vector3 cuyo x, y, z contienen pitch, yaw y roll.
ColladaSaveOptions
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)
Crea un quaternion que representa una rotación de `angle` radianes alrededor de `axis`.
```typescript
static fromAngleAxis(angle: number, axis: Vector3): QuaternionColladaSaveOptions
angle number — Ángulo de rotación en radianes.
axis Vector3 — El eje de rotación. No necesita ser normalizado.
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)
Crea el cuaternión de arco más corto que rota el vector de dirección orig a dest.
static fromRotation(orig: Vector3, dest: Vector3): QuaternionQuaternion.slerp(t, v1, v2)
Realiza una interpolación lineal esférica entre v1 y v2 en el parámetro t (0.0 = v1, 1.0 = v2).
static slerp(t: number, v1: Quaternion, v2: Quaternion): QuaternionColladaSaveOptions
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`. Realiza una interpolación lineal esférica.
```typescript
static interpolate(t: number, fromQ: Quaternion, toQ: Quaternion): QuaternionReferencia de LoadOptions, SaveOptions y todas las clases de opciones específicas de formato (OBJ, glTF, STL, FBX, COLLADA) utilizadas para controlar el comportamiento de importación y exportación.
normalize()
Devuelve un nuevo cuaternión escalado a longitud unitaria.
normalize(): Quaternionconjugate()
Devuelve el conjugado (w, -x, -y, -z).
conjugate(): Quaternioninverse()
Devuelve el cuaternión inverso. Lanza una excepción si el cuaternión tiene longitud cero.
inverse(): Quaterniondot(q)
Devuelve el producto escalar con cuaternión q.
dot(q: Quaternion): numberconcat(rhs)
Devuelve el producto de cuaterniones this * rhs, que representa la rotación combinada de aplicar primero this y luego rhs.
concat(rhs: Quaternion): QuaternioneulerAngles()
Devuelve la rotación expresada como ángulos de Euler en radianes como un Vector3(pitch, yaw, roll).
eulerAngles(): Vector3ColladaSaveOptions
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()
Convierte este cuaternión a un equivalente `Matrix4` matriz de rotación.
```typescript
toMatrix(): Matrix4equals(other)
ColladaSaveOptions true si los cuatro componentes son estrictamente iguales.
equals(other: Quaternion): booleantoString()
Devuelve una cadena con el formato Quaternion(w, x, y, z).
toString(): string