Quaternion

Csomag: @aspose/3d (v24.12.0)

Quaternion az egész @aspose/3d API a gimbal lock nélküli forgatások ábrázolására. Ez a típus, amelyet visszaad Transform.rotation és GlobalTransform.rotation. Az identitás kvaternió (1, 0, 0, 0) nem jelöl forgást. Quaternion exportálva van a @aspose/3d/utilities alkönyvtárból.

export class Quaternion
import { Quaternion } from '@aspose/3d/utilities';

ColladaSaveOptions

Forgass egy csomópontot 90°-kal az Y tengely körül, majd simán interpolálj vissza az egységhez.

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

NameTypeAccessDescription
wnumberRead/WriteGets the w.
xnumberRead/WriteGets the x.
ynumberRead/WriteGets the y.
znumberRead/WriteGets the z.
lengthnumberReadGets the length.

ColladaSaveOptions

SignatureDescription
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()QuaternionReturns the identity quaternion representing no rotation
normalize()QuaternionReturns a unit‑length version of this quaternion
conjugate()QuaternionReturns the conjugate of the quaternion
inverse()QuaternionReturns the multiplicative inverse of the quaternion
dot(q: Quaternion)numberComputes the dot product with another quaternion
concat(rhs: Quaternion)QuaternionReturns the concatenation (multiplication) of this quaternion with another
eulerAngles()Vector3Returns a Vector3 of Euler angles representing the rotation
fromEulerAngle(pitch: number, yaw: number, roll: number)QuaternionOverload accepts a Vector3 or numeric pitch with yaw and roll
fromEulerAngle(vec: Vector3)Quaternion
`fromEulerAngle(pitch: Vector3number, yaw: number, roll: number)Quaternion`
fromAngleAxis(a: number, axis: Vector3)QuaternionCreates a quaternion from a rotation angle and axis vector
fromRotation(orig: Vector3, dest: Vector3)QuaternionBuilds a quaternion that rotates from one direction vector to another
interpolate(t: number, fromQ: Quaternion, toQ: Quaternion)QuaternionLinearly interpolates between two quaternions using parameter t
slerp(t: number, v1: Quaternion, v2: Quaternion)QuaternionPerforms spherical linear interpolation between two quaternions at t
toString()stringReturns a string representation of the quaternion components
equals(other: Quaternion)booleanChecks whether another quaternion has identical component values
toMatrix()Matrix4Converts the quaternion into a 4×4 rotation matrix

Statikus tulajdonságok

ColladaSaveOptionsColladaSaveOptionsColladaSaveOptions
Quaternion.IDENTITYQuaternionVisszaad egy új egységkvaterniont (1, 0, 0, 0).

Statikus metódusok

Quaternion.fromEulerAngle(pitch, yaw, roll)

Kvaterniót hoz létre Euler-szögekből radiánban.

static fromEulerAngle(pitch: number, yaw: number, roll: number): Quaternion
static fromEulerAngle(vec: Vector3): Quaternion

ColladaSaveOptions

pitch number — Forgatás az X tengely körül radiánban.

yaw number — Forgatás az Y tengely körül radiánban.

roll number — Forgatás a Z tengely körül radiánban.

Alternatívaként adjon át egyetlen Vector3 amelynek x, y, z tartalmazza a pitch, yaw és roll értékeket.

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)

Létrehoz egy kvaterniót, amely egy forgatást ábrázol `angle` radiánban a `axis`.

```typescript
static fromAngleAxis(angle: number, axis: Vector3): Quaternion

ColladaSaveOptions

angle number — Forgatási szög radiánban.

axis Vector3 — A forgatás tengelye. Nem szükséges normalizálni.

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)

Létrehoz egy legkisebb ívű kvaterniót, amely elforgatja az irányvektort orig az dest.

static fromRotation(orig: Vector3, dest: Vector3): Quaternion

Quaternion.slerp(t, v1, v2)

Végrehajt gömbi lineáris interpolációt a v1 és v2 a paraméternél t (0.0 = v1, 1.0 = v2).

static slerp(t: number, v1: Quaternion, v2: Quaternion): Quaternion

ColladaSaveOptions

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)

Álnév a `slerp`. Sphérikus lineáris interpolációt hajt végre.

```typescript
static interpolate(t: number, fromQ: Quaternion, toQ: Quaternion): Quaternion

LoadOptions

normalize()

Visszaad egy új kvaterniót, amely egység hosszra van skálázva.

normalize(): Quaternion

conjugate()

Visszaadja a konjugáltat (w, -x, -y, -z).

conjugate(): Quaternion

inverse()

Visszaadja a kvaternió inverzét. Kivételt dob, ha a kvaternió hossza nulla.

inverse(): Quaternion

dot(q)

Visszaadja a skaláris szorzatot a kvaternióval q.

dot(q: Quaternion): number

concat(rhs)

Visszaadja a kvaternió szorzatát this * rhs, amely először alkalmazva a kombinált forgatást jelenti this majd rhs.

concat(rhs: Quaternion): Quaternion

eulerAngles()

Visszaadja a forgatást, amely radiánban kifejezett Euler-szögekként van megadva, mint egy Vector3(pitch, yaw, roll).

eulerAngles(): Vector3

ColladaSaveOptions

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()

Átalakítja ezt a kvaterniót egy ekvivalens `Matrix4` forgatási mátrixot.

```typescript
toMatrix(): Matrix4

equals(other)

ColladaSaveOptions true ha mind a négy komponens szigorúan egyenlő.

equals(other: Quaternion): boolean

toString()

Visszaad egy karakterláncot a következő formában Quaternion(w, x, y, z).

toString(): string
 Magyar