Dieser Inhalt wurde automatisch aus dem Englischen übersetzt, und kann Fehler enthalten. Erfahre mehr über dieses Experiment.

View in English Always switch to English

DOMMatrix: fromFloat64Array() statische Methode

Baseline Widely available

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

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

Die fromFloat64Array() statische Methode der DOMMatrix Schnittstelle erstellt ein neues DOMMatrix Objekt aus einem Array von Gleitkommazahlen mit Doppelpräzision (64-Bit).

Hat das Array 6 Werte, ist das Ergebnis eine 2D-Matrix; hat das Array 16 Werte, ist das Ergebnis eine 3D-Matrix. Andernfalls wird eine TypeError-Ausnahme ausgelöst.

Syntax

js
DOMMatrix.fromFloat64Array(array)

Parameter

array

Ein Float64Array mit 6 oder 16 Elementen in spaltenweiser Anordnung.

Rückgabewert

Ein DOMMatrix Objekt.

Ausnahmen

TypeError

Wird ausgelöst, wenn die Länge des array-Parameters nicht 6 oder 16 ist.

Beispiele

Erstellen einer 2D-Matrix aus einem Float64Array

Dieses Beispiel erstellt eine 2D-Matrix aus einem 6-Elemente Float64Array.

js
const float64Array = new Float64Array([1, 0, 0, 1, 10, 20]);
const matrix2D = DOMMatrix.fromFloat64Array(float64Array);

console.log(matrix2D.toString());
// Output: matrix(1, 0, 0, 1, 10, 20)

console.log(matrix2D.is2D);
// Output: true

console.log(matrix2D.e, matrix2D.f);
// Output: 10 20

Erstellen einer 3D-Matrix aus einem Float64Array

Dieses Beispiel erstellt eine 3D-Matrix aus einem 16-Elemente Float64Array.

js
const float64Array = new Float64Array([
  1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 10, 20, 30, 1,
]);
const matrix3D = DOMMatrix.fromFloat64Array(float64Array);

console.log(matrix3D.is2D);
// Output: false

console.log(matrix3D.m41, matrix3D.m42, matrix3D.m43);
// Output: 10 20 30

Spezifikationen

Specification
Geometry Interfaces Module Level 1
# dom-dommatrix-fromfloat64array

Browser-Kompatibilität

Siehe auch