DOMMatrixReadOnly: rotateFromVector()-Methode

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since January 2020.

Hinweis: Diese Funktion ist in Web Workers verfügbar.

Die rotateFromVector()-Methode der DOMMatrixReadOnly-Schnittstelle gibt eine neue DOMMatrix zurück, die durch Rotieren der Quellmatrix um den Winkel zwischen dem angegebenen Vektor und (1, 0) erstellt wurde. Der Drehwinkel wird durch den Winkel zwischen dem Vektor (1,0)T und (x,y)T im Uhrzeigersinn, oder (+/-)arctan(y/x), bestimmt. Wenn x und y beide 0 sind, wird der Winkel als 0 angegeben. Die ursprüngliche Matrix wird nicht verändert.

Um die Matrix zu manipulieren, während Sie sie um den Winkel zwischen dem angegebenen Vektor und (1, 0) drehen, siehe DOMMatrix.rotateFromVectorSelf().

Syntax

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

Parameter

rotX Optional

Eine Zahl; Die x-Koordinate des x,y-Vektors, der den Drehwinkel bestimmt. Wenn nicht definiert, wird 0 verwendet.

rotY Optional

Eine Zahl; Die y-Koordinate des x,y-Vektors, der den Drehwinkel bestimmt. Wenn nicht definiert, wird 0 verwendet.

Rückgabewert

Eine DOMMatrix.

Beispiele

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)"

Spezifikationen

Specification
Geometry Interfaces Module Level 1
# dom-dommatrixreadonly-rotatefromvector

Browser-Kompatibilität

BCD tables only load in the browser

Siehe auch