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

瀏覽器相容性

另見