Skip to content

Commit

Permalink
Merge pull request #13 from ami-iit/fix-slerp-step
Browse files Browse the repository at this point in the history
[SLERP] Return the first quaternion when the two quaternion are equal
  • Loading branch information
Giulero authored Nov 29, 2023
2 parents ea55d1f + 2ac00cd commit 234f242
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/liecasadi/quaternion.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ def slerp_step(q1: Vector, q2: Vector, t: Scalar) -> Vector:

dot = cs.dot(q1, q2)
angle = cs.acos(dot)
# if the angle is small (meaning the quaternions are "equal") we return the first quaternion
return Quaternion(
(cs.sin((1.0 - t) * angle) * q1 + cs.sin(t * angle) * q2) / cs.sin(angle)
cs.if_else(
angle < 1e-6,
q1,
(cs.sin((1.0 - t) * angle) * q1 + cs.sin(t * angle) * q2)
/ cs.sin(angle),
)
)

0 comments on commit 234f242

Please sign in to comment.