quat.js
function fromEuler (q, euler) {
  var x = euler[0]
  var y = euler[1]
  var z = euler[2]
  var cx = Math.cos(x / 2)
  var cy = Math.cos(y / 2)
  var cz = Math.cos(z / 2)
  var sx = Math.sin(x / 2)
  var sy = Math.sin(y / 2)
  var sz = Math.sin(z / 2)

  q[0] = sx * cy * cz + cx * sy * sz
  q[1] = cx * sy * cz - sx * cy * sz
  q[2] = cx * cy * sz + sx * sy * cz
  q[3] = cx * cy * cz - sx * sy * sz

  return q
}
function fromEuler (q, euler) {
  var x = euler[0]
  var y = euler[1]
  var z = euler[2]
  var cx = Math.cos(x / 2)
  var cy = Math.cos(y / 2)
  var cz = Math.cos(z / 2)
  var sx = Math.sin(x / 2)
  var sy = Math.sin(y / 2)
  var sz = Math.sin(z / 2)

  q[0] = sx * cy * cz + cx * sy * sz
  q[1] = cx * sy * cz - sx * cy * sz
  q[2] = cx * cy * sz + sx * sy * cz
  q[3] = cx * cy * cz - sx * sy * sz

  return q
}
function fromEuler ( q , euler ) { var x = euler [ 0 ] var y = euler [ 1 ] var z = euler [ 2 ] var cx = Math . cos ( x / 2 ) var cy = Math . cos ( y / 2 ) var cz = Math . cos ( z / 2 ) var sx = Math . sin ( x / 2 ) var sy = Math . sin ( y / 2 ) var sz = Math . sin ( z / 2 ) q [ 0 ] = sx * cy * cz + cx * sy * sz q [ 1 ] = cx * sy * cz - sx * cy * sz q [ 2 ] = cx * cy * sz + sx * sy * cz q [ 3 ] = cx * cy * cz - sx * sy * sz return q }
x = yaw, y = pitch, z = roll assumes XYZ order
x = yaw y = pitch z = roll assumes XYZ order