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

View in English Always switch to English

DOMMatrixReadOnly: fromFloat32Array() 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 fromFloat32Array() statische Methode des DOMMatrixReadOnly-Interfaces erstellt ein neues DOMMatrixReadOnly-Objekt aus einem Array von Einzelpräzisions-Gleitkommawerten (32-Bit).

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

Syntax

js
DOMMatrixReadOnly.fromFloat32Array(array)

Parameter

array

Ein Float32Array mit 6 oder 16 Elementen in spaltenweiser Anordnung.

Rückgabewert

Ein DOMMatrixReadOnly-Objekt.

Ausnahmen

TypeError

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

Beispiele

Erstellen einer 2D-Matrix aus einem Float32Array

Dieses Beispiel erstellt eine 2D-Matrix aus einem 6-Element-Float32Array.

js
const float32Array = new Float32Array([1, 0, 0, 1, 10, 20]);
const matrix2D = DOMMatrixReadOnly.fromFloat32Array(float32Array);

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

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

Erstellen einer 3D-Matrix aus einem Float32Array

Dieses Beispiel erstellt eine 3D-Matrix aus einem 16-Element-Float32Array.

js
const float32Array = new Float32Array([
  1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 10, 20, 30, 1,
]);
const matrix3D = DOMMatrixReadOnly.fromFloat32Array(float32Array);

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-dommatrixreadonly-fromfloat32array

Browser-Kompatibilität

Siehe auch