Math Cheat Sheet

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
n1,d1

a vector that goes that far in that direction
new direction vector v0

v0 = n1.mult(d1)

point and direction vector
p1,v1

to move the point
new point p0

direction, position and distance
v1,p1,dist

Position at distance
p2

v1.normalzeLocal()
scaledDir = v1.mult(dist)

two direction vectors or normals
v1,v2

to combine both directions
new direction vector v0

two points
p1, p2

distance between two points
new scalar d0

d0 = p1.subtract(p2).length()
d0 = p1.distance(p2)

two points
p1, p2

the direction from p2 to p1
new direction vector v0

v0 = p1.substract(p2)

two points, a fraction
p1, p2, h=0.5f

the point “halfway” (h=0.5f) between the two points
new interpolated point p0

p0 = FastMath.interpolateLinear(h,p1,p2)

a direction vector, an up vector
v, up

A rotation around this up axis towards this direction
new Quaternion q

Quaternion q = new Quaternion();
q.lookAt(v,up)

I have… I want… Formula

angle in degrees
a

to convert angle a from degrees to radians
new float angle phi

phi = a / 180 * FastMath.PI;
OR

phi

to convert angle phi from radians to degrees
new float angle a

a = phi * 180 / FastMath.PI

phi, x

to rotate around x axis
new quaternion q0

q0.fromAngleAxis( phi, Vector3f.UNIT_X )

phi, y

to rotate around y axis
new quaternion q0

q0.fromAngleAxis( phi, Vector3f.UNIT_Y )

phi, z

to rotate around z axis
new quaternion q0

q0.fromAngleAxis( phi, Vector3f.UNIT_Z )

several quaternions
q1, q2, q3

to combine rotations, in that order
new quaternion q0

q0 = q1.mult(q2).mult(q3)

point and quaternion
p1, q1

to rotate the point around origin
new point p0

p0 = q1.mult(p1)

phi,r

to arrange or move objects horizontally in a circle (with y=0)
x and z coordinates

float x = FastMath.cos(phi)*r;
float z = FastMath.sin(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(); etc

• Local method changes v directly!