three.js Matrix3

2023-02-16 17:46 更新

一個(gè)表示3X3矩陣matrix.的類。

代碼示例

const m = new Matrix3();

注意行優(yōu)先列優(yōu)先的順序。

set()方法參數(shù)采用行優(yōu)先row-major, 而它們?cè)趦?nèi)部是用列優(yōu)先column-major順序存儲(chǔ)在數(shù)組當(dāng)中。

這意味著

m.set( 11, 12, 13,
       21, 22, 23,
       31, 32, 33 );

元素?cái)?shù)組elements將存儲(chǔ)為:

m.elements = [ 11, 21, 31,
              12, 22, 32,
              13, 23, 33 ];

在內(nèi)部,所有的計(jì)算都是使用列優(yōu)先順序進(jìn)行的。然而,由于實(shí)際的排序在數(shù)學(xué)上沒有什么不同, 而且大多數(shù)人習(xí)慣于以行優(yōu)先順序考慮矩陣,所以three.js文檔以行為主的順序顯示矩陣。 請(qǐng)記住,如果您正在閱讀源代碼,您必須對(duì)這里列出的任何矩陣進(jìn)行轉(zhuǎn)置transpose,以理解計(jì)算。

構(gòu)造器

Matrix3()

創(chuàng)建并初始化一個(gè)3X3的單位矩陣identity matrix.

屬性(Properties)

.elements : Array

矩陣列優(yōu)先column-major列表。

方法(Methods)

.clone () : Matrix3

創(chuàng)建一個(gè)新的矩陣,元素 elements 與該矩陣相同。

.copy ( m : Matrix3 ) : this

將矩陣m的元素復(fù)制到當(dāng)前矩陣中。

.determinant () : Float

計(jì)算并返回矩陣的行列式determinant 。

.equals ( m : Matrix3 ) : Boolean

如果矩陣m 與當(dāng)前矩陣所有對(duì)應(yīng)元素相同則返回true。

.extractBasis ( xAxis : Vector3, yAxis : Vector3, zAxis : Vector3 ) : this

將該矩陣的基向量 basis 提取到提供的三個(gè)軸向中。如果該矩陣如下:

a, b, c,
d, e, f,
g, h, i

那么 xAxis, yAxis, zAxis 將會(huì)被設(shè)置為:

xAxis = (a, d, g)
yAxis = (b, e, h)
zAxis = (c, f, i)

.fromArray ( array : Array, offset : Integer ) : this

array - 用來存儲(chǔ)設(shè)置元素?cái)?shù)據(jù)的數(shù)組
offset - (可選參數(shù)) 數(shù)組的偏移量,默認(rèn)值為 0。

使用基于列優(yōu)先格式column-major的數(shù)組來設(shè)置該矩陣。

.invert () : this

將當(dāng)前矩陣翻轉(zhuǎn)為它的逆矩陣,使用 analytic method 解析方式。你不能對(duì)行或列為 0 的矩陣進(jìn)行翻轉(zhuǎn),如果你嘗試這樣做,該方法將生成一個(gè)零矩陣。

.getNormalMatrix ( m : Matrix4 ) : this

m - Matrix4

將這個(gè)矩陣設(shè)置為給定矩陣的正規(guī)矩陣normal matrix(左上角的3x3)。 正規(guī)矩陣是矩陣m的逆矩陣inverse 的轉(zhuǎn)置transpose。

.identity () : this

將此矩陣重置為3x3單位矩陣:

1, 0, 0
0, 1, 0
0, 0, 1

.makeRotation ( theta : Float ) : this

theta — 以弧度為單位的旋轉(zhuǎn)角度。正值逆時(shí)針旋轉(zhuǎn)。

將此矩陣設(shè)置為按 theta 弧度的 2D 旋轉(zhuǎn)變換。結(jié)果矩陣將是:

cos(θ) -sin(θ) 0
sin(θ) cos(θ)  0
0      0       1

.makeScale ( x : Float, y : Float ) : this

x - 在 X 軸上縮放的量。

y - 在 Y 軸上縮放的量。

將此矩陣設(shè)置為二維比例變換:

x, 0, 0,
0, y, 0,
0, 0, 1

.makeTranslation ( x : Float, y : Float ) : this

x - 在 X 軸上平移的量。

y - 在 Y 軸上平移的量。

將此矩陣設(shè)置為 2D 平移變換:

1, 0, x,
0, 1, y,
0, 0, 1

.multiply ( m : Matrix3 ) : this

將當(dāng)前矩陣乘以矩陣m。

.multiplyMatrices ( a : Matrix3, b : Matrix3 ) : this

設(shè)置當(dāng)前矩陣為矩陣a x 矩陣b。

.multiplyScalar ( s : Float ) : this

當(dāng)前矩陣所有的元素乘以該縮放值s

.set ( n11 : Float, n12 : Float, n13 : Float, n21 : Float, n22 : Float, n23 : Float, n31 : Float, n32 : Float, n33 : Float ) : this

n11 - 設(shè)置第一行第一列的值。
n12 - 設(shè)置第一行第二列的值。
...
...
n32 - 設(shè)置第三行第二列的值。
n33 - 設(shè)置第三行第三列的值。

使用行優(yōu)先 row-major 的格式來設(shè)置該矩陣。

.premultiply ( m : Matrix3 ) : this

將矩陣m乘以當(dāng)前矩陣。

.setFromMatrix4 ( m : Matrix4 ) : this

根據(jù)參數(shù) m 左上 3x3 的矩陣值,設(shè)置當(dāng)前矩陣的值。

.setUvTransform ( tx : Float, ty : Float, sx : Float, sy : Float, rotation : Float, cx : Float, cy : Float ) : this

tx - x偏移量
ty - y偏移量
sx - x方向的重復(fù)比例
sy - y方向的重復(fù)比例
rotation - 旋轉(zhuǎn), 弧度。正值逆時(shí)針旋轉(zhuǎn)

cx - 旋轉(zhuǎn)中心x
cy - 旋轉(zhuǎn)中心y

使用偏移,重復(fù),旋轉(zhuǎn)和中心點(diǎn)位置設(shè)置UV變換矩陣。

.toArray ( array : Array, offset : Integer ) : Array

array - (可選參數(shù)) 存儲(chǔ)矩陣元素的數(shù)組,如果未指定會(huì)創(chuàng)建一個(gè)新的數(shù)組。
offset - (可選參數(shù)) 存放矩陣元素?cái)?shù)組的偏移量。

使用列優(yōu)先column-major格式將此矩陣的元素寫入數(shù)組中。

.transpose () : this

將該矩陣轉(zhuǎn)置Transposes。

.transposeIntoArray ( array : Array ) : this

array - 用于存儲(chǔ)當(dāng)前矩陣轉(zhuǎn)置結(jié)果的數(shù)組。

將當(dāng)前矩陣的轉(zhuǎn)置Transposes存入給定的數(shù)組 array 中,但不改變當(dāng)前矩陣, 并返回當(dāng)前矩陣。

源碼(Source)

src/math/Matrix3.js


以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)