math_cheet_sheet.adoc 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. = Math Cheat Sheet
  2. :revnumber: 2.0
  3. :revdate: 2020/07/13
  4. == Formulas
  5. [NOTE]
  6. ====
  7. Typically you have to string these formulas together. Look in the table for what you want, and what you have. If the two are not the same line, than you need conversion steps inbetween. E.g. if you have an angle in degrees, but the formula expects radians: 1) convert degrees to radians, 2) use the radians formula on the result.
  8. ====
  9. [cols="3", options="header"]
  10. |===
  11. a|I have…
  12. a|I want…
  13. a|Formula
  14. a|normalized direction and length +
  15. n1,d1
  16. a|a vector that goes that far in that direction +
  17. new direction vector v0
  18. a|v0 = n1.mult(d1)
  19. a|point and direction vector +
  20. p1,v1
  21. a|to move the point +
  22. new point p0
  23. a|p0 = p1.add(v1)
  24. a| direction, position and distance +
  25. v1,p1,dist
  26. a|Position at distance +
  27. p2
  28. a|v1.normalizeLocal() +
  29. scaledDir = v1.mult(dist) +
  30. p2 = p1.add(scaledDir)
  31. a|two direction vectors or normals +
  32. v1,v2
  33. a|to combine both directions +
  34. new direction vector v0
  35. a|v0 = v1.add(v2)
  36. a|two points +
  37. p1, p2
  38. a|distance between two points +
  39. new scalar d0
  40. a|d0 = p1.subtract(p2).length() +
  41. d0 = p1.distance(p2)
  42. a|two points +
  43. p1, p2
  44. a|the direction from p2 to p1 +
  45. new direction vector v0
  46. a|v0 = p1.subtract(p2)
  47. a|two points, a fraction +
  48. p1, p2, h=0.5f
  49. a|the point "`halfway`" (h=0.5f) between the two points +
  50. new interpolated point p0
  51. a|p0 = FastMath.interpolateLinear(h,p1,p2)
  52. a|a direction vector, an up vector +
  53. v, up
  54. a|A rotation around this up axis towards this direction +
  55. new Quaternion q
  56. a|Quaternion q = new Quaternion(); +
  57. q.lookAt(v,up)
  58. |===
  59. [cols="3", options="header"]
  60. |===
  61. a|I have…
  62. a|I want…
  63. a|Formula
  64. a|angle in degrees +
  65. a
  66. a| to convert angle a from degrees to radians +
  67. new float angle phi
  68. a|phi = a / 180 * FastMath.PI; +
  69. OR +
  70. phi=a.mult(FastMath.DEG_TO_RAD);
  71. a|angle in radians +
  72. phi
  73. a| to convert angle phi from radians to degrees +
  74. new float angle a
  75. a|a = phi * 180 / FastMath.PI
  76. a|radian angle and x axis +
  77. phi, x
  78. a|to rotate around x axis +
  79. new quaternion q0
  80. a|q0.fromAngleAxis( phi, Vector3f.UNIT_X )
  81. a|radian angle and y axis +
  82. phi, y
  83. a|to rotate around y axis +
  84. new quaternion q0
  85. a|q0.fromAngleAxis( phi, Vector3f.UNIT_Y )
  86. a|radian angle and z axis +
  87. phi, z
  88. a|to rotate around z axis +
  89. new quaternion q0
  90. a|q0.fromAngleAxis( phi, Vector3f.UNIT_Z )
  91. a|several quaternions +
  92. q1, q2, q3
  93. a|to combine rotations, in that order +
  94. new quaternion q0
  95. a|q0 = q1.mult(q2).mult(q3)
  96. a|point and quaternion +
  97. p1, q1
  98. a|to rotate the point around origin +
  99. new point p0
  100. a|p0 = q1.mult(p1)
  101. a|angle in radians and radius +
  102. phi,r
  103. a|to arrange or move objects horizontally in a circle (with y=0) +
  104. x and z coordinates
  105. a|float x = FastMath.cos(phi)*r; +
  106. float z = FastMath.sin(phi)*r;
  107. |===
  108. == Local vs Non-local methods?
  109. * Non-local method creates new object as return value, v remains unchanged. +
  110. `v2 = v.mult(); v2 = v.add(); v2 = v.subtract();` etc
  111. * Local method changes v directly! +
  112. `v.multLocal(); v.addLocal(); v.subtractLocal();` etc