matrix.adoc 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. = Matrix
  2. :author:
  3. :revnumber:
  4. :revdate: 2020/07/15
  5. == Matrix
  6. See link:{link-javadoc}/com/jme3/math/Matrix3f.html[Javadoc of Matrix3f] and link:{link-javadoc}/com/jme3/math/Matrix4f.html[Javadoc of Matrix4f]
  7. === Definition
  8. 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).
  9. There are a few special matrices:
  10. _zero matrix_ is the Matrix with all zero entries.
  11. [cols="3", options="header"]
  12. |===
  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. a|0
  22. |===
  23. The _Identity Matrix_ is the matrix with 1 on the diagonal entries and 0 for all other entries.
  24. [cols="3", options="header"]
  25. |===
  26. a|1
  27. a|0
  28. a|0
  29. a|0
  30. a|1
  31. a|0
  32. a|0
  33. a|0
  34. a|1
  35. |===
  36. A Matrix is _invertible_ if there is a matrix _M^-1^_ where _MM^-1^ = M^-1^ = I_.
  37. 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^_.
  38. [cols="7", options="header"]
  39. |===
  40. a|1
  41. a|1
  42. a|1
  43. <a|
  44. a|1
  45. a|2
  46. a|3
  47. a|2
  48. a|2
  49. a|2
  50. a| ⇒
  51. a|1
  52. a|2
  53. a|3
  54. a|3
  55. a|3
  56. a|3
  57. <a|
  58. a|1
  59. a|2
  60. a|3
  61. |===
  62. A Matrix is symmetric if _M_ = _M^T^_.
  63. [cols="3", options="header"]
  64. |===
  65. a|X
  66. a|A
  67. a|B
  68. a|A
  69. a|X
  70. a|C
  71. a|B
  72. a|C
  73. a|X
  74. |===
  75. Where X, A, B, and C equal numbers
  76. 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.
  77. === Transformations
  78. Multiplying a xref:tutorials:intermediate/terminology.adoc#vectors[Vector] with a Matrix allows the Vector to be transformed. Either rotating, scaling or translating that Vector.
  79. ==== Scaling
  80. 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.
  81. ==== Rotation
  82. 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:
  83. [cols="3", options="header"]
  84. |===
  85. a|0
  86. a|u~2~
  87. a|-u~1~
  88. a|-u~2~
  89. a|0
  90. a|u~0~
  91. a|u~1~
  92. a|-u~0~
  93. a|0
  94. |===
  95. ==== Translation
  96. 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:
  97. [cols="2", options="header"]
  98. |===
  99. a|M
  100. a|T
  101. a|S^T^
  102. a|1
  103. |===
  104. 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.
  105. === jME Class
  106. 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.
  107. Most methods are straight forward, and I will leave documentation to the Javadoc.