Euler math functions ported from THREE.js