Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions HelpSource/Classes/Quaternion.schelp
Original file line number Diff line number Diff line change
Expand Up @@ -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::
Expand Down
23 changes: 17 additions & 6 deletions classes/various/Quaternion.sc
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down