matrix.adoc 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. = Matrix
  2. :revnumber: 2.0
  3. :revdate: 2020/07/24
  4. == Matrix
  5. See link:{link-javadoc}/com/jme3/math/Matrix3f.html[Javadoc of Matrix3f] and link:{link-javadoc}/com/jme3/math/Matrix4f.html[Javadoc of Matrix4f]
  6. === Definition
  7. A Matrix is typically used as a _linear transformation_ to map vectors to vectors. That is: Y = MX where X is a Vector and M is a Matrix applying any or all transformations (scale, rotate, translate).
  8. There are a few special matrices:
  9. _zero matrix_ is the Matrix with all zero entries.
  10. [cols="3", options="header"]
  11. |===
  12. a|0
  13. a|0
  14. a|0
  15. a|0
  16. a|0
  17. a|0
  18. a|0
  19. a|0
  20. a|0
  21. |===
  22. The _Identity Matrix_ is the matrix with 1 on the diagonal entries and 0 for all other entries.
  23. [cols="3", options="header"]
  24. |===
  25. a|1
  26. a|0
  27. a|0
  28. a|0
  29. a|1
  30. a|0
  31. a|0
  32. a|0
  33. a|1
  34. |===
  35. A Matrix is _invertible_ if there is a matrix _M^-1^_ where _MM^-1^ = M^-1^ = I_.
  36. The _transpose_ of a matrix _M = [m~ij~]_ is _M^T^ = [m~ji~]_. This causes the rows of _M_ to become the columns of _M^T^_.
  37. [cols="7", options="header"]
  38. |===
  39. a|1
  40. a|1
  41. a|1
  42. <a|
  43. a|1
  44. a|2
  45. a|3
  46. a|2
  47. a|2
  48. a|2
  49. a| ⇒
  50. a|1
  51. a|2
  52. a|3
  53. a|3
  54. a|3
  55. a|3
  56. <a|
  57. a|1
  58. a|2
  59. a|3
  60. |===
  61. A Matrix is symmetric if _M_ = _M^T^_.
  62. [cols="3", options="header"]
  63. |===
  64. a|X
  65. a|A
  66. a|B
  67. a|A
  68. a|X
  69. a|C
  70. a|B
  71. a|C
  72. a|X
  73. |===
  74. Where X, A, B, and C equal numbers
  75. jME includes two types of Matrix classes: Matrix3f and Matrix4f. Matrix3f is a 3x3 matrix and is the most commonly used (able to handle scaling and rotating), while Matrix4f is a 4x4 matrix that can also handle translation.
  76. === Transformations
  77. Multiplying a <<tutorials:concepts/terminology.adoc#vectors,Vector>> with a Matrix allows the Vector to be transformed. Either rotating, scaling or translating that Vector.
  78. ==== Scaling
  79. If a _diagonal Matrix_, defined by D = [d~ij~] and d~ij~ = 0 for i != j, has all positive entries it is a _scaling matrix_. If d~i~ is greater than 1 then the resulting Vector will grow, while if d~i~ is less than 1 it will shrink.
  80. ==== Rotation
  81. A _rotation matrix_ requires that the transpose and inverse are the same matrix (R^-1^ = R^T^). The _rotation matrix_ R can then be calculated as: R = I + (sin(angle)) S + (1 - cos(angle)S^2^ where S is:
  82. [cols="3", options="header"]
  83. |===
  84. a|0
  85. a|u~2~
  86. a|-u~1~
  87. a|-u~2~
  88. a|0
  89. a|u~0~
  90. a|u~1~
  91. a|-u~0~
  92. a|0
  93. |===
  94. ==== Translation
  95. Translation requires a 4x4 matrix, where the Vector (x,y,z) is mapped to (x,y,z,1) for multiplication. The _Translation Matrix_ is then defined as:
  96. [cols="2", options="header"]
  97. |===
  98. a|M
  99. a|T
  100. a|S^T^
  101. a|1
  102. |===
  103. where M is the 3x3 matrix (containing any rotation/scale information), T is the translation Vector and S^T^ is the transpose Vector of T. 1 is just a constant.
  104. === jME Class
  105. Both Matrix3f and Matrix4f store their values as floats and are publicly available as (m00, m01, m02, …, mNN) where N is either 2 or 3.
  106. Most methods are straight forward, and I will leave documentation to the Javadoc.