Matrix3.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  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:<br /><br />
  76. <math>
  77. <mrow>
  78. <mo>[</mo>
  79. <mtable>
  80. <mtr>
  81. <mtd><mi>a</mi></mtd>
  82. <mtd><mi>b</mi></mtd>
  83. <mtd><mi>c</mi></mtd>
  84. </mtr>
  85. <mtr>
  86. <mtd><mi>d</mi></mtd>
  87. <mtd><mi>e</mi></mtd>
  88. <mtd><mi>f</mi></mtd>
  89. </mtr>
  90. <mtr>
  91. <mtd><mi>g</mi></mtd>
  92. <mtd><mi>h</mi></mtd>
  93. <mtd><mi>i</mi></mtd>
  94. </mtr>
  95. </mtable>
  96. <mo>]</mo>
  97. </mrow>
  98. </math><br /><br />
  99. then the [page:Vector3 xAxis], [page:Vector3 yAxis], [page:Vector3 zAxis]
  100. will be set to:<br /><br />
  101. <math>
  102. <mrow>
  103. <mi>xAxis</mi>
  104. <mo>=</mo>
  105. <mo>[</mo>
  106. <mtable>
  107. <mtr><mtd style="height: 1rem"><mi>a</mi></mtd></mtr>
  108. <mtr><mtd style="height: 1rem"><mi>d</mi></mtd></mtr>
  109. <mtr><mtd style="height: 1rem"><mi>g</mi></mtd></mtr>
  110. </mtable>
  111. <mo>]</mo>
  112. </mrow>
  113. </math>,
  114. <math>
  115. <mrow>
  116. <mi>yAxis</mi>
  117. <mo>=</mo>
  118. <mo>[</mo>
  119. <mtable>
  120. <mtr><mtd style="height: 1rem"><mi>b</mi></mtd></mtr>
  121. <mtr><mtd style="height: 1rem"><mi>e</mi></mtd></mtr>
  122. <mtr><mtd style="height: 1rem"><mi>h</mi></mtd></mtr>
  123. </mtable>
  124. <mo>]</mo>
  125. </mrow>
  126. </math>, and
  127. <math>
  128. <mrow>
  129. <mi>zAxis</mi>
  130. <mo>=</mo>
  131. <mo>[</mo>
  132. <mtable>
  133. <mtr><mtd style="height: 1rem"><mi>c</mi></mtd></mtr>
  134. <mtr><mtd style="height: 1rem"><mi>f</mi></mtd></mtr>
  135. <mtr><mtd style="height: 1rem"><mi>i</mi></mtd></mtr>
  136. </mtable>
  137. <mo>]</mo>
  138. </mrow>
  139. </math>
  140. </p>
  141. <h3>
  142. [method:this fromArray]( [param:Array array], [param:Integer offset] )
  143. </h3>
  144. <p>
  145. [page:Array array] - the array to read the elements from.<br />
  146. [page:Integer offset] - (optional) index of first element in the array.
  147. Default is `0`.<br /><br />
  148. Sets the elements of this matrix based on an array in
  149. [link:https://en.wikipedia.org/wiki/Row-_and_column-major_order#Column-major_order column-major] format.
  150. </p>
  151. <h3>[method:this invert]()</h3>
  152. <p>
  153. Inverts this matrix, using the
  154. [link:https://en.wikipedia.org/wiki/Invertible_matrix#Analytic_solution analytic method].
  155. You can not invert with a determinant of zero. If you
  156. attempt this, the method produces a zero matrix instead.
  157. </p>
  158. <h3>[method:this getNormalMatrix]( [param:Matrix4 m] )</h3>
  159. <p>
  160. [page:Matrix4 m] - [page:Matrix4]<br /><br />
  161. Sets this matrix as the upper left 3x3 of the
  162. [link:https://en.wikipedia.org/wiki/Normal_matrix normal matrix] of the
  163. passed [page:Matrix4 matrix4].
  164. The normal matrix is the
  165. [link:https://en.wikipedia.org/wiki/Invertible_matrix inverse]
  166. [link:https://en.wikipedia.org/wiki/Transpose transpose] of the matrix
  167. [page:Matrix4 m].
  168. </p>
  169. <h3>[method:this identity]()</h3>
  170. <p>
  171. Resets this matrix to the 3x3 identity matrix:<br /><br />
  172. <math>
  173. <mrow>
  174. <mo>[</mo>
  175. <mtable>
  176. <mtr>
  177. <mtd><mn>1</mn></mtd>
  178. <mtd><mn>0</mn></mtd>
  179. <mtd><mn>0</mn></mtd>
  180. </mtr>
  181. <mtr>
  182. <mtd><mn>0</mn></mtd>
  183. <mtd><mn>1</mn></mtd>
  184. <mtd><mn>0</mn></mtd>
  185. </mtr>
  186. <mtr>
  187. <mtd><mn>0</mn></mtd>
  188. <mtd><mn>0</mn></mtd>
  189. <mtd><mn>1</mn></mtd>
  190. </mtr>
  191. </mtable>
  192. <mo>]</mo>
  193. </mrow>
  194. </math>
  195. </p>
  196. <h3>[method:this makeRotation]( [param:Float theta] )</h3>
  197. <p>
  198. [page:Float theta] — Rotation angle in radians. Positive values rotate
  199. counterclockwise.<br /><br />
  200. Sets this matrix as a 2D rotational transformation by [page:Float theta]
  201. radians. The resulting matrix will be:<br /><br />
  202. <math>
  203. <mrow>
  204. <mo>[</mo>
  205. <mtable>
  206. <mtr>
  207. <mtd>
  208. <mi>cos</mi>
  209. <mi>&theta;</mi>
  210. </mtd>
  211. <mtd>
  212. <mi>-sin</mi>
  213. <mi>&theta;</mi>
  214. </mtd>
  215. <mtd>
  216. <mn>0</mn>
  217. </mtd>
  218. </mtr>
  219. <mtr>
  220. <mtd>
  221. <mi>sin</mi>
  222. <mi>&theta;</mi>
  223. </mtd>
  224. <mtd>
  225. <mi>cos</mi>
  226. <mi>&theta;</mi>
  227. </mtd>
  228. <mtd>
  229. <mn>0</mn>
  230. </mtd>
  231. </mtr>
  232. <mtr>
  233. <mtd><mn>0</mn></mtd>
  234. <mtd><mn>0</mn></mtd>
  235. <mtd><mn>1</mn></mtd>
  236. </mtr>
  237. </mtable>
  238. <mo>]</mo>
  239. </mrow>
  240. </math>
  241. </p>
  242. <h3>[method:this makeScale]( [param:Float x], [param:Float y] )</h3>
  243. <p>
  244. [page:Float x] - the amount to scale in the X axis.<br />
  245. [page:Float y] - the amount to scale in the Y axis.<br />
  246. Sets this matrix as a 2D scale transform:<br /><br />
  247. <math>
  248. <mrow>
  249. <mo>[</mo>
  250. <mtable>
  251. <mtr>
  252. <mtd><mi>x</mi></mtd>
  253. <mtd><mn>0</mn></mtd>
  254. <mtd><mn>0</mn></mtd>
  255. </mtr>
  256. <mtr>
  257. <mtd><mn>0</mn></mtd>
  258. <mtd><mi>y</mi></mtd>
  259. <mtd><mn>0</mn></mtd>
  260. </mtr>
  261. <mtr>
  262. <mtd><mn>0</mn></mtd>
  263. <mtd><mn>0</mn></mtd>
  264. <mtd><mn>1</mn></mtd>
  265. </mtr>
  266. </mtable>
  267. <mo>]</mo>
  268. </mrow>
  269. </math>
  270. </p>
  271. <h3>[method:this makeTranslation]( [param:Vector2 v] )</h3>
  272. <h3>[method:this makeTranslation]( [param:Float x], [param:Float y] )</h3>
  273. <p>
  274. [page:Vector2 v] a translation transform from vector.<br />
  275. or<br />
  276. [page:Float x] - the amount to translate in the X axis.<br />
  277. [page:Float y] - the amount to translate in the Y axis.<br />
  278. Sets this matrix as a 2D translation transform:<br /><br />
  279. <math>
  280. <mrow>
  281. <mo>[</mo>
  282. <mtable>
  283. <mtr>
  284. <mtd><mn>1</mn></mtd>
  285. <mtd><mn>0</mn></mtd>
  286. <mtd><mi>x</mi></mtd>
  287. </mtr>
  288. <mtr>
  289. <mtd><mn>0</mn></mtd>
  290. <mtd><mn>1</mn></mtd>
  291. <mtd><mi>y</mi></mtd>
  292. </mtr>
  293. <mtr>
  294. <mtd><mn>0</mn></mtd>
  295. <mtd><mn>0</mn></mtd>
  296. <mtd><mn>1</mn></mtd>
  297. </mtr>
  298. </mtable>
  299. <mo>]</mo>
  300. </mrow>
  301. </math>
  302. </p>
  303. <h3>[method:this multiply]( [param:Matrix3 m] )</h3>
  304. <p>Post-multiplies this matrix by [page:Matrix3 m].</p>
  305. <h3>
  306. [method:this multiplyMatrices]( [param:Matrix3 a], [param:Matrix3 b] )
  307. </h3>
  308. <p>Sets this matrix to [page:Matrix3 a] x [page:Matrix3 b].</p>
  309. <h3>[method:this multiplyScalar]( [param:Float s] )</h3>
  310. <p>Multiplies every component of the matrix by the scalar value *s*.</p>
  311. <h3>[method:this rotate]( [param:Float theta] )</h3>
  312. <p>Rotates this matrix by the given angle (in radians).</p>
  313. <h3>[method:this scale]( [param:Float sx], [param:Float sy] )</h3>
  314. <p>Scales this matrix with the given scalar values.</p>
  315. <h3>
  316. [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] )
  317. </h3>
  318. <p>
  319. Sets the 3x3 matrix values to the given
  320. [link:https://en.wikipedia.org/wiki/Row-_and_column-major_order row-major]
  321. sequence of values:<br /><br />
  322. <math>
  323. <mrow>
  324. <mo>[</mo>
  325. <mtable>
  326. <mtr>
  327. <mtd><mi>n11</mi></mtd>
  328. <mtd><mi>n12</mi></mtd>
  329. <mtd><mi>n13</mi></mtd>
  330. </mtr>
  331. <mtr>
  332. <mtd><mi>n21</mi></mtd>
  333. <mtd><mi>n22</mi></mtd>
  334. <mtd><mi>n23</mi></mtd>
  335. </mtr>
  336. <mtr>
  337. <mtd><mi>n31</mi></mtd>
  338. <mtd><mi>n32</mi></mtd>
  339. <mtd><mi>n33</mi></mtd>
  340. </mtr>
  341. </mtable>
  342. <mo>]</mo>
  343. </mrow>
  344. </math>
  345. </p>
  346. <h3>[method:this premultiply]( [param:Matrix3 m] )</h3>
  347. <p>Pre-multiplies this matrix by [page:Matrix3 m].</p>
  348. <h3>[method:this setFromMatrix4]( [param:Matrix4 m] )</h3>
  349. <p>
  350. Set this matrix to the upper 3x3 matrix of the Matrix4 [page:Matrix4 m].
  351. </p>
  352. <h3>
  353. [method:this setUvTransform]( [param:Float tx], [param:Float ty], [param:Float sx], [param:Float sy], [param:Float rotation], [param:Float cx], [param:Float cy] )
  354. </h3>
  355. <p>
  356. [page:Float tx] - offset x<br />
  357. [page:Float ty] - offset y<br />
  358. [page:Float sx] - repeat x<br />
  359. [page:Float sy] - repeat y<br />
  360. [page:Float rotation] - rotation, in radians. Positive values rotate
  361. counterclockwise<br />
  362. [page:Float cx] - center x of rotation<br />
  363. [page:Float cy] - center y of rotation<br /><br />
  364. Sets the UV transform matrix from offset, repeat, rotation, and center.
  365. </p>
  366. <h3>
  367. [method:Array toArray]( [param:Array array], [param:Integer offset] )
  368. </h3>
  369. <p>
  370. [page:Array array] - (optional) array to store the resulting vector in. If
  371. not given a new array will be created.<br />
  372. [page:Integer offset] - (optional) offset in the array at which to put the
  373. result.<br /><br />
  374. Writes the elements of this matrix to an array in
  375. [link:https://en.wikipedia.org/wiki/Row-_and_column-major_order#Column-major_order column-major] format.
  376. </p>
  377. <h3>[method:this translate]( [param:Float tx], [param:Float ty] )</h3>
  378. <p>Translates this matrix by the given scalar values.</p>
  379. <h3>[method:this transpose]()</h3>
  380. <p>
  381. [link:https://en.wikipedia.org/wiki/Transpose Transposes] this matrix in
  382. place.
  383. </p>
  384. <h3>[method:this transposeIntoArray]( [param:Array array] )</h3>
  385. <p>
  386. [page:Array array] - array to store the resulting vector in.<br /><br />
  387. [link:https://en.wikipedia.org/wiki/Transpose Transposes] this matrix into
  388. the supplied array, and returns itself unchanged.
  389. </p>
  390. <h2>Source</h2>
  391. <p>
  392. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  393. </p>
  394. </body>
  395. </html>