[fxtf-drafts] [geometry-1] Assumption of `z=1` for `rotateAxisAngle(0, 0, z, angle)`? (#601)

danburzo has just created a new issue for https://github.com/w3c/fxtf-drafts:

== [geometry-1] Assumption of `z=1` for `rotateAxisAngle(0, 0, z, angle)`? ==
I’m working on a polyfill for the Geometry Interfaces and I might be misinterpreting something in the specs, as I’m getting different results than browsers for `rotateAxisAngle()`. Given [the definition](https://drafts.fxtf.org/geometry/#dom-dommatrix-rotateaxisangleself):

<blockquote>

rotateAxisAngleSelf(x, y, z, angle)

[Post-multiply](https://drafts.fxtf.org/geometry/#post-multiply) a rotation transformation on the current matrix around the specified vector x, y, z by the specified rotation angle in degrees. The 3D rotation matrix is [described](https://drafts.csswg.org/css-transforms-1/#RotateDefined) in CSS Transforms with alpha = angle in degrees. [[CSS3-TRANSFORMS]](https://drafts.fxtf.org/geometry/#biblio-css3-transforms)

If x or y are not 0 or -0, set [is 2D](https://drafts.fxtf.org/geometry/#matrix-is-2d) of the current matrix to false.

Return the current matrix.
</blockquote>

And the 3D rotation matrix from [css-transforms-1](https://drafts.csswg.org/css-transforms/#mathematical-description):

<blockquote>

 A 2D rotation with the parameter alpha is equivalent to a 3D rotation with the vector [x,y,z] where x has zero as a value, y has zero as a value, z has one as a value, and the parameter alpha.

![Image](https://github.com/user-attachments/assets/3aa1bdff-e826-4c58-8f32-51f3e0c5feff)

where:

![Image](https://github.com/user-attachments/assets/4998aa83-3f6d-4487-a9c8-50cc206775c9)

</blockquote>

Is there any reason for browsers to return an identical result for `rotateAxisAngle(0, 0, z, angle)` regardless of the value of `z`?

<details>
<summary>Console results</summary>

```js
new DOMMatrix().rotateAxisAngleSelf(0, 0, 1, 40).toJSON()

{
  "a": 0.766044443118978,
  "b": 0.6427876096865393,
  "c": -0.6427876096865393,
  "d": 0.766044443118978,
  "e": 0,
  "f": 0,
  "m11": 0.766044443118978,
  "m12": 0.6427876096865393,
  "m13": 0,
  "m14": 0,
  "m21": -0.6427876096865393,
  "m22": 0.766044443118978,
  "m23": 0,
  "m24": 0,
  "m31": 0,
  "m32": 0,
  "m33": 1,
  "m34": 0,
  "m41": 0,
  "m42": 0,
  "m43": 0,
  "m44": 1,
  "is2D": false,
  "isIdentity": false
}

new DOMMatrix().rotateAxisAngleSelf(0, 0, 2, 40).toJSON() 

{
  "a": 0.766044443118978,
  "b": 0.6427876096865393,
  "c": -0.6427876096865393,
  "d": 0.766044443118978,
  "e": 0,
  "f": 0,
  "m11": 0.766044443118978,
  "m12": 0.6427876096865393,
  "m13": 0,
  "m14": 0,
  "m21": -0.6427876096865393,
  "m22": 0.766044443118978,
  "m23": 0,
  "m24": 0,
  "m31": 0,
  "m32": 0,
  "m33": 1,
  "m34": 0,
  "m41": 0,
  "m42": 0,
  "m43": 0,
  "m44": 1,
  "is2D": false,
  "isIdentity": false
}
```

</details>

Attaching, for convenience, a function to compute the rotation matrices, in which I’ve made perhaps an error:

```js
function getRotationMatrix(x = 0, y = 0, z = 0, angle = 0) {
 const s = Math.sin(angle * Math.PI / 360);
 const sc = s * Math.cos(angle * Math.PI / 360);
 const sq = s * s;
 if (x === 0 && y === 0) {
  return [
   1 - 2 * z * z * sq, 
   2 * z * sc, 
   -2 * z * sc, 
   1 - 2 * z * z * sq, 
   0, 
   0
  ];
 }
 return [
  1 - 2 * (y * y + z * z) * sq,
  2 * (x * y * sq + z * sc),
  2 * (x * z * sq - y * sc),
  0,
  2 * (x * y * sq - z * sc),
  1 - 2 * (x * x + z * z) * sq,
  2 * (y * z * sq + x * sc),
  0,
  2 * (x * z * sq + y * sc),
  2 * (y * z * sq - x * sc),
  1 - 2 * (x * x + y * y) * sq,
  0,
  0,
  0,
  0,
  1
 ];
}
```


Please view or discuss this issue at https://github.com/w3c/fxtf-drafts/issues/601 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Wednesday, 2 July 2025 12:32:40 UTC