Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 6 of 6

Thread: quaternion indices

Hybrid View

  1. #1
    Advanced Member Frequent Contributor
    Join Date
    Oct 2009
    Posts
    593

    quaternion indices

    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?

  2. #2
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    3,188
    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 05:44 AM.

  3. #3
    Advanced Member Frequent Contributor
    Join Date
    Oct 2009
    Posts
    593
    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/

  4. #4
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,948
    Be careful with expression templates, as new C++11 features like `auto` and `decltype` can really ruin your day.

  5. #5
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    3,188
    Quote Originally Posted by ugluk View Post
    Certainly, it's thanks to the shaders, we have this scalar part = w convention.
    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.

  6. #6
    Advanced Member Frequent Contributor
    Join Date
    Oct 2009
    Posts
    593
    But (GLSL) shaders had their precursors too, if you can call them precursors. Maybe one of those early shading languages influenced the paper.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •