Matrix3.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  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]顺序存储在 [page:.elements elements] 数组当中。<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. 根据给定的参数,按行优先顺序创建一个 3x3 矩阵。如果没有提供参数,构造函数会将 [name] 初始化为 3x3 单位矩阵([link:https://en.wikipedia.org/wiki/Identity_matrix identity matrix])。
  44. </p>
  45. <h2>属性(Properties)</h2>
  46. <h3>[property:Array elements]</h3>
  47. <p>
  48. 矩阵列优先[link:https://en.wikipedia.org/wiki/Row-_and_column-major_order column-major]列表。
  49. </p>
  50. <h2>方法(Methods)</h2>
  51. <h3>[method:Matrix3 clone]()</h3>
  52. <p>创建一个新的矩阵,元素 [page:.elements elements] 与该矩阵相同。</p>
  53. <h3>[method:this copy]( [param:Matrix3 m] )</h3>
  54. <p>将矩阵[page:Matrix3 m]的元素复制到当前矩阵中。</p>
  55. <h3>[method:Float determinant]()</h3>
  56. <p>
  57. 计算并返回矩阵的行列式[link:https://en.wikipedia.org/wiki/Determinant determinant] 。
  58. </p>
  59. <h3>[method:Boolean equals]( [param:Matrix3 m] )</h3>
  60. <p>如果矩阵[page:Matrix3 m] 与当前矩阵所有对应元素相同则返回true。</p>
  61. <h3>[method:this extractBasis]( [param:Vector3 xAxis], [param:Vector3 yAxis], [param:Vector3 zAxis] )</h3>
  62. <p>
  63. 将该矩阵的基向量 [link:https://en.wikipedia.org/wiki/Basis_(linear_algebra) basis] 提取到提供的三个轴向中。如果该矩阵如下:
  64. </p>
  65. <math display="block">
  66. <mrow>
  67. <mo>[</mo>
  68. <mtable>
  69. <mtr>
  70. <mtd><mi>a</mi></mtd>
  71. <mtd><mi>b</mi></mtd>
  72. <mtd><mi>c</mi></mtd>
  73. </mtr>
  74. <mtr>
  75. <mtd><mi>d</mi></mtd>
  76. <mtd><mi>e</mi></mtd>
  77. <mtd><mi>f</mi></mtd>
  78. </mtr>
  79. <mtr>
  80. <mtd><mi>g</mi></mtd>
  81. <mtd><mi>h</mi></mtd>
  82. <mtd><mi>i</mi></mtd>
  83. </mtr>
  84. </mtable>
  85. <mo>]</mo>
  86. </mrow>
  87. </math>
  88. <p>
  89. 那么 [page:Vector3 xAxis], [page:Vector3 yAxis], [page:Vector3 zAxis] 将会被设置为:
  90. </p>
  91. <div style="text-align: center">
  92. <math>
  93. <mrow>
  94. <mi>xAxis</mi>
  95. <mo>=</mo>
  96. <mo>[</mo>
  97. <mtable>
  98. <mtr><mtd style="height: 1rem"><mi>a</mi></mtd></mtr>
  99. <mtr><mtd style="height: 1rem"><mi>d</mi></mtd></mtr>
  100. <mtr><mtd style="height: 1rem"><mi>g</mi></mtd></mtr>
  101. </mtable>
  102. <mo>]</mo>
  103. </mrow>
  104. </math>,
  105. <math>
  106. <mrow>
  107. <mi>yAxis</mi>
  108. <mo>=</mo>
  109. <mo>[</mo>
  110. <mtable>
  111. <mtr><mtd style="height: 1rem"><mi>b</mi></mtd></mtr>
  112. <mtr><mtd style="height: 1rem"><mi>e</mi></mtd></mtr>
  113. <mtr><mtd style="height: 1rem"><mi>h</mi></mtd></mtr>
  114. </mtable>
  115. <mo>]</mo>
  116. </mrow>
  117. </math>, and
  118. <math>
  119. <mrow>
  120. <mi>zAxis</mi>
  121. <mo>=</mo>
  122. <mo>[</mo>
  123. <mtable>
  124. <mtr><mtd style="height: 1rem"><mi>c</mi></mtd></mtr>
  125. <mtr><mtd style="height: 1rem"><mi>f</mi></mtd></mtr>
  126. <mtr><mtd style="height: 1rem"><mi>i</mi></mtd></mtr>
  127. </mtable>
  128. <mo>]</mo>
  129. </mrow>
  130. </math>
  131. </div>
  132. <h3>[method:this fromArray]( [param:Array array], [param:Integer offset] )</h3>
  133. <p>
  134. [page:Array array] - 用来存储设置元素数据的数组<br />
  135. [page:Integer offset] - (可选参数) 数组的偏移量,默认值为 0。<br /><br />
  136. 使用基于列优先格式[link:https://en.wikipedia.org/wiki/Row-_and_column-major_order#Column-major_order column-major]的数组来设置该矩阵。
  137. </p>
  138. <h3>[method:this invert]()</h3>
  139. <p>
  140. 将当前矩阵翻转为它的逆矩阵,使用 [link:https://en.wikipedia.org/wiki/Invertible_matrix#Analytic_solution analytic method] 解析方式。你不能对行或列为 0 的矩阵进行翻转,如果你尝试这样做,该方法将生成一个零矩阵。
  141. </p>
  142. <h3>[method:this getNormalMatrix]( [param:Matrix4 m] )</h3>
  143. <p>
  144. [page:Matrix4 m] - [page:Matrix4]<br /><br />
  145. 将这个矩阵设置为给定矩阵的正规矩阵[link:https://en.wikipedia.org/wiki/Normal_matrix normal matrix](左上角的3x3)。
  146. 正规矩阵是矩阵[page:Matrix4 m]的逆矩阵[link:https://en.wikipedia.org/wiki/Invertible_matrix inverse] 的转置[link:https://en.wikipedia.org/wiki/Transpose transpose]。
  147. </p>
  148. <h3>[method:this identity]()</h3>
  149. <p>
  150. 将此矩阵重置为3x3单位矩阵:
  151. </p>
  152. <math display="block">
  153. <mrow>
  154. <mo>[</mo>
  155. <mtable>
  156. <mtr>
  157. <mtd><mn>1</mn></mtd>
  158. <mtd><mn>0</mn></mtd>
  159. <mtd><mn>0</mn></mtd>
  160. </mtr>
  161. <mtr>
  162. <mtd><mn>0</mn></mtd>
  163. <mtd><mn>1</mn></mtd>
  164. <mtd><mn>0</mn></mtd>
  165. </mtr>
  166. <mtr>
  167. <mtd><mn>0</mn></mtd>
  168. <mtd><mn>0</mn></mtd>
  169. <mtd><mn>1</mn></mtd>
  170. </mtr>
  171. </mtable>
  172. <mo>]</mo>
  173. </mrow>
  174. </math>
  175. <h3>[method:this makeRotation]( [param:Float theta] )</h3>
  176. <p>
  177. [page:Float theta] — 旋转角度(以弧度为单位)。正值表示逆时针旋转。<br /><br />
  178. 将此矩阵设置为以 [page:Float theta] 弧度为单位的二维旋转变换。
  179. 结果如下:
  180. </p>
  181. <math display="block">
  182. <mrow>
  183. <mo>[</mo>
  184. <mtable>
  185. <mtr>
  186. <mtd>
  187. <mi>cos</mi>
  188. <mi>&theta;</mi>
  189. </mtd>
  190. <mtd>
  191. <mi>-sin</mi>
  192. <mi>&theta;</mi>
  193. </mtd>
  194. <mtd>
  195. <mn>0</mn>
  196. </mtd>
  197. </mtr>
  198. <mtr>
  199. <mtd>
  200. <mi>sin</mi>
  201. <mi>&theta;</mi>
  202. </mtd>
  203. <mtd>
  204. <mi>cos</mi>
  205. <mi>&theta;</mi>
  206. </mtd>
  207. <mtd>
  208. <mn>0</mn>
  209. </mtd>
  210. </mtr>
  211. <mtr>
  212. <mtd><mn>0</mn></mtd>
  213. <mtd><mn>0</mn></mtd>
  214. <mtd><mn>1</mn></mtd>
  215. </mtr>
  216. </mtable>
  217. <mo>]</mo>
  218. </mrow>
  219. </math>
  220. <h3>[method:this makeScale]( [param:Float x], [param:Float y] )</h3>
  221. <p>
  222. [page:Float x] - 在X轴方向的缩放比。<br />
  223. [page:Float y] - 在Y轴方向的缩放比。<br /><br />
  224. 将这个矩阵设置为二维缩放变换。结果如下:<br /><br />
  225. </p>
  226. <math display="block">
  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. <h3>[method:this makeTranslation]( [param:Vector2 v] )</h3>
  250. <h3>[method:this makeTranslation]( [param:Float x], [param:Float y] )</h3>
  251. <p>
  252. [page:Vector2 v] 从向量进行平移变换。<br />
  253. 或<br />
  254. [page:Float x] - X 轴上的平移量。<br />
  255. [page:Float y] - Y 轴上的平移量。<br />
  256. 将此矩阵设置为二维平移变换。结果如下:
  257. </p>
  258. <math display="block">
  259. <mrow>
  260. <mo>[</mo>
  261. <mtable>
  262. <mtr>
  263. <mtd><mn>1</mn></mtd>
  264. <mtd><mn>0</mn></mtd>
  265. <mtd><mi>x</mi></mtd>
  266. </mtr>
  267. <mtr>
  268. <mtd><mn>0</mn></mtd>
  269. <mtd><mn>1</mn></mtd>
  270. <mtd><mi>y</mi></mtd>
  271. </mtr>
  272. <mtr>
  273. <mtd><mn>0</mn></mtd>
  274. <mtd><mn>0</mn></mtd>
  275. <mtd><mn>1</mn></mtd>
  276. </mtr>
  277. </mtable>
  278. <mo>]</mo>
  279. </mrow>
  280. </math>
  281. <h3>[method:this multiply]( [param:Matrix3 m] )</h3>
  282. <p>将当前矩阵乘以矩阵[page:Matrix3 m]。</p>
  283. <h3>[method:this multiplyMatrices]( [param:Matrix3 a], [param:Matrix3 b] )</h3>
  284. <p>设置当前矩阵为矩阵[page:Matrix3 a] x 矩阵[page:Matrix3 b]。</p>
  285. <h3>[method:this multiplyScalar]( [param:Float s] )</h3>
  286. <p>当前矩阵所有的元素乘以该缩放值*s*</p>
  287. <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>
  288. <p>
  289. 使用行优先 [link:https://en.wikipedia.org/wiki/Row-_and_column-major_order row-major] 的格式来设置该矩阵:
  290. </p>
  291. <math display="block">
  292. <mrow>
  293. <mo>[</mo>
  294. <mtable>
  295. <mtr>
  296. <mtd><mi>n11</mi></mtd>
  297. <mtd><mi>n12</mi></mtd>
  298. <mtd><mi>n13</mi></mtd>
  299. </mtr>
  300. <mtr>
  301. <mtd><mi>n21</mi></mtd>
  302. <mtd><mi>n22</mi></mtd>
  303. <mtd><mi>n23</mi></mtd>
  304. </mtr>
  305. <mtr>
  306. <mtd><mi>n31</mi></mtd>
  307. <mtd><mi>n32</mi></mtd>
  308. <mtd><mi>n33</mi></mtd>
  309. </mtr>
  310. </mtable>
  311. <mo>]</mo>
  312. </mrow>
  313. </math>
  314. <h3>[method:this premultiply]( [param:Matrix3 m] )</h3>
  315. <p>将矩阵[page:Matrix3 m]乘以当前矩阵。</p>
  316. <h3>[method:this setFromMatrix4]( [param:Matrix4 m] )</h3>
  317. <p>根据参数 [page:Matrix4 m] 左上 3x3 的矩阵值,设置当前矩阵的值。</p>
  318. <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>
  319. <p>
  320. [page:Float tx] - x偏移量<br />
  321. [page:Float ty] - y偏移量<br />
  322. [page:Float sx] - x方向的重复比例<br />
  323. [page:Float sy] - y方向的重复比例<br />
  324. [page:Float rotation] - 旋转, 弧度。正值表示逆时针旋转。<br />
  325. [page:Float cx] - 旋转中心x<br />
  326. [page:Float cy] - 旋转中心y<br /><br />
  327. 使用偏移,重复,旋转和中心点位置设置UV变换矩阵。
  328. </p>
  329. <h3>[method:Array toArray]( [param:Array array], [param:Integer offset] )</h3>
  330. <p>
  331. [page:Array array] - (可选参数) 存储矩阵元素的数组,如果未指定会创建一个新的数组。<br />
  332. [page:Integer offset] - (可选参数) 存放矩阵元素数组的偏移量。<br /><br />
  333. 使用列优先[link:https://en.wikipedia.org/wiki/Row-_and_column-major_order#Column-major_order column-major]格式将此矩阵的元素写入数组中。
  334. </p>
  335. <h3>[method:this translate]( [param:Float tx], [param:Float ty] )</h3>
  336. <p>通过给定的参数,在当前矩阵的基础上叠加一个平移变换。</p>
  337. <h3>[method:this transpose]()</h3>
  338. <p>将该矩阵转置[link:https://en.wikipedia.org/wiki/Transpose Transposes]。</p>
  339. <h3>[method:this transposeIntoArray]( [param:Array array] )</h3>
  340. <p>
  341. [page:Array array] - 用于存储当前矩阵转置结果的数组。<br /><br />
  342. 将当前矩阵的转置[link:https://en.wikipedia.org/wiki/Transpose Transposes]存入给定的数组 array 中,但不改变当前矩阵,
  343. 并返回当前矩阵。
  344. </p>
  345. <h2>源码(Source)</h2>
  346. <p>
  347. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  348. </p>
  349. </body>
  350. </html>
粤ICP备19079148号