Hello everyone, I am trying to interpolate over a sequence of rotations represented by quaternions. I am currently employing Squad (Spherical and Quadrangle Interpolation). I successfully applied the function to 4 rotations and the results corresponded to the expected one.
RotationSequence( std::vector<Quaternion> rotations ) { if (rotations.size() < 4) throw std::runtime_error("Rotation sequence requires at least four rotations."); for (Quaternion rotation : rotations) this->rotations.push_back(rotation); /* Copy the last position to force the interpolation to behave correctly. */ this->rotations.push_back(rotations[rotations.size() - 1]); /* Preprocesses the sequence, selectively negating all quaternions. */ for (size_t ui = 1; ui < this->rotations.size(); ui++) if (this->rotations[ui].dot(this->rotations[ui - 1]) < 0.0) this->rotations[ui].negate(); /* Compute supports for the whole sequence, 0-th and n-th correspond to quaternions 0-th and n-th. */ supports.push_back(this->rotations[0]); for (size_t ui = 1; ui <= this->rotations.size()-2; ui++) supports.push_back( Support( this->rotations[ui - 1], this->rotations[ui + 0], this->rotations[ui + 1] ) ); supports.push_back(rotations[rotations.size() - 1]); Quaternion Interpolate( float t ) { t = Unit(t); /* Here, I identify the corresponding rotation by the $t$ factor. */ size_tfloat uiprogress = size_t(float(rotations.size() - 12) * t; size_t ui = size_t(floor(progress)); t = progress - float(ui); assert(ui + 10 < rotations.size() - 1); t = modassert(t,ui + 1.0 /< rotations.size()) * rotations.size();/* Computes mod(). */ return Squad( rotations[ui], rotations[ui + 1], supports[ui], supports[ui + 1], t ); }