diff --git a/HelpSource/Classes/Quaternion.schelp b/HelpSource/Classes/Quaternion.schelp index 349e046..7933880 100644 --- a/HelpSource/Classes/Quaternion.schelp +++ b/HelpSource/Classes/Quaternion.schelp @@ -73,6 +73,28 @@ METHOD:: distance Return the distance between two quaternions. +METHOD:: yaw +Return the yaw (rotation about the z-axis) Euler angle in radians. Returns values between -pi and pi (-180 and 180 degrees). + + +METHOD:: roll +Return the roll (rotation about the x-axis) Euler angle in radians. Returns values between -pi and pi (-180 and 180 degrees). + + +METHOD:: pitch +Return the pitch (rotation about the y-axis) Euler angle in radians. Returns values between -0.5pi and 0.5pi (-90 and 90 degrees). + + +METHOD:: rotate +Return the rotate (rotation about the z-axis) Euler angle in radians. Returns values between -pi and pi (-180 and 180 degrees). Equivalent to link::#-yaw::. + + +METHOD:: tilt +Return the tilt (rotation about the x-axis) Euler angle in radians. Returns values between -pi and pi (-180 and 180 degrees). Equivalent to link::#-roll::. + + +METHOD:: tumble +Return the tumble (rotation about the y-axis) Euler angle in radians. Returns values between -0.5pi and 0.5pi (-90 and 90 degrees). Equivalent to link::#-pitch::. EXAMPLES:: diff --git a/classes/various/Quaternion.sc b/classes/various/Quaternion.sc index ed0d3d8..034c33f 100644 --- a/classes/various/Quaternion.sc +++ b/classes/various/Quaternion.sc @@ -111,19 +111,30 @@ Quaternion { // conversion to euler angles // Math taken from https://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles#Quaternion_to_Euler_Angles_Conversion - // roll + + roll { + ^atan2((2 * (a * b + (c * d))), (1 - (2 * (b.squared + c.squared)))) + } + + pitch { + ^asin((2 * (a * c - (b * d))).clip(-1.0, 1.0)); + } + + yaw { + ^atan2((2 * (a * d + (c * b))), (1 - (2 * (d.squared + c.squared)))) + } + + // for convenience with the naming convention tilt { - ^atan2((2 * (a * b - (c * d))), (1 - (2*(b.squared + c.squared)))) + ^this.roll } - // pitch tumble { - ^asin((2 * (a * c + (b * d))).clip(-1.0, 1.0)); + ^this.pitch } - // yaw rotate { - ^atan2((2 * (a * d - (c * b))), (1 - (2*(d.squared + c.squared)))) + ^this.yaw } }