In general, the math for any transformation, or combination of transformations, looks like:
newx = A * oldx + B * oldy + C * oldz + D newy = E * oldx + F * oldy + G * oldz + H newz = I * oldx + J * oldy + K * oldz + L
This can be simplified by treating positions as 4-coordinate vectors, where the last coordinate (w) is usually 1.
The transformation is then a 4x4 matrix that is the vectors are multiplied by.
| x | | A B C D | | x | | y | = | E F G H | * | y | | z | | I J K L | | z | | w | | M N O P | | w |