DOMMatrixReadOnly:rotateFromVector() 方法

Baseline 已广泛支持

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

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

DOMMatrixReadOnly 接口的 rotateFromVector() 方法会返回一个新的 DOMMatrix 对象,该对象由源矩阵围绕指定向量与 (1, 0) 之间的角度进行旋转而创建。旋转角度由向量 (1,0)T(x,y)T 之间顺时针方向的角度确定,即 (+/-)arctan(y/x)。如果 xy 都为 0,则角度指定为 0。原始矩阵不会被修改。

要修改矩阵,使其围绕指定向量与 (1, 0) 之间的角度旋转,请参阅 DOMMatrix.rotateFromVectorSelf()

语法

js
rotateFromVector()
rotateFromVector(rotX)
rotateFromVector(rotX, rotY)

参数

rotX 可选

一个数字;用于确定旋转角度的 x,y 向量的 x 坐标。如果未定义,则使用 0

rotY 可选

一个数字;用于确定旋转角度的 x,y 向量的 y 坐标。如果未定义,则使用 0

返回值

一个 DOMMatrix

示例

js
const matrix = new DOMMatrix(); // create a matrix
console.log(matrix.toString()); // original value
// output: "matrix(1, 0, 0, 1, 0, 0)"

console.log(matrix.rotateFromVector().toString()); // defaults to `0`
// output: matrix(1, 0, 0, 1, 0, 0)

console.log(matrix.rotateFromVector(10, 20).toString());
// matrix(0.447, 0.894, -0.894, 0.447, 0, 0)

console.log(matrix.rotateFromVector(-5, 5).toString());
// matrix(-0.707, 0.707, -0.707, -0.707, 0, 0)

console.log(matrix.toString()); // matrix remains unchanged
// output: "matrix(1, 0, 0, 1, 0, 0)"

规范

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

浏览器兼容性

另见