DOMMatrixReadOnly: rotateAxisAngle() 方法

Baseline 已广泛支持

此特性已相当成熟,可在许多设备和浏览器版本上使用。自 ⁨2020 年 1 月⁩ 起,所有主流浏览器均已支持。

注意:此功能在 Web Workers 中可用。

DOMMatrixReadOnly 接口的 rotateAxisAngle() 方法会返回一个新的 DOMMatrix 对象,该对象通过将源矩阵绕给定向量和角度进行旋转而创建。原始矩阵不会被修改。

要旋转矩阵并直接修改它,请参阅 DOMMatrix.rotateAxisAngleSelf()

语法

js
rotateAxisAngle()
rotateAxisAngle(rotX)
rotateAxisAngle(rotX, rotY)
rotateAxisAngle(rotX, rotY, rotZ)
rotateAxisAngle(rotX, rotY, rotZ, angle)

参数

rotX

一个数字;表示旋转轴的向量的 x 坐标。如果非零,则 is2D 为 false。

rotY 可选

一个数字;表示旋转轴的向量的 y 坐标。如果未定义,则使用 rotX 的值。如果非零,则 is2D 为 false。

rotZ 可选

一个数字;表示旋转轴的向量的 z 坐标。如果未定义,则使用 rotX 的值。

angle 可选

一个数字;围绕轴向量的旋转角度,以度为单位。

返回值

一个 DOMMatrix

示例

js
const matrix = new DOMMatrix(); // create a matrix
console.log(matrix.rotateAxisAngle().toString()); // matrix(1, 0, 0, 1, 0, 0)
console.log(matrix.rotateAxisAngle(10, 20, 30).toString()); // matrix(1, 0, 0, 1, 0, 0)
console.log(matrix.rotateAxisAngle(10, 20, 30, 45).toString());
/* matrix3d(
    0.728, 0.609, -0.315, 0, 
    -0.525, 0.791, 0.315, 0, 
    0.441, -0.063, 0.895, 
    0, 0, 0, 0, 1) */
console.log(matrix.rotateAxisAngle(5, 5, 5, -45).toString());
/* matrix3d(
    0.805, -0.311, 0.506, 0, 
    0.506, 0.805, -0.311, 0, 
    -0.311, 0.506, 0.805, 0, 
    0, 0, 0, 1) */
console.log(matrix.toString()); // output: "matrix(1, 0, 0, 1, 0, 0)" (unchanged)

规范

规范
Geometry Interfaces Module Level 1
# dom-dommatrixreadonly-rotateaxisangle

浏览器兼容性

另见