From 9c117b8832b5456cecab9bedd4b7f15ab2b98b62 Mon Sep 17 00:00:00 2001 From: yzrmn Date: Thu, 14 Nov 2024 12:28:58 +0100 Subject: [PATCH] Add quaternion method to extract rotation axis and angle --- packages/redgeometry/src/primitives/quaternion.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/redgeometry/src/primitives/quaternion.ts b/packages/redgeometry/src/primitives/quaternion.ts index 007d333..a7814e5 100644 --- a/packages/redgeometry/src/primitives/quaternion.ts +++ b/packages/redgeometry/src/primitives/quaternion.ts @@ -562,6 +562,14 @@ export class Quaternion implements QuaternionLike { this.d = qd * cos + qa * sin; } + public rotationAngle(): number { + return 2 * Math.acos(this.a); + } + + public rotationAxis(): Vector3 { + return new Vector3(this.b, this.c, this.d); + } + /** * Returns the spherical linear interpolation of the current quaternion and `q`. */