diff --git a/packages/redgeometry/src/core/path.ts b/packages/redgeometry/src/core/path.ts index e872c8e..5787087 100644 --- a/packages/redgeometry/src/core/path.ts +++ b/packages/redgeometry/src/core/path.ts @@ -189,7 +189,7 @@ export class Path2 implements PathSink2 { let sin = Math.sin(startAngle); let cos = Math.cos(startAngle); - const mat = Matrix3x2.fromRotation(sin, cos); + const mat = Matrix3x2.fromRotation(cos, sin); mat.scalePre(rx, ry); mat.translatePre(pc.x, pc.y); @@ -572,7 +572,7 @@ export class Path2 implements PathSink2 { let cos = Math.cos(xAxisRotation); // Inverse rotation to align the ellipse - const mat = Matrix3x2.fromRotation(-sin, cos); + const mat = Matrix3x2.fromRotation(cos, -sin); // Vector from center (transformed midpoint) let v = p0.sub(p1).mul(0.5); @@ -626,10 +626,10 @@ export class Path2 implements PathSink2 { let v2 = pp1.sub(pc); // Set up the final transformation matrix - mat.rotateSet(v1.y, v1.x); + mat.rotateSet(v1.x, v1.y); mat.translatePre(pc.x, pc.y); mat.scalePre(sx, sy); - mat.rotatePre(sin, cos); + mat.rotatePre(cos, sin); // We have `sin = v1.cross(v2) / (v1.length * v2.length)` // with the length of `v1` and `v2` both 1 (unit vectors) diff --git a/packages/redgeometry/src/primitives/quaternion.ts b/packages/redgeometry/src/primitives/quaternion.ts index b7b86ab..4aab550 100644 --- a/packages/redgeometry/src/primitives/quaternion.ts +++ b/packages/redgeometry/src/primitives/quaternion.ts @@ -87,19 +87,19 @@ export class Quaternion { } } - public static fromRotationXAngle(angle: number): Quaternion { + public static fromRotationAngleX(angle: number): Quaternion { const sin = Math.sin(0.5 * angle); const cos = Math.cos(0.5 * angle); return new Quaternion(cos, sin, 0, 0); } - public static fromRotationYAngle(angle: number): Quaternion { + public static fromRotationAngleY(angle: number): Quaternion { const sin = Math.sin(0.5 * angle); const cos = Math.cos(0.5 * angle); return new Quaternion(cos, 0, sin, 0); } - public static fromRotationZAngle(angle: number): Quaternion { + public static fromRotationAngleZ(angle: number): Quaternion { const sin = Math.sin(0.5 * angle); const cos = Math.cos(0.5 * angle); return new Quaternion(cos, 0, 0, sin); diff --git a/packages/redgeometry/tests/primitives/matrix.spec.ts b/packages/redgeometry/tests/primitives/matrix.spec.ts index 569cf48..3be4f5b 100644 --- a/packages/redgeometry/tests/primitives/matrix.spec.ts +++ b/packages/redgeometry/tests/primitives/matrix.spec.ts @@ -166,7 +166,7 @@ test("Matrix4x3 - mapVector", () => { }); test("Matrix4x3 - rotate (x)", () => { - const q = Quaternion.fromRotationXAngle(1); + const q = Quaternion.fromRotationAngleX(1); const mat1 = Matrix4x3.fromRotation(q.a, q.b, q.c, q.d); const mat2 = Matrix4x3.createIdentity(); const mat3 = Matrix4x3.createIdentity(); @@ -182,7 +182,7 @@ test("Matrix4x3 - rotate (x)", () => { }); test("Matrix4x3 - rotate (y)", () => { - const q = Quaternion.fromRotationYAngle(1); + const q = Quaternion.fromRotationAngleY(1); const mat1 = Matrix4x3.fromRotation(q.a, q.b, q.c, q.d); const mat2 = Matrix4x3.createIdentity(); const mat3 = Matrix4x3.createIdentity(); @@ -198,7 +198,7 @@ test("Matrix4x3 - rotate (y)", () => { }); test("Matrix4x3 - rotate (z)", () => { - const q = Quaternion.fromRotationZAngle(1); + const q = Quaternion.fromRotationAngleZ(1); const mat1 = Matrix4x3.fromRotation(q.a, q.b, q.c, q.d); const mat2 = Matrix4x3.createIdentity(); const mat3 = Matrix4x3.createIdentity(); @@ -262,7 +262,7 @@ test("Matrix4x4 - mapVector", () => { }); test("Matrix4x4 - rotate (x)", () => { - const q = Quaternion.fromRotationXAngle(1); + const q = Quaternion.fromRotationAngleX(1); const mat1 = Matrix4x4.fromRotation(q.a, q.b, q.c, q.d); const mat2 = Matrix4x4.createIdentity(); const mat3 = Matrix4x4.createIdentity(); @@ -278,7 +278,7 @@ test("Matrix4x4 - rotate (x)", () => { }); test("Matrix4x4 - rotate (y)", () => { - const q = Quaternion.fromRotationYAngle(1); + const q = Quaternion.fromRotationAngleY(1); const mat1 = Matrix4x4.fromRotation(q.a, q.b, q.c, q.d); const mat2 = Matrix4x4.createIdentity(); const mat3 = Matrix4x4.createIdentity(); @@ -294,7 +294,7 @@ test("Matrix4x4 - rotate (y)", () => { }); test("Matrix4x4 - rotate (z)", () => { - const q = Quaternion.fromRotationZAngle(1); + const q = Quaternion.fromRotationAngleZ(1); const mat1 = Matrix4x4.fromRotation(q.a, q.b, q.c, q.d); const mat2 = Matrix4x4.createIdentity(); const mat3 = Matrix4x4.createIdentity(); diff --git a/packages/redgeometry/tests/primitives/quaternion.spec.ts b/packages/redgeometry/tests/primitives/quaternion.spec.ts index eb5697e..d5e6093 100644 --- a/packages/redgeometry/tests/primitives/quaternion.spec.ts +++ b/packages/redgeometry/tests/primitives/quaternion.spec.ts @@ -2,7 +2,7 @@ import { expect, test } from "vitest"; import { Quaternion, RotationOrder } from "../../src/primitives/quaternion.js"; test("Quaternion - fromXAngle", () => { - const q = Quaternion.fromRotationXAngle(1); + const q = Quaternion.fromRotationAngleX(1); const q1 = Quaternion.fromRotationEuler(1, 0, 0, RotationOrder.XYZ); const q2 = Quaternion.fromRotationEuler(1, 0, 0, RotationOrder.XZY); @@ -20,7 +20,7 @@ test("Quaternion - fromXAngle", () => { }); test("Quaternion - fromYAngle", () => { - const q = Quaternion.fromRotationYAngle(1); + const q = Quaternion.fromRotationAngleY(1); const q1 = Quaternion.fromRotationEuler(0, 1, 0, RotationOrder.XYZ); const q2 = Quaternion.fromRotationEuler(0, 1, 0, RotationOrder.XZY); @@ -39,7 +39,7 @@ test("Quaternion - fromYAngle", () => { }); test("Quaternion - fromZAngle", () => { - const q = Quaternion.fromRotationZAngle(1); + const q = Quaternion.fromRotationAngleZ(1); const q1 = Quaternion.fromRotationEuler(0, 0, 1, RotationOrder.XYZ); const q2 = Quaternion.fromRotationEuler(0, 0, 1, RotationOrder.XZY); @@ -68,12 +68,12 @@ test("Quaternion - fromEulerAngles", () => { const qe1 = Quaternion.fromRotationEuler(ax, ay, az, RotationOrder.ZXY); const qf1 = Quaternion.fromRotationEuler(ax, ay, az, RotationOrder.ZYX); - const qa2 = Quaternion.fromRotationXAngle(ax).rotateY(ay).rotateZ(az); - const qb2 = Quaternion.fromRotationXAngle(ax).rotateZ(az).rotateY(ay); - const qc2 = Quaternion.fromRotationYAngle(ay).rotateX(ax).rotateZ(az); - const qd2 = Quaternion.fromRotationYAngle(ay).rotateZ(az).rotateX(ax); - const qe2 = Quaternion.fromRotationZAngle(az).rotateX(ax).rotateY(ay); - const qf2 = Quaternion.fromRotationZAngle(az).rotateY(ay).rotateX(ax); + const qa2 = Quaternion.fromRotationAngleX(ax).rotateY(ay).rotateZ(az); + const qb2 = Quaternion.fromRotationAngleX(ax).rotateZ(az).rotateY(ay); + const qc2 = Quaternion.fromRotationAngleY(ay).rotateX(ax).rotateZ(az); + const qd2 = Quaternion.fromRotationAngleY(ay).rotateZ(az).rotateX(ax); + const qe2 = Quaternion.fromRotationAngleZ(az).rotateX(ax).rotateY(ay); + const qf2 = Quaternion.fromRotationAngleZ(az).rotateY(ay).rotateX(ax); expectToBeCloseToQuaternion(qa1, qa2); expectToBeCloseToQuaternion(qb1, qb2);