Q_Slerp() cleanup.

This commit is contained in:
Revar Desmera 2020-02-14 23:06:01 -08:00
parent fe5d7baa0b
commit 393f9e2639
2 changed files with 12 additions and 8 deletions

View file

@ -190,13 +190,17 @@ function Q_Dist(q1, q2) = norm(q2-q1);
// color("red",0.25) Qrot(b) cylinder(d=1, h=80); // color("red",0.25) Qrot(b) cylinder(d=1, h=80);
// Qrot(Q_Slerp(a, b, 0.6)) cylinder(d=1, h=80); // Qrot(Q_Slerp(a, b, 0.6)) cylinder(d=1, h=80);
function Q_Slerp(q1, q2, u) = let( function Q_Slerp(q1, q2, u) = let(
dot = Q_Dot(q1, q2), q1 = Q_Normalize(q1),
qq2 = dot<0? Q_Neg(q2) : q2, q2 = Q_Normalize(q2),
dott = dot<0? -dot : dot, dot = Q_Dot(q1, q2)
theta = u * acos(constrain(dott,-1,1)) ) (dot>0.9995)? Q_Normalize(q1 + (u * (q2-q1))) :
) (dott>0.9995)? let(
Q_Normalize(q1 + ((qq2-q1) * u)) : dot = constrain(dot,-1,1),
(q1*cos(theta) + (Q_Normalize(qq2 - (q1 * dott)) * sin(theta))); 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() // Function: Q_Matrix3()

View file

@ -8,7 +8,7 @@
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
BOSL_VERSION = [2,0,126]; BOSL_VERSION = [2,0,127];
// Section: BOSL Library Version Functions // Section: BOSL Library Version Functions