math_cheet_sheet.adoc 3.0 KB

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