Matrix3.html 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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 [page:set]() method takes 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]()</h3>
  47. <p>
  48. Creates and initializes the [name] to the 3x3
  49. [link:https://en.wikipedia.org/wiki/Identity_matrix identity matrix].
  50. </p>
  51. <h2>Properties</h2>
  52. <h3>[property:Array elements]</h3>
  53. <p>
  54. A [link:https://en.wikipedia.org/wiki/Row-_and_column-major_order column-major] list of matrix values.
  55. </p>
  56. <h2>Methods</h2>
  57. <h3>[method:Matrix3 clone]()</h3>
  58. <p>Creates a new Matrix3 and with identical elements to this one.</p>
  59. <h3>[method:this copy]( [param:Matrix3 m] )</h3>
  60. <p>Copies the elements of matrix [page:Matrix3 m] into this matrix.</p>
  61. <h3>[method:Float determinant]()</h3>
  62. <p>
  63. Computes and returns the [link:https://en.wikipedia.org/wiki/Determinant determinant] of this matrix.
  64. </p>
  65. <h3>[method:Boolean equals]( [param:Matrix3 m] )</h3>
  66. <p>Return true if this matrix and [page:Matrix3 m] are equal.</p>
  67. <h3>
  68. [method:this extractBasis]( [param:Vector3 xAxis], [param:Vector3 yAxis], [param:Vector3 zAxis] )
  69. </h3>
  70. <p>
  71. Extracts the [link:https://en.wikipedia.org/wiki/Basis_(linear_algebra) basis]
  72. of this matrix into the three axis vectors provided. If this matrix
  73. is:
  74. <code>
  75. a, b, c,
  76. d, e, f,
  77. g, h, i
  78. </code>
  79. then the [page:Vector3 xAxis], [page:Vector3 yAxis], [page:Vector3 zAxis]
  80. will be set to:
  81. <code>
  82. xAxis = (a, d, g)
  83. yAxis = (b, e, h)
  84. zAxis = (c, f, i)
  85. </code>
  86. </p>
  87. <h3>
  88. [method:this fromArray]( [param:Array array], [param:Integer offset] )
  89. </h3>
  90. <p>
  91. [page:Array array] - the array to read the elements from.<br />
  92. [page:Integer offset] - (optional) index of first element in the array.
  93. Default is 0.<br /><br />
  94. Sets the elements of this matrix based on an array in
  95. [link:https://en.wikipedia.org/wiki/Row-_and_column-major_order#Column-major_order column-major] format.
  96. </p>
  97. <h3>[method:this invert]()</h3>
  98. <p>
  99. Inverts this matrix, using the
  100. [link:https://en.wikipedia.org/wiki/Invertible_matrix#Analytic_solution analytic method].
  101. You can not invert with a determinant of zero. If you
  102. attempt this, the method produces a zero matrix instead.
  103. </p>
  104. <h3>[method:this getNormalMatrix]( [param:Matrix4 m] )</h3>
  105. <p>
  106. [page:Matrix4 m] - [page:Matrix4]<br /><br />
  107. Sets this matrix as the upper left 3x3 of the
  108. [link:https://en.wikipedia.org/wiki/Normal_matrix normal matrix] of the
  109. passed [page:Matrix4 matrix4].
  110. The normal matrix is the
  111. [link:https://en.wikipedia.org/wiki/Invertible_matrix inverse]
  112. [link:https://en.wikipedia.org/wiki/Transpose transpose] of the matrix
  113. [page:Matrix4 m].
  114. </p>
  115. <h3>[method:this identity]()</h3>
  116. <p>
  117. Resets this matrix to the 3x3 identity matrix:
  118. <code>
  119. 1, 0, 0
  120. 0, 1, 0
  121. 0, 0, 1 </code>
  122. </p>
  123. <h3>[method:this makeRotation]( [param:Float theta] )</h3>
  124. <p>
  125. [page:Float theta] — Rotation angle in radians. Positive values rotate
  126. counterclockwise.<br /><br />
  127. Sets this matrix as a 2D rotational transformation by [page:Float theta]
  128. radians. The resulting matrix will be:
  129. <code>
  130. cos(&theta;) -sin(&theta;) 0
  131. sin(&theta;) cos(&theta;) 0
  132. 0 0 1
  133. </code>
  134. </p>
  135. <h3>[method:this makeScale]( [param:Float x], [param:Float y] )</h3>
  136. <p>
  137. [page:Float x] - the amount to scale in the X axis.<br />
  138. [page:Float y] - the amount to scale in the Y axis.<br />
  139. Sets this matrix as a 2D scale transform:
  140. <code>
  141. x, 0, 0,
  142. 0, y, 0,
  143. 0, 0, 1 </code>
  144. </p>
  145. <h3>[method:this makeTranslation]( [param:Float x], [param:Float y] )</h3>
  146. <p>
  147. [page:Float x] - the amount to translate in the X axis.<br />
  148. [page:Float y] - the amount to translate in the Y axis.<br />
  149. Sets this matrix as a 2D translation transform:
  150. <code>
  151. 1, 0, x,
  152. 0, 1, y,
  153. 0, 0, 1 </code>
  154. </p>
  155. <h3>[method:this multiply]( [param:Matrix3 m] )</h3>
  156. <p>Post-multiplies this matrix by [page:Matrix3 m].</p>
  157. <h3>
  158. [method:this multiplyMatrices]( [param:Matrix3 a], [param:Matrix3 b] )
  159. </h3>
  160. <p>Sets this matrix to [page:Matrix3 a] x [page:Matrix3 b].</p>
  161. <h3>[method:this multiplyScalar]( [param:Float s] )</h3>
  162. <p>Multiplies every component of the matrix by the scalar value *s*.</p>
  163. <h3>[method:this rotate]( [param:Float theta] )</h3>
  164. <p>Rotates this matrix by the given angle (in radians).</p>
  165. <h3>[method:this scale]( [param:Float sx], [param:Float sy] )</h3>
  166. <p>Scales this matrix with the given scalar values.</p>
  167. <h3>
  168. [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] )
  169. </h3>
  170. <p>
  171. [page:Float n11] - value to put in row 1, col 1.<br />
  172. [page:Float n12] - value to put in row 1, col 2.<br />
  173. ...<br />
  174. ...<br />
  175. [page:Float n32] - value to put in row 3, col 2.<br />
  176. [page:Float n33] - value to put in row 3, col 3.<br /><br />
  177. Sets the 3x3 matrix values to the given
  178. [link:https://en.wikipedia.org/wiki/Row-_and_column-major_order row-major]
  179. sequence of values.
  180. </p>
  181. <h3>[method:this premultiply]( [param:Matrix3 m] )</h3>
  182. <p>Pre-multiplies this matrix by [page:Matrix3 m].</p>
  183. <h3>[method:this setFromMatrix4]( [param:Matrix4 m] )</h3>
  184. <p>
  185. Set this matrix to the upper 3x3 matrix of the Matrix4 [page:Matrix4 m].
  186. </p>
  187. <h3>
  188. [method:this setUvTransform]( [param:Float tx], [param:Float ty], [param:Float sx], [param:Float sy], [param:Float rotation], [param:Float cx], [param:Float cy] )
  189. </h3>
  190. <p>
  191. [page:Float tx] - offset x<br />
  192. [page:Float ty] - offset y<br />
  193. [page:Float sx] - repeat x<br />
  194. [page:Float sy] - repeat y<br />
  195. [page:Float rotation] - rotation, in radians. Positive values rotate
  196. counterclockwise<br />
  197. [page:Float cx] - center x of rotation<br />
  198. [page:Float cy] - center y of rotation<br /><br />
  199. Sets the UV transform matrix from offset, repeat, rotation, and center.
  200. </p>
  201. <h3>
  202. [method:Array toArray]( [param:Array array], [param:Integer offset] )
  203. </h3>
  204. <p>
  205. [page:Array array] - (optional) array to store the resulting vector in. If
  206. not given a new array will be created.<br />
  207. [page:Integer offset] - (optional) offset in the array at which to put the
  208. result.<br /><br />
  209. Writes the elements of this matrix to an array in
  210. [link:https://en.wikipedia.org/wiki/Row-_and_column-major_order#Column-major_order column-major] format.
  211. </p>
  212. <h3>[method:this translate]( [param:Float tx], [param:Float ty] )</h3>
  213. <p>Translates this matrix by the given scalar values.</p>
  214. <h3>[method:this transpose]()</h3>
  215. <p>
  216. [link:https://en.wikipedia.org/wiki/Transpose Transposes] this matrix in
  217. place.
  218. </p>
  219. <h3>[method:this transposeIntoArray]( [param:Array array] )</h3>
  220. <p>
  221. [page:Array array] - array to store the resulting vector in.<br /><br />
  222. [link:https://en.wikipedia.org/wiki/Transpose Transposes] this matrix into
  223. the supplied array, and returns itself unchanged.
  224. </p>
  225. <h2>Source</h2>
  226. <p>
  227. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  228. </p>
  229. </body>
  230. </html>