Matrix3.html 12 KB

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