Matrix3.html 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8" />
  5. <base href="../../../" />
  6. <script src="page.js"></script>
  7. <link type="text/css" rel="stylesheet" href="page.css" />
  8. </head>
  9. <body>
  10. <h1>[name]</h1>
  11. <p class="desc">
  12. A class representing a 3x3
  13. [link:https://en.wikipedia.org/wiki/Matrix_(mathematics) matrix].
  14. </p>
  15. <h2>Code Example</h2>
  16. <code>
  17. const m = new Matrix3();
  18. </code>
  19. <h2>A Note on Row-Major and Column-Major Ordering</h2>
  20. <p>
  21. The constructor and [page:set]() method take arguments in
  22. [link:https://en.wikipedia.org/wiki/Row-_and_column-major_order#Column-major_order row-major]
  23. order, while internally they are stored in the [page:.elements elements]
  24. array in column-major order.<br /><br />
  25. This means that calling
  26. <code>
  27. m.set( 11, 12, 13,
  28. 21, 22, 23,
  29. 31, 32, 33 );
  30. </code>
  31. will result in the [page:.elements elements] array containing:
  32. <code>
  33. m.elements = [ 11, 21, 31,
  34. 12, 22, 32,
  35. 13, 23, 33 ];
  36. </code>
  37. and internally all calculations are performed using column-major ordering.
  38. However, as the actual ordering makes no difference mathematically and
  39. most people are used to thinking about matrices in row-major order, the
  40. three.js documentation shows matrices in row-major order. Just bear in
  41. mind that if you are reading the source code, you'll have to take the
  42. [link:https://en.wikipedia.org/wiki/Transpose transpose] of any matrices
  43. outlined here to make sense of the calculations.
  44. </p>
  45. <h2>Constructor</h2>
  46. <h3>[name]( [param:Number n11], [param:Number n12], [param:Number n13],
  47. [param:Number n21], [param:Number n22], [param:Number n23],
  48. [param:Number n31], [param:Number n32], [param:Number n33] )</h3>
  49. <p>
  50. Creates a 3x3 matrix with the given arguments in row-major order. If no arguments are provided, the constructor initializes
  51. the [name] to the 3x3 [link:https://en.wikipedia.org/wiki/Identity_matrix identity matrix].
  52. </p>
  53. <h2>Properties</h2>
  54. <h3>[property:Array elements]</h3>
  55. <p>
  56. A [link:https://en.wikipedia.org/wiki/Row-_and_column-major_order column-major] list of matrix values.
  57. </p>
  58. <h2>Methods</h2>
  59. <h3>[method:Matrix3 clone]()</h3>
  60. <p>Creates a new Matrix3 and with identical elements to this one.</p>
  61. <h3>[method:this copy]( [param:Matrix3 m] )</h3>
  62. <p>Copies the elements of matrix [page:Matrix3 m] into this matrix.</p>
  63. <h3>[method:Float determinant]()</h3>
  64. <p>
  65. Computes and returns the [link:https://en.wikipedia.org/wiki/Determinant determinant] of this matrix.
  66. </p>
  67. <h3>[method:Boolean equals]( [param:Matrix3 m] )</h3>
  68. <p>Return true if this matrix and [page:Matrix3 m] are equal.</p>
  69. <h3>
  70. [method:this extractBasis]( [param:Vector3 xAxis], [param:Vector3 yAxis], [param:Vector3 zAxis] )
  71. </h3>
  72. <p>
  73. Extracts the [link:https://en.wikipedia.org/wiki/Basis_(linear_algebra) basis]
  74. of this matrix into the three axis vectors provided. If this matrix
  75. is:
  76. <code>
  77. a, b, c,
  78. d, e, f,
  79. g, h, i
  80. </code>
  81. then the [page:Vector3 xAxis], [page:Vector3 yAxis], [page:Vector3 zAxis]
  82. will be set to:
  83. <code>
  84. xAxis = (a, d, g)
  85. yAxis = (b, e, h)
  86. zAxis = (c, f, i)
  87. </code>
  88. </p>
  89. <h3>
  90. [method:this fromArray]( [param:Array array], [param:Integer offset] )
  91. </h3>
  92. <p>
  93. [page:Array array] - the array to read the elements from.<br />
  94. [page:Integer offset] - (optional) index of first element in the array.
  95. Default is `0`.<br /><br />
  96. Sets the elements of this matrix based on an array in
  97. [link:https://en.wikipedia.org/wiki/Row-_and_column-major_order#Column-major_order column-major] format.
  98. </p>
  99. <h3>[method:this invert]()</h3>
  100. <p>
  101. Inverts this matrix, using the
  102. [link:https://en.wikipedia.org/wiki/Invertible_matrix#Analytic_solution analytic method].
  103. You can not invert with a determinant of zero. If you
  104. attempt this, the method produces a zero matrix instead.
  105. </p>
  106. <h3>[method:this getNormalMatrix]( [param:Matrix4 m] )</h3>
  107. <p>
  108. [page:Matrix4 m] - [page:Matrix4]<br /><br />
  109. Sets this matrix as the upper left 3x3 of the
  110. [link:https://en.wikipedia.org/wiki/Normal_matrix normal matrix] of the
  111. passed [page:Matrix4 matrix4].
  112. The normal matrix is the
  113. [link:https://en.wikipedia.org/wiki/Invertible_matrix inverse]
  114. [link:https://en.wikipedia.org/wiki/Transpose transpose] of the matrix
  115. [page:Matrix4 m].
  116. </p>
  117. <h3>[method:this identity]()</h3>
  118. <p>
  119. Resets this matrix to the 3x3 identity matrix:
  120. <code>
  121. 1, 0, 0
  122. 0, 1, 0
  123. 0, 0, 1 </code>
  124. </p>
  125. <h3>[method:this makeRotation]( [param:Float theta] )</h3>
  126. <p>
  127. [page:Float theta] — Rotation angle in radians. Positive values rotate
  128. counterclockwise.<br /><br />
  129. Sets this matrix as a 2D rotational transformation by [page:Float theta]
  130. radians. The resulting matrix will be:
  131. <code>
  132. cos(&theta;) -sin(&theta;) 0
  133. sin(&theta;) cos(&theta;) 0
  134. 0 0 1
  135. </code>
  136. </p>
  137. <h3>[method:this makeScale]( [param:Float x], [param:Float y] )</h3>
  138. <p>
  139. [page:Float x] - the amount to scale in the X axis.<br />
  140. [page:Float y] - the amount to scale in the Y axis.<br />
  141. Sets this matrix as a 2D scale transform:
  142. <code>
  143. x, 0, 0,
  144. 0, y, 0,
  145. 0, 0, 1 </code>
  146. </p>
  147. <h3>[method:this makeTranslation]( [param:Vector2 v] )</h3>
  148. <h3>[method:this makeTranslation]( [param:Float x], [param:Float y] )</h3>
  149. <p>
  150. [page:Vector2 v] a translation transform from vector.<br />
  151. or<br />
  152. [page:Float x] - the amount to translate in the X axis.<br />
  153. [page:Float y] - the amount to translate in the Y axis.<br />
  154. Sets this matrix as a 2D translation transform:
  155. <code>
  156. 1, 0, x,
  157. 0, 1, y,
  158. 0, 0, 1 </code>
  159. </p>
  160. <h3>[method:this multiply]( [param:Matrix3 m] )</h3>
  161. <p>Post-multiplies this matrix by [page:Matrix3 m].</p>
  162. <h3>
  163. [method:this multiplyMatrices]( [param:Matrix3 a], [param:Matrix3 b] )
  164. </h3>
  165. <p>Sets this matrix to [page:Matrix3 a] x [page:Matrix3 b].</p>
  166. <h3>[method:this multiplyScalar]( [param:Float s] )</h3>
  167. <p>Multiplies every component of the matrix by the scalar value *s*.</p>
  168. <h3>[method:this rotate]( [param:Float theta] )</h3>
  169. <p>Rotates this matrix by the given angle (in radians).</p>
  170. <h3>[method:this scale]( [param:Float sx], [param:Float sy] )</h3>
  171. <p>Scales this matrix with the given scalar values.</p>
  172. <h3>
  173. [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] )
  174. </h3>
  175. <p>
  176. [page:Float n11] - value to put in row 1, col 1.<br />
  177. [page:Float n12] - value to put in row 1, col 2.<br />
  178. ...<br />
  179. ...<br />
  180. [page:Float n32] - value to put in row 3, col 2.<br />
  181. [page:Float n33] - value to put in row 3, col 3.<br /><br />
  182. Sets the 3x3 matrix values to the given
  183. [link:https://en.wikipedia.org/wiki/Row-_and_column-major_order row-major]
  184. sequence of values.
  185. </p>
  186. <h3>[method:this premultiply]( [param:Matrix3 m] )</h3>
  187. <p>Pre-multiplies this matrix by [page:Matrix3 m].</p>
  188. <h3>[method:this setFromMatrix4]( [param:Matrix4 m] )</h3>
  189. <p>
  190. Set this matrix to the upper 3x3 matrix of the Matrix4 [page:Matrix4 m].
  191. </p>
  192. <h3>
  193. [method:this setUvTransform]( [param:Float tx], [param:Float ty], [param:Float sx], [param:Float sy], [param:Float rotation], [param:Float cx], [param:Float cy] )
  194. </h3>
  195. <p>
  196. [page:Float tx] - offset x<br />
  197. [page:Float ty] - offset y<br />
  198. [page:Float sx] - repeat x<br />
  199. [page:Float sy] - repeat y<br />
  200. [page:Float rotation] - rotation, in radians. Positive values rotate
  201. counterclockwise<br />
  202. [page:Float cx] - center x of rotation<br />
  203. [page:Float cy] - center y of rotation<br /><br />
  204. Sets the UV transform matrix from offset, repeat, rotation, and center.
  205. </p>
  206. <h3>
  207. [method:Array toArray]( [param:Array array], [param:Integer offset] )
  208. </h3>
  209. <p>
  210. [page:Array array] - (optional) array to store the resulting vector in. If
  211. not given a new array will be created.<br />
  212. [page:Integer offset] - (optional) offset in the array at which to put the
  213. result.<br /><br />
  214. Writes the elements of this matrix to an array in
  215. [link:https://en.wikipedia.org/wiki/Row-_and_column-major_order#Column-major_order column-major] format.
  216. </p>
  217. <h3>[method:this translate]( [param:Float tx], [param:Float ty] )</h3>
  218. <p>Translates this matrix by the given scalar values.</p>
  219. <h3>[method:this transpose]()</h3>
  220. <p>
  221. [link:https://en.wikipedia.org/wiki/Transpose Transposes] this matrix in
  222. place.
  223. </p>
  224. <h3>[method:this transposeIntoArray]( [param:Array array] )</h3>
  225. <p>
  226. [page:Array array] - array to store the resulting vector in.<br /><br />
  227. [link:https://en.wikipedia.org/wiki/Transpose Transposes] this matrix into
  228. the supplied array, and returns itself unchanged.
  229. </p>
  230. <h2>Source</h2>
  231. <p>
  232. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  233. </p>
  234. </body>
  235. </html>