Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Interpolating rotations(slerp) using Eigen

I am trying to slerp between 2 quaternions using Eigen(thought would be the easiest).

I found two different examples

One,

for(int i = 0; i < list.size(); i++)
{
  Matrix3f m;
  Quaternion<float,0> q1 = m.toRotationMatrix();

  Quaternion<float,0> q3(q1.slerp(1,q2));
  m_node->Rotation(q3.toRotationMatrix());
}

Second,

Vec3 slerp(const Vec3& a, const Vec3& b, const Real& t)
{
 Quaternionf qa;
 Quaternionf qb;
 qa = Quaternionf::Identity();
 qb.setFromTwoVectors(a,b); 
  return (qa.slerp(t,qb)) * a; 
 }

I cant really say which one is correct. There is not many documentation about this. Can anyone tell me if I should use a different library? or how can I slerp using eigen.

like image 279
james456 Avatar asked Dec 12 '22 10:12

james456


2 Answers

Doing a SLERP between two quaternions is just a matter of calling the slerp method:

Quaterniond qa, qb, qres;
// initialize qa, qb;
qres = qa.slerp(t, qb);

where t is your interpolation parameter.

like image 195
ggael Avatar answered Dec 17 '22 17:12

ggael


Use the second variant.

Both code snippets implement a SLERP, however the first one does something with elements in a list, which your snippet doesn't show. Also the second variant is the computationally more efficient one, as it doesn't take a detour over a rotation matrix.

like image 31
datenwolf Avatar answered Dec 17 '22 16:12

datenwolf