Add explanation of how the rotation decomposition is derived

Also fix an issue: rotate[2] can in fact be chosen arbitrarily when
cos(rotate[1]) == 0, so set it at 0 in that case. Still keep the more
robust formulas for rotate[0].