If you check math books, the scalar part of a quaternion is usually at index 0 of a quaternion list, but in some code I've looked up, the scalar part is at index 3. Do there exist any practical benefits to either convention?
If you check math books, the scalar part of a quaternion is usually at index 0 of a quaternion list, but in some code I've looked up, the scalar part is at index 3. Do there exist any practical benefits to either convention?
I've seen both orderings as well. Indices aside, in math contexts you typically see <s,v> where s is the scalar part and v is the vector part (thus scalar being first). However in 3D graphics contexts, almost always .xyz is the vector part (not surprisingly) and .w is the scalar part (as we just stuff quats into normal 4-vectors which we deal with all the time). Even Shoemake used this symbology in his quaternion write-up.
The index is a derived thing. We graphics guys index vectors .xyzw not alphabetically .wxyz. Thus the scalar part being index 3.
Definitely a convention but not something you have to do. You could use .x for the scalar part and .yzw for the 3-vector part, though it's not as intuitive for graphics folks.
Also beyond conventions, and more to your question, the vector part is really and truly a 3D vector which is the axis of rotation. There are cases where you want to cross another 3D vector with this axis to generate an orthonormal basis or transform coordinates in some way. There you can intuitively write cross ( quat.xyz, v.xyz ) or similar. This would be less readable with the vector part in .yzw.
Last edited by Dark Photon; 10-19-2012 at 06:44 AM.
Too bad I haven't thought of this myself. Certainly, it's thanks to the shaders, we have this scalar part = w convention. I've written an expression template library (as TVMET is slowly starting to become too old for my taste) and needed to know at what index to put the scalar part.
http://code.google.com/p/etemlib/
Be careful with expression templates, as new C++11 features like `auto` and `decltype` can really ruin your day.
Actually, no. It's way pre-shaders. Here's Shoemake's SIGGRAPH 1985 paper:
* Animating Rotation with Quaternion Curves
See the 2nd paragraph at the top of page 4. And I'm not saying this is the first such paper to use .xyz for vector and .w for scalar. Might be, but don't know for sure.
But (GLSL) shaders had their precursors too, if you can call them precursors. Maybe one of those early shading languages influenced the paper.