You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

454 lines
12 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<base href="../../../" />
<script src="page.js"></script>
<link type="text/css" rel="stylesheet" href="page.css" />
</head>
<body>
<h1>[name]</h1>
<p class="desc">
A class representing a 3x3
[link:https://en.wikipedia.org/wiki/Matrix_(mathematics) matrix].
</p>
<h2>Code Example</h2>
<code>
const m = new Matrix3();
</code>
<h2>A Note on Row-Major and Column-Major Ordering</h2>
<p>
The constructor and [page:set]() method take arguments in
[link:https://en.wikipedia.org/wiki/Row-_and_column-major_order#Column-major_order row-major]
order, while internally they are stored in the [page:.elements elements]
array in column-major order.<br /><br />
This means that calling
<code>
m.set( 11, 12, 13,
21, 22, 23,
31, 32, 33 );
</code>
will result in the [page:.elements elements] array containing:
<code>
m.elements = [ 11, 21, 31,
12, 22, 32,
13, 23, 33 ];
</code>
and internally all calculations are performed using column-major ordering.
However, as the actual ordering makes no difference mathematically and
most people are used to thinking about matrices in row-major order, the
three.js documentation shows matrices in row-major order. Just bear in
mind that if you are reading the source code, you'll have to take the
[link:https://en.wikipedia.org/wiki/Transpose transpose] of any matrices
outlined here to make sense of the calculations.
</p>
<h2>Constructor</h2>
<h3>[name]( [param:Number n11], [param:Number n12], [param:Number n13],
[param:Number n21], [param:Number n22], [param:Number n23],
[param:Number n31], [param:Number n32], [param:Number n33] )</h3>
<p>
Creates a 3x3 matrix with the given arguments in row-major order. If no arguments are provided, the constructor initializes
the [name] to the 3x3 [link:https://en.wikipedia.org/wiki/Identity_matrix identity matrix].
</p>
<h2>Properties</h2>
<h3>[property:Array elements]</h3>
<p>
A [link:https://en.wikipedia.org/wiki/Row-_and_column-major_order column-major] list of matrix values.
</p>
<h2>Methods</h2>
<h3>[method:Matrix3 clone]()</h3>
<p>Creates a new Matrix3 and with identical elements to this one.</p>
<h3>[method:this copy]( [param:Matrix3 m] )</h3>
<p>Copies the elements of matrix [page:Matrix3 m] into this matrix.</p>
<h3>[method:Float determinant]()</h3>
<p>
Computes and returns the [link:https://en.wikipedia.org/wiki/Determinant determinant] of this matrix.
</p>
<h3>[method:Boolean equals]( [param:Matrix3 m] )</h3>
<p>Return true if this matrix and [page:Matrix3 m] are equal.</p>
<h3>
[method:this extractBasis]( [param:Vector3 xAxis], [param:Vector3 yAxis], [param:Vector3 zAxis] )
</h3>
<p>
Extracts the [link:https://en.wikipedia.org/wiki/Basis_(linear_algebra) basis]
of this matrix into the three axis vectors provided. If this matrix
is:
</p>
<math display="block">
<mrow>
<mo>[</mo>
<mtable>
<mtr>
<mtd><mi>a</mi></mtd>
<mtd><mi>b</mi></mtd>
<mtd><mi>c</mi></mtd>
</mtr>
<mtr>
<mtd><mi>d</mi></mtd>
<mtd><mi>e</mi></mtd>
<mtd><mi>f</mi></mtd>
</mtr>
<mtr>
<mtd><mi>g</mi></mtd>
<mtd><mi>h</mi></mtd>
<mtd><mi>i</mi></mtd>
</mtr>
</mtable>
<mo>]</mo>
</mrow>
</math>
<p>
then the [page:Vector3 xAxis], [page:Vector3 yAxis], [page:Vector3 zAxis]
will be set to:
</p>
<p style="text-align: center">
<math>
<mrow>
<mi>xAxis</mi>
<mo>=</mo>
<mo>[</mo>
<mtable>
<mtr><mtd style="height: 1rem"><mi>a</mi></mtd></mtr>
<mtr><mtd style="height: 1rem"><mi>d</mi></mtd></mtr>
<mtr><mtd style="height: 1rem"><mi>g</mi></mtd></mtr>
</mtable>
<mo>]</mo>
</mrow>
</math>,
<math>
<mrow>
<mi>yAxis</mi>
<mo>=</mo>
<mo>[</mo>
<mtable>
<mtr><mtd style="height: 1rem"><mi>b</mi></mtd></mtr>
<mtr><mtd style="height: 1rem"><mi>e</mi></mtd></mtr>
<mtr><mtd style="height: 1rem"><mi>h</mi></mtd></mtr>
</mtable>
<mo>]</mo>
</mrow>
</math>, and
<math>
<mrow>
<mi>zAxis</mi>
<mo>=</mo>
<mo>[</mo>
<mtable>
<mtr><mtd style="height: 1rem"><mi>c</mi></mtd></mtr>
<mtr><mtd style="height: 1rem"><mi>f</mi></mtd></mtr>
<mtr><mtd style="height: 1rem"><mi>i</mi></mtd></mtr>
</mtable>
<mo>]</mo>
</mrow>
</math>
</p>
<h3>
[method:this fromArray]( [param:Array array], [param:Integer offset] )
</h3>
<p>
[page:Array array] - the array to read the elements from.<br />
[page:Integer offset] - (optional) index of first element in the array.
Default is `0`.<br /><br />
Sets the elements of this matrix based on an array in
[link:https://en.wikipedia.org/wiki/Row-_and_column-major_order#Column-major_order column-major] format.
</p>
<h3>[method:this invert]()</h3>
<p>
Inverts this matrix, using the
[link:https://en.wikipedia.org/wiki/Invertible_matrix#Analytic_solution analytic method].
You can not invert with a determinant of zero. If you
attempt this, the method produces a zero matrix instead.
</p>
<h3>[method:this getNormalMatrix]( [param:Matrix4 m] )</h3>
<p>
[page:Matrix4 m] - [page:Matrix4]<br /><br />
Sets this matrix as the upper left 3x3 of the
[link:https://en.wikipedia.org/wiki/Normal_matrix normal matrix] of the
passed [page:Matrix4 matrix4].
The normal matrix is the
[link:https://en.wikipedia.org/wiki/Invertible_matrix inverse]
[link:https://en.wikipedia.org/wiki/Transpose transpose] of the matrix
[page:Matrix4 m].
</p>
<h3>[method:this identity]()</h3>
<p>
Resets this matrix to the 3x3 identity matrix:
</p>
<math display="block">
<mrow>
<mo>[</mo>
<mtable>
<mtr>
<mtd><mn>1</mn></mtd>
<mtd><mn>0</mn></mtd>
<mtd><mn>0</mn></mtd>
</mtr>
<mtr>
<mtd><mn>0</mn></mtd>
<mtd><mn>1</mn></mtd>
<mtd><mn>0</mn></mtd>
</mtr>
<mtr>
<mtd><mn>0</mn></mtd>
<mtd><mn>0</mn></mtd>
<mtd><mn>1</mn></mtd>
</mtr>
</mtable>
<mo>]</mo>
</mrow>
</math>
<h3>[method:this makeRotation]( [param:Float theta] )</h3>
<p>
[page:Float theta] — Rotation angle in radians. Positive values rotate
counterclockwise.<br /><br />
Sets this matrix as a 2D rotational transformation by [page:Float theta]
radians. The resulting matrix will be:
</p>
<math display="block">
<mrow>
<mo>[</mo>
<mtable>
<mtr>
<mtd>
<mi>cos</mi>
<mi>&theta;</mi>
</mtd>
<mtd>
<mi>-sin</mi>
<mi>&theta;</mi>
</mtd>
<mtd>
<mn>0</mn>
</mtd>
</mtr>
<mtr>
<mtd>
<mi>sin</mi>
<mi>&theta;</mi>
</mtd>
<mtd>
<mi>cos</mi>
<mi>&theta;</mi>
</mtd>
<mtd>
<mn>0</mn>
</mtd>
</mtr>
<mtr>
<mtd><mn>0</mn></mtd>
<mtd><mn>0</mn></mtd>
<mtd><mn>1</mn></mtd>
</mtr>
</mtable>
<mo>]</mo>
</mrow>
</math>
<h3>[method:this makeScale]( [param:Float x], [param:Float y] )</h3>
<p>
[page:Float x] - the amount to scale in the X axis.<br />
[page:Float y] - the amount to scale in the Y axis.<br />
Sets this matrix as a 2D scale transform:
</p>
<math display="block">
<mrow>
<mo>[</mo>
<mtable>
<mtr>
<mtd><mi>x</mi></mtd>
<mtd><mn>0</mn></mtd>
<mtd><mn>0</mn></mtd>
</mtr>
<mtr>
<mtd><mn>0</mn></mtd>
<mtd><mi>y</mi></mtd>
<mtd><mn>0</mn></mtd>
</mtr>
<mtr>
<mtd><mn>0</mn></mtd>
<mtd><mn>0</mn></mtd>
<mtd><mn>1</mn></mtd>
</mtr>
</mtable>
<mo>]</mo>
</mrow>
</math>
<h3>[method:this makeTranslation]( [param:Vector2 v] )</h3>
<h3>[method:this makeTranslation]( [param:Float x], [param:Float y] )</h3>
<p>
[page:Vector2 v] a translation transform from vector.<br />
or<br />
[page:Float x] - the amount to translate in the X axis.<br />
[page:Float y] - the amount to translate in the Y axis.<br />
Sets this matrix as a 2D translation transform:
</p>
<math display="block">
<mrow>
<mo>[</mo>
<mtable>
<mtr>
<mtd><mn>1</mn></mtd>
<mtd><mn>0</mn></mtd>
<mtd><mi>x</mi></mtd>
</mtr>
<mtr>
<mtd><mn>0</mn></mtd>
<mtd><mn>1</mn></mtd>
<mtd><mi>y</mi></mtd>
</mtr>
<mtr>
<mtd><mn>0</mn></mtd>
<mtd><mn>0</mn></mtd>
<mtd><mn>1</mn></mtd>
</mtr>
</mtable>
<mo>]</mo>
</mrow>
</math>
<h3>[method:this multiply]( [param:Matrix3 m] )</h3>
<p>Post-multiplies this matrix by [page:Matrix3 m].</p>
<h3>
[method:this multiplyMatrices]( [param:Matrix3 a], [param:Matrix3 b] )
</h3>
<p>Sets this matrix to [page:Matrix3 a] x [page:Matrix3 b].</p>
<h3>[method:this multiplyScalar]( [param:Float s] )</h3>
<p>Multiplies every component of the matrix by the scalar value *s*.</p>
<h3>[method:this rotate]( [param:Float theta] )</h3>
<p>Rotates this matrix by the given angle (in radians).</p>
<h3>[method:this scale]( [param:Float sx], [param:Float sy] )</h3>
<p>Scales this matrix with the given scalar values.</p>
<h3>
[method:this set]( [param:Float n11], [param:Float n12], [param:Float n13], [param:Float n21], [param:Float n22], [param:Float n23], [param:Float n31], [param:Float n32], [param:Float n33] )
</h3>
<p>
Sets the 3x3 matrix values to the given
[link:https://en.wikipedia.org/wiki/Row-_and_column-major_order row-major]
sequence of values:
</p>
<math display="block">
<mrow>
<mo>[</mo>
<mtable>
<mtr>
<mtd><mi>n11</mi></mtd>
<mtd><mi>n12</mi></mtd>
<mtd><mi>n13</mi></mtd>
</mtr>
<mtr>
<mtd><mi>n21</mi></mtd>
<mtd><mi>n22</mi></mtd>
<mtd><mi>n23</mi></mtd>
</mtr>
<mtr>
<mtd><mi>n31</mi></mtd>
<mtd><mi>n32</mi></mtd>
<mtd><mi>n33</mi></mtd>
</mtr>
</mtable>
<mo>]</mo>
</mrow>
</math>
<h3>[method:this premultiply]( [param:Matrix3 m] )</h3>
<p>Pre-multiplies this matrix by [page:Matrix3 m].</p>
<h3>[method:this setFromMatrix4]( [param:Matrix4 m] )</h3>
<p>
Set this matrix to the upper 3x3 matrix of the Matrix4 [page:Matrix4 m].
</p>
<h3>
[method:this setUvTransform]( [param:Float tx], [param:Float ty], [param:Float sx], [param:Float sy], [param:Float rotation], [param:Float cx], [param:Float cy] )
</h3>
<p>
[page:Float tx] - offset x<br />
[page:Float ty] - offset y<br />
[page:Float sx] - repeat x<br />
[page:Float sy] - repeat y<br />
[page:Float rotation] - rotation, in radians. Positive values rotate
counterclockwise<br />
[page:Float cx] - center x of rotation<br />
[page:Float cy] - center y of rotation<br /><br />
Sets the UV transform matrix from offset, repeat, rotation, and center.
</p>
<h3>
[method:Array toArray]( [param:Array array], [param:Integer offset] )
</h3>
<p>
[page:Array array] - (optional) array to store the resulting vector in. If
not given a new array will be created.<br />
[page:Integer offset] - (optional) offset in the array at which to put the
result.<br /><br />
Writes the elements of this matrix to an array in
[link:https://en.wikipedia.org/wiki/Row-_and_column-major_order#Column-major_order column-major] format.
</p>
<h3>[method:this translate]( [param:Float tx], [param:Float ty] )</h3>
<p>Translates this matrix by the given scalar values.</p>
<h3>[method:this transpose]()</h3>
<p>
[link:https://en.wikipedia.org/wiki/Transpose Transposes] this matrix in
place.
</p>
<h3>[method:this transposeIntoArray]( [param:Array array] )</h3>
<p>
[page:Array array] - array to store the resulting vector in.<br /><br />
[link:https://en.wikipedia.org/wiki/Transpose Transposes] this matrix into
the supplied array, and returns itself unchanged.
</p>
<h2>Source</h2>
<p>
[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
</p>
</body>
</html>