## Formulas

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. |

I have… | I want… | Formula |
---|---|---|

normalized direction and length | a vector that goes that far in that direction | v0 = n1.mult(d1) |

point and direction vector | to move the point | p0 = p1.add(v1) |

direction, position and distance | Position at distance | v1.normalzeLocal() |

two direction vectors or normals | to combine both directions | v0 = v1.add(v2) |

two points | distance between two points | d0 = p1.subtract(p2).length() |

two points | the direction from p2 to p1 | v0 = p1.substract(p2) |

two points, a fraction | the point “halfway (h=0.5f) between the two points | p0 = FastMath.interpolateLinear(h,p1,p2) |

a direction vector, an up vector | A rotation around this up axis towards this direction | Quaternion q = new Quaternion(); |

I have… | I want… | Formula |
---|---|---|

angle in degrees | to convert angle a from degrees to radians | phi = a / 180 * FastMath.PI; |

angle in radians | to convert angle phi from radians to degrees | a = phi * 180 / FastMath.PI |

radian angle and x axis | to rotate around x axis | q0.fromAngleAxis( phi, Vector3f.UNIT_X ) |

radian angle and y axis | to rotate around y axis | q0.fromAngleAxis( phi, Vector3f.UNIT_Y ) |

radian angle and z axis | to rotate around z axis | q0.fromAngleAxis( phi, Vector3f.UNIT_Z ) |

several quaternions | to combine rotations, in that order | q0 = q1.mult(q2).mult(q3) |

point and quaternion | to rotate the point around origin | p0 = q1.mult(p1) |

angle in radians and radius | to arrange or move objects horizontally in a circle (with y=0) | float x = FastMath.cos(phi)*r; |

## Local vs Non-local methods?

Non-local method creates new object as return value, v remains unchanged.

`v2 = v.mult(); v2 = v.add(); v2 = v.subtract();`

etcLocal method changes v directly!

`v.multLocal(); v.addLocal(); v.subtractLocal();`

etc