このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docs コミュニティーについてもっと知り、仲間になるにはこちらから。

View in English Always switch to English

DOMMatrixReadOnly: transformPoint() メソッド

Baseline Widely available

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

メモ: この機能はウェブワーカー内で利用可能です。

transformPointDOMMatrixReadOnly インターフェイスのメソッドで、指定された点を行列によって座標変換し、新しい DOMPoint オブジェクトを作成します。行列も元の点も変更されません。

行列を点に適用して新しい DOMPoint を生成するのは DOMPointReadOnly.matrixTransform() メソッドでもできます。

構文

js
transformPoint()
transformPoint(point)

引数

point

DOMPoint または DOMPointReadOnly のインスタンス、または次のプロパティのうち最大 4 つを持つオブジェクトです。

x

空間の点の x 座標を表す数値です。デフォルト値は 0 です。

y

空間の点の y 座標を表す数値です。デフォルト値は 0 です。

z

空間の点の z 座標、または奥行き座標を表す数値です。デフォルト値は 0 です。正の数はユーザーに近づき、負の数は画面の奥へ遠ざかります。

w

点の w 視点値を表す数値です。デフォルト値は 1 です。

返値

DOMPoint です。

二次元座標変換

js
const matrix = new DOMMatrixReadOnly();
const point = new DOMPointReadOnly(10, 20); // DOMPointReadOnly {x: 10, y: 20, z: 0, w: 1}
let newPoint = matrix.transformPoint(point); // DOMPoint {x: 10, y: 20, z: 0, w: 1}

三次元座標変換

この例では、三次元の点に三次元の行列を適用します。

js
// Matrix with translate(22, 37, 10) applied
const matrix3D = new DOMMatrixReadOnly([
  1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 22, 37, 10, 1,
]);
const point3D = new DOMPointReadOnly(5, 10, 3); // DOMPointReadOnly {x: 5, y: 10, z: 3, w: 1}
const transformedPoint3D = point3D.matrixTransform(matrix3D); // DOMPoint {x: 27, y: 47, z: 13, w: 1}

仕様書

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

ブラウザーの互換性

関連情報