From 393f9e263964f8c7e11f2f124c8168afad81b47a Mon Sep 17 00:00:00 2001 From: Revar Desmera Date: Fri, 14 Feb 2020 23:06:01 -0800 Subject: [PATCH] Q_Slerp() cleanup. --- quaternions.scad | 18 +++++++++++------- version.scad | 2 +- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/quaternions.scad b/quaternions.scad index a471903..3934880 100644 --- a/quaternions.scad +++ b/quaternions.scad @@ -190,13 +190,17 @@ function Q_Dist(q1, q2) = norm(q2-q1); // color("red",0.25) Qrot(b) cylinder(d=1, h=80); // Qrot(Q_Slerp(a, b, 0.6)) cylinder(d=1, h=80); function Q_Slerp(q1, q2, u) = let( - dot = Q_Dot(q1, q2), - qq2 = dot<0? Q_Neg(q2) : q2, - dott = dot<0? -dot : dot, - theta = u * acos(constrain(dott,-1,1)) - ) (dott>0.9995)? - Q_Normalize(q1 + ((qq2-q1) * u)) : - (q1*cos(theta) + (Q_Normalize(qq2 - (q1 * dott)) * sin(theta))); + q1 = Q_Normalize(q1), + q2 = Q_Normalize(q2), + dot = Q_Dot(q1, q2) + ) (dot>0.9995)? Q_Normalize(q1 + (u * (q2-q1))) : + let( + dot = constrain(dot,-1,1), + theta_0 = acos(dot), + theta = theta_0 * u, + q3 = Q_Normalize(q2 - q1*dot), + out = q1*cos(theta) + q3*sin(theta) + ) out; // Function: Q_Matrix3() diff --git a/version.scad b/version.scad index 58ca33e..98b9eda 100644 --- a/version.scad +++ b/version.scad @@ -8,7 +8,7 @@ ////////////////////////////////////////////////////////////////////// -BOSL_VERSION = [2,0,126]; +BOSL_VERSION = [2,0,127]; // Section: BOSL Library Version Functions