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

p0 = p1.add(v1)

direction, position and distance
v1,p1,dist

Position at distance
p2

v1.normalzeLocal()
scaledDir = v1.mult(dist)
p2 = p1.add(scaledDir)

two direction vectors or normals
v1,v2

to combine both directions
new direction vector v0

v0 = v1.add(v2)

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=a.mult(FastMath.DEG_TO_RAD);

angle in radians
phi

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

a = phi * 180 / FastMath.PI

radian angle and x axis
phi, x

to rotate around x axis
new quaternion q0

q0.fromAngleAxis( phi, Vector3f.UNIT_X )

radian angle and y axis
phi, y

to rotate around y axis
new quaternion q0

q0.fromAngleAxis( phi, Vector3f.UNIT_Y )

radian angle and z axis
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)

angle in radians and radius
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!
    v.multLocal(); v.addLocal(); v.subtractLocal(); etc