Created
March 17, 2016 01:04
-
-
Save SIRHAMY/9767ed75bddf0b87b929 to your computer and use it in GitHub Desktop.
Example of quaternion on quaternion multiplication using the C++ Eigen library.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Eigen::Quaterniond MyWorld::quatMult(Eigen::Quaterniond q1, Eigen::Quaterniond q2) { | |
Eigen::Quaterniond resultQ; | |
resultQ.setIdentity(); | |
resultQ.w() = q1.w() * q2.w() - q1.vec().dot(q2.vec()); | |
resultQ.vec() = q1.w() * q2.vec() + q2.w() * q1.vec() + q1.vec().cross(q2.vec()); | |
return resultQ; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Are you sure? A coworker added some code that is nearly identical to yours. (Including the initialization of resultQ to identity. Which is probably redundant since you overwrite all of its state.) On your blog you say “Unfortunately, it looks like the standard * operator performs normal multiplication, not the special quaternion multiplication required by an actual quaternion.” I am not sure what that means, but when I tried an example, they appear to compute the same value:
produces:
Not a rigorous proof, but at least brings into question your original claim about Eigen’s operator* for quaternions.