Skip to content

Instantly share code, notes, and snippets.

@larryhou
Created September 1, 2015 12:30
Show Gist options
  • Save larryhou/9dd0f29acfa0d4622c40 to your computer and use it in GitHub Desktop.
Save larryhou/9dd0f29acfa0d4622c40 to your computer and use it in GitHub Desktop.
func convertQuaternionToEuler(quat:CMQuaternion) -> (pitch:Double, roll:Double, yaw:Double)
{
let x = atan2(2 * (quat.w * quat.x + quat.y * quat.z), 1 - 2 * (quat.x * quat.x + quat.y * quat.y))
let y = asin(2 * (quat.w * quat.y - quat.z * quat.x))
let z = atan2(2 * (quat.w * quat.z + quat.x * quat.y), 1 - 2 * (quat.y * quat.y + quat.z * quat.z))
return (x, y, z)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment