Matrix3.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. <!DOCTYPE html>
  2. <html lang="zh">
  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. 一个表示3X3矩阵[link:https://en.wikipedia.org/wiki/Matrix_(mathematics) matrix].的类。
  13. </p>
  14. <h2>代码示例</h2>
  15. <code>
  16. const m = new Matrix3();
  17. </code>
  18. <h2>注意行优先列优先的顺序。</h2>
  19. <p>
  20. [page:set]()方法参数采用行优先[link:https://en.wikipedia.org/wiki/Row-_and_column-major_order#Column-major_order row-major],
  21. 而它们在内部是用列优先[link:https://en.wikipedia.org/wiki/Row-_and_column-major_order column-major]顺序存储在数组当中。<br /><br />
  22. 这意味着
  23. <code>
  24. m.set( 11, 12, 13,
  25. 21, 22, 23,
  26. 31, 32, 33 );
  27. </code>
  28. 元素数组[page:.elements elements]将存储为:
  29. <code>
  30. m.elements = [ 11, 21, 31,
  31. 12, 22, 32,
  32. 13, 23, 33 ];
  33. </code>
  34. 在内部,所有的计算都是使用列优先顺序进行的。然而,由于实际的排序在数学上没有什么不同,
  35. 而且大多数人习惯于以行优先顺序考虑矩阵,所以three.js文档以行为主的顺序显示矩阵。
  36. 请记住,如果您正在阅读源代码,您必须对这里列出的任何矩阵进行转置[link:https://en.wikipedia.org/wiki/Transpose transpose],以理解计算。
  37. </p>
  38. <h2>Constructor</h2>
  39. <h3>[name]( [param:Number n11], [param:Number n12], [param:Number n13],
  40. [param:Number n21], [param:Number n22], [param:Number n23],
  41. [param:Number n31], [param:Number n32], [param:Number n33] )</h3>
  42. <p>
  43. Creates a 3x3 matrix with the given arguments in row-major order. If no arguments are provided, the constructor initializes
  44. the [name] to the 3x3 [link:https://en.wikipedia.org/wiki/Identity_matrix identity matrix].
  45. </p>
  46. <h2>属性(Properties)</h2>
  47. <h3>[property:Array elements]</h3>
  48. <p>
  49. 矩阵列优先[link:https://en.wikipedia.org/wiki/Row-_and_column-major_order column-major]列表。
  50. </p>
  51. <h2>方法(Methods)</h2>
  52. <h3>[method:Matrix3 clone]()</h3>
  53. <p>创建一个新的矩阵,元素 [page:.elements elements] 与该矩阵相同。</p>
  54. <h3>[method:this copy]( [param:Matrix3 m] )</h3>
  55. <p>将矩阵[page:Matrix3 m]的元素复制到当前矩阵中。</p>
  56. <h3>[method:Float determinant]()</h3>
  57. <p>
  58. 计算并返回矩阵的行列式[link:https://en.wikipedia.org/wiki/Determinant determinant] 。
  59. </p>
  60. <h3>[method:Boolean equals]( [param:Matrix3 m] )</h3>
  61. <p>如果矩阵[page:Matrix3 m] 与当前矩阵所有对应元素相同则返回true。</p>
  62. <h3>[method:this extractBasis]( [param:Vector3 xAxis], [param:Vector3 yAxis], [param:Vector3 zAxis] )</h3>
  63. <p>
  64. 将该矩阵的基向量 [link:https://en.wikipedia.org/wiki/Basis_(linear_algebra) basis] 提取到提供的三个轴向中。如果该矩阵如下:
  65. </p>
  66. <math display="block">
  67. <mrow>
  68. <mo>[</mo>
  69. <mtable>
  70. <mtr>
  71. <mtd><mi>a</mi></mtd>
  72. <mtd><mi>b</mi></mtd>
  73. <mtd><mi>c</mi></mtd>
  74. </mtr>
  75. <mtr>
  76. <mtd><mi>d</mi></mtd>
  77. <mtd><mi>e</mi></mtd>
  78. <mtd><mi>f</mi></mtd>
  79. </mtr>
  80. <mtr>
  81. <mtd><mi>g</mi></mtd>
  82. <mtd><mi>h</mi></mtd>
  83. <mtd><mi>i</mi></mtd>
  84. </mtr>
  85. </mtable>
  86. <mo>]</mo>
  87. </mrow>
  88. </math>
  89. <p>
  90. 那么 [page:Vector3 xAxis], [page:Vector3 yAxis], [page:Vector3 zAxis] 将会被设置为:
  91. </p>
  92. <div style="text-align: center">
  93. <math>
  94. <mrow>
  95. <mi>xAxis</mi>
  96. <mo>=</mo>
  97. <mo>[</mo>
  98. <mtable>
  99. <mtr><mtd style="height: 1rem"><mi>a</mi></mtd></mtr>
  100. <mtr><mtd style="height: 1rem"><mi>d</mi></mtd></mtr>
  101. <mtr><mtd style="height: 1rem"><mi>g</mi></mtd></mtr>
  102. </mtable>
  103. <mo>]</mo>
  104. </mrow>
  105. </math>,
  106. <math>
  107. <mrow>
  108. <mi>yAxis</mi>
  109. <mo>=</mo>
  110. <mo>[</mo>
  111. <mtable>
  112. <mtr><mtd style="height: 1rem"><mi>b</mi></mtd></mtr>
  113. <mtr><mtd style="height: 1rem"><mi>e</mi></mtd></mtr>
  114. <mtr><mtd style="height: 1rem"><mi>h</mi></mtd></mtr>
  115. </mtable>
  116. <mo>]</mo>
  117. </mrow>
  118. </math>, and
  119. <math>
  120. <mrow>
  121. <mi>zAxis</mi>
  122. <mo>=</mo>
  123. <mo>[</mo>
  124. <mtable>
  125. <mtr><mtd style="height: 1rem"><mi>c</mi></mtd></mtr>
  126. <mtr><mtd style="height: 1rem"><mi>f</mi></mtd></mtr>
  127. <mtr><mtd style="height: 1rem"><mi>i</mi></mtd></mtr>
  128. </mtable>
  129. <mo>]</mo>
  130. </mrow>
  131. </math>
  132. </div>
  133. <h3>[method:this fromArray]( [param:Array array], [param:Integer offset] )</h3>
  134. <p>
  135. [page:Array array] - 用来存储设置元素数据的数组<br />
  136. [page:Integer offset] - (可选参数) 数组的偏移量,默认值为 0。<br /><br />
  137. 使用基于列优先格式[link:https://en.wikipedia.org/wiki/Row-_and_column-major_order#Column-major_order column-major]的数组来设置该矩阵。
  138. </p>
  139. <h3>[method:this invert]()</h3>
  140. <p>
  141. 将当前矩阵翻转为它的逆矩阵,使用 [link:https://en.wikipedia.org/wiki/Invertible_matrix#Analytic_solution analytic method] 解析方式。你不能对行或列为 0 的矩阵进行翻转,如果你尝试这样做,该方法将生成一个零矩阵。
  142. </p>
  143. <h3>[method:this getNormalMatrix]( [param:Matrix4 m] )</h3>
  144. <p>
  145. [page:Matrix4 m] - [page:Matrix4]<br /><br />
  146. 将这个矩阵设置为给定矩阵的正规矩阵[link:https://en.wikipedia.org/wiki/Normal_matrix normal matrix](左上角的3x3)。
  147. 正规矩阵是矩阵[page:Matrix4 m]的逆矩阵[link:https://en.wikipedia.org/wiki/Invertible_matrix inverse] 的转置[link:https://en.wikipedia.org/wiki/Transpose transpose]。
  148. </p>
  149. <h3>[method:this identity]()</h3>
  150. <p>
  151. 将此矩阵重置为3x3单位矩阵:
  152. </p>
  153. <math display="block">
  154. <mrow>
  155. <mo>[</mo>
  156. <mtable>
  157. <mtr>
  158. <mtd><mn>1</mn></mtd>
  159. <mtd><mn>0</mn></mtd>
  160. <mtd><mn>0</mn></mtd>
  161. </mtr>
  162. <mtr>
  163. <mtd><mn>0</mn></mtd>
  164. <mtd><mn>1</mn></mtd>
  165. <mtd><mn>0</mn></mtd>
  166. </mtr>
  167. <mtr>
  168. <mtd><mn>0</mn></mtd>
  169. <mtd><mn>0</mn></mtd>
  170. <mtd><mn>1</mn></mtd>
  171. </mtr>
  172. </mtable>
  173. <mo>]</mo>
  174. </mrow>
  175. </math>
  176. <h3>[method:this makeRotation]( [param:Float theta] )</h3>
  177. <p>
  178. [page:Float theta] — Rotation angle in radians. Positive values rotate counterclockwise.<br /><br />
  179. Sets this matrix as a 2D rotational transformation by [page:Float theta] radians.
  180. The resulting matrix will be:
  181. </p>
  182. <math display="block">
  183. <mrow>
  184. <mo>[</mo>
  185. <mtable>
  186. <mtr>
  187. <mtd>
  188. <mi>cos</mi>
  189. <mi>&theta;</mi>
  190. </mtd>
  191. <mtd>
  192. <mi>-sin</mi>
  193. <mi>&theta;</mi>
  194. </mtd>
  195. <mtd>
  196. <mn>0</mn>
  197. </mtd>
  198. </mtr>
  199. <mtr>
  200. <mtd>
  201. <mi>sin</mi>
  202. <mi>&theta;</mi>
  203. </mtd>
  204. <mtd>
  205. <mi>cos</mi>
  206. <mi>&theta;</mi>
  207. </mtd>
  208. <mtd>
  209. <mn>0</mn>
  210. </mtd>
  211. </mtr>
  212. <mtr>
  213. <mtd><mn>0</mn></mtd>
  214. <mtd><mn>0</mn></mtd>
  215. <mtd><mn>1</mn></mtd>
  216. </mtr>
  217. </mtable>
  218. <mo>]</mo>
  219. </mrow>
  220. </math>
  221. <h3>[method:this makeScale]( [param:Float x], [param:Float y] )</h3>
  222. <p>
  223. [page:Float x] - the amount to scale in the X axis.<br />
  224. [page:Float y] - the amount to scale in the Y axis.<br />
  225. Sets this matrix as a 2D scale transform:<br /><br />
  226. <math>
  227. <mrow>
  228. <mo>[</mo>
  229. <mtable>
  230. <mtr>
  231. <mtd><mi>x</mi></mtd>
  232. <mtd><mn>0</mn></mtd>
  233. <mtd><mn>0</mn></mtd>
  234. </mtr>
  235. <mtr>
  236. <mtd><mn>0</mn></mtd>
  237. <mtd><mi>y</mi></mtd>
  238. <mtd><mn>0</mn></mtd>
  239. </mtr>
  240. <mtr>
  241. <mtd><mn>0</mn></mtd>
  242. <mtd><mn>0</mn></mtd>
  243. <mtd><mn>1</mn></mtd>
  244. </mtr>
  245. </mtable>
  246. <mo>]</mo>
  247. </mrow>
  248. </math>
  249. </p>
  250. <h3>[method:this makeTranslation]( [param:Vector2 v] )</h3>
  251. <h3>[method:this makeTranslation]( [param:Float x], [param:Float y] )</h3>
  252. <p>
  253. [page:Vector2 v] a translation transform from vector.<br />
  254. or<br />
  255. [page:Float x] - the amount to translate in the X axis.<br />
  256. [page:Float y] - the amount to translate in the Y axis.<br />
  257. Sets this matrix as a 2D translation transform:
  258. </p>
  259. <math display="block">
  260. <mrow>
  261. <mo>[</mo>
  262. <mtable>
  263. <mtr>
  264. <mtd><mn>1</mn></mtd>
  265. <mtd><mn>0</mn></mtd>
  266. <mtd><mi>x</mi></mtd>
  267. </mtr>
  268. <mtr>
  269. <mtd><mn>0</mn></mtd>
  270. <mtd><mn>1</mn></mtd>
  271. <mtd><mi>y</mi></mtd>
  272. </mtr>
  273. <mtr>
  274. <mtd><mn>0</mn></mtd>
  275. <mtd><mn>0</mn></mtd>
  276. <mtd><mn>1</mn></mtd>
  277. </mtr>
  278. </mtable>
  279. <mo>]</mo>
  280. </mrow>
  281. </math>
  282. <h3>[method:this multiply]( [param:Matrix3 m] )</h3>
  283. <p>将当前矩阵乘以矩阵[page:Matrix3 m]。</p>
  284. <h3>[method:this multiplyMatrices]( [param:Matrix3 a], [param:Matrix3 b] )</h3>
  285. <p>设置当前矩阵为矩阵[page:Matrix3 a] x 矩阵[page:Matrix3 b]。</p>
  286. <h3>[method:this multiplyScalar]( [param:Float s] )</h3>
  287. <p>当前矩阵所有的元素乘以该缩放值*s*</p>
  288. <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>
  289. <p>
  290. 使用行优先 [link:https://en.wikipedia.org/wiki/Row-_and_column-major_order row-major] 的格式来设置该矩阵:
  291. </p>
  292. <math display="block">
  293. <mrow>
  294. <mo>[</mo>
  295. <mtable>
  296. <mtr>
  297. <mtd><mi>n11</mi></mtd>
  298. <mtd><mi>n12</mi></mtd>
  299. <mtd><mi>n13</mi></mtd>
  300. </mtr>
  301. <mtr>
  302. <mtd><mi>n21</mi></mtd>
  303. <mtd><mi>n22</mi></mtd>
  304. <mtd><mi>n23</mi></mtd>
  305. </mtr>
  306. <mtr>
  307. <mtd><mi>n31</mi></mtd>
  308. <mtd><mi>n32</mi></mtd>
  309. <mtd><mi>n33</mi></mtd>
  310. </mtr>
  311. </mtable>
  312. <mo>]</mo>
  313. </mrow>
  314. </math>
  315. <h3>[method:this premultiply]( [param:Matrix3 m] )</h3>
  316. <p>将矩阵[page:Matrix3 m]乘以当前矩阵。</p>
  317. <h3>[method:this setFromMatrix4]( [param:Matrix4 m] )</h3>
  318. <p>根据参数 [page:Matrix4 m] 左上 3x3 的矩阵值,设置当前矩阵的值。</p>
  319. <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>
  320. <p>
  321. [page:Float tx] - x偏移量<br />
  322. [page:Float ty] - y偏移量<br />
  323. [page:Float sx] - x方向的重复比例<br />
  324. [page:Float sy] - y方向的重复比例<br />
  325. [page:Float rotation] - 旋转, 弧度。Positive values rotate counterclockwise<br />
  326. [page:Float cx] - 旋转中心x<br />
  327. [page:Float cy] - 旋转中心y<br /><br />
  328. 使用偏移,重复,旋转和中心点位置设置UV变换矩阵。
  329. </p>
  330. <h3>[method:Array toArray]( [param:Array array], [param:Integer offset] )</h3>
  331. <p>
  332. [page:Array array] - (可选参数) 存储矩阵元素的数组,如果未指定会创建一个新的数组。<br />
  333. [page:Integer offset] - (可选参数) 存放矩阵元素数组的偏移量。<br /><br />
  334. 使用列优先[link:https://en.wikipedia.org/wiki/Row-_and_column-major_order#Column-major_order column-major]格式将此矩阵的元素写入数组中。
  335. </p>
  336. <h3>[method:this transpose]()</h3>
  337. <p>将该矩阵转置[link:https://en.wikipedia.org/wiki/Transpose Transposes]。</p>
  338. <h3>[method:this transposeIntoArray]( [param:Array array] )</h3>
  339. <p>
  340. [page:Array array] - 用于存储当前矩阵转置结果的数组。<br /><br />
  341. 将当前矩阵的转置[link:https://en.wikipedia.org/wiki/Transpose Transposes]存入给定的数组 array 中,但不改变当前矩阵,
  342. 并返回当前矩阵。
  343. </p>
  344. <h2>源码(Source)</h2>
  345. <p>
  346. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  347. </p>
  348. </body>
  349. </html>