From a237e771d148ea8b05f66557ad632361551f0c48 Mon Sep 17 00:00:00 2001 From: Daniel Peterson Date: Thu, 19 Dec 2019 17:28:29 -0800 Subject: [PATCH 1/4] Quaternion: euler angles fixed When experimenting with different math, had combined two equations. Now fixed to be exactly from https://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles --- classes/various/Quaternion.sc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/classes/various/Quaternion.sc b/classes/various/Quaternion.sc index ed0d3d8..f2005b3 100644 --- a/classes/various/Quaternion.sc +++ b/classes/various/Quaternion.sc @@ -113,17 +113,17 @@ Quaternion { // roll tilt { - ^atan2((2 * (a * b - (c * d))), (1 - (2*(b.squared + c.squared)))) + ^atan2((2 * (a * b + (c * d))), (1 - (2 * (b.squared + c.squared)))) } // pitch tumble { - ^asin((2 * (a * c + (b * d))).clip(-1.0, 1.0)); + ^asin((2 * (a * c - (b * d))).clip(-1.0, 1.0)); } // yaw rotate { - ^atan2((2 * (a * d - (c * b))), (1 - (2*(d.squared + c.squared)))) + ^atan2((2 * (a * d + (c * b))), (1 - (2 * (d.squared + c.squared)))) } } From 2bc338d4ad9c591bd4fe5dcf617686a6726faf08 Mon Sep 17 00:00:00 2001 From: Daniel Peterson Date: Thu, 19 Dec 2019 17:35:10 -0800 Subject: [PATCH 2/4] Quaternion: add Euler angle methods to help file --- HelpSource/Classes/Quaternion.schelp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/HelpSource/Classes/Quaternion.schelp b/HelpSource/Classes/Quaternion.schelp index 349e046..d631f2b 100644 --- a/HelpSource/Classes/Quaternion.schelp +++ b/HelpSource/Classes/Quaternion.schelp @@ -73,6 +73,16 @@ METHOD:: distance Return the distance between two quaternions. +METHOD:: rotate +Return the rotation (yaw) Euler angle in radians. Returns values between -pi and pi (-180 and 180 degrees). + + +METHOD:: tilt +Return the tilt (roll) Euler angle in radians. Returns values between -pi and pi (-180 and 180 degrees). + + +METHOD:: tumble +Return the tumble (pitch) Euler angle in radians. Returns values between -0.5pi and 0.5pi (-90 and 90 degrees). EXAMPLES:: From 8c6747c4dec106ade47cdf326b2952dc8679f7ff Mon Sep 17 00:00:00 2001 From: Daniel Peterson Date: Tue, 21 Jan 2020 17:00:15 -0800 Subject: [PATCH 3/4] Quaternion: naming convention updates --- HelpSource/Classes/Quaternion.schelp | 24 ++++++++++++++++++------ classes/various/Quaternion.sc | 23 +++++++++++++++++------ 2 files changed, 35 insertions(+), 12 deletions(-) diff --git a/HelpSource/Classes/Quaternion.schelp b/HelpSource/Classes/Quaternion.schelp index d631f2b..19c96be 100644 --- a/HelpSource/Classes/Quaternion.schelp +++ b/HelpSource/Classes/Quaternion.schelp @@ -73,16 +73,28 @@ METHOD:: distance Return the distance between two quaternions. -METHOD:: rotate -Return the rotation (yaw) Euler angle in radians. Returns values between -pi and pi (-180 and 180 degrees). +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:: tilt -Return the tilt (roll) 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:: tumble -Return the tumble (pitch) Euler angle in radians. Returns values between -0.5pi and 0.5pi (-90 and 90 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 f2005b3..034c33f 100644 --- a/classes/various/Quaternion.sc +++ b/classes/various/Quaternion.sc @@ -111,20 +111,31 @@ 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 - tilt { + + roll { ^atan2((2 * (a * b + (c * d))), (1 - (2 * (b.squared + c.squared)))) } - // pitch - tumble { + pitch { ^asin((2 * (a * c - (b * d))).clip(-1.0, 1.0)); } - // yaw - rotate { + yaw { ^atan2((2 * (a * d + (c * b))), (1 - (2 * (d.squared + c.squared)))) } + + // for convenience with the naming convention + tilt { + ^this.roll + } + + tumble { + ^this.pitch + } + + rotate { + ^this.yaw + } } + SimpleNumber { From 717caab7ba7c1baa20d1e7ac72404de23a1cd285 Mon Sep 17 00:00:00 2001 From: Daniel Peterson Date: Wed, 22 Jan 2020 10:12:02 -0800 Subject: [PATCH 4/4] Quaternion: schelp fixes --- HelpSource/Classes/Quaternion.schelp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/HelpSource/Classes/Quaternion.schelp b/HelpSource/Classes/Quaternion.schelp index 19c96be..7933880 100644 --- a/HelpSource/Classes/Quaternion.schelp +++ b/HelpSource/Classes/Quaternion.schelp @@ -85,16 +85,16 @@ 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 +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:: 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:. +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::