Open GoogleCodeExporter opened 9 years ago
The error seems to have been introduced in revision 26. Revision 25 works fine
on this example but revision 26 fails.
Original comment by chris.fl...@gmail.com
on 19 Dec 2011 at 9:21
Here is the diff between -r25 and -r26:
@@ -1287,6 +1346,12 @@
Q = cls()
costheta = q1.w * q2.w + q1.x * q2.x + q1.y * q2.y + q1.z * q2.z
+ if costheta < 0.:
+ costheta = -costheta
+ q1 = q1.conjugated()
+ elif costheta > 1:
+ costheta = 1
+
theta = math.acos(costheta)
if abs(theta) < 0.01:
Q.w = q2.w
It just seems like reverting the new_interpolate function back to -r25 would
fix things. I'm not sure why the following lines are necessary (assuming both
quaternions are normalized):
+ elif costheta > 1:
+ costheta = 1
I guess in case of rounding errors?
Original comment by chris.fl...@gmail.com
on 19 Dec 2011 at 9:32
Probably related to bug #16
Original comment by rodrigo....@gmail.com
on 6 Aug 2014 at 9:45
I ended up making some other mods to this function, here is currently working
for me. I needed to have very precise interpolation for my application, the
existing code will skip interpolation altogether if the quaternion angle
difference is lower than an arbitrary threshold.
def new_interpolate(cls, q1, q2, t):
assert isinstance(q1, Quaternion) and isinstance(q2, Quaternion)
Q = cls()
costheta = q1.w * q2.w + q1.x * q2.x + q1.y * q2.y + q1.z * q2.z
if costheta < 0.:
costheta = -costheta
q1 = q1.conjugated()
elif costheta > 1:
costheta = 1
elif costheta == 1.0:
Q.w = q1.w
Q.x = q1.x
Q.y = q1.y
Q.z = q1.z
return Q
theta = math.acos(costheta)
sintheta = math.sqrt(1.0 - costheta * costheta)
try:
ratio1 = math.sin((1 - t) * theta) / sintheta
except ZeroDivisionError:
Q.w = q1.w
Q.x = q1.x
Q.y = q1.y
Q.z = q1.z
return Q
ratio2 = math.sin(t * theta) / sintheta
Q.w = q1.w * ratio1 + q2.w * ratio2
Q.x = q1.x * ratio1 + q2.x * ratio2
Q.y = q1.y * ratio1 + q2.y * ratio2
Q.z = q1.z * ratio1 + q2.z * ratio2
return Q
new_interpolate = classmethod(new_interpolate)
Original comment by chris.fl...@gmail.com
on 6 Aug 2014 at 10:33
Original issue reported on code.google.com by
chris.fl...@gmail.com
on 19 Dec 2011 at 9:10