An interactive guide to sensor fusion with quaternions

(quaternion.cafe)

45 points | by Bogdanp 9 hours ago ago

12 comments

  • mci 6 hours ago

    > a quaternion is a 4D representation of a rotation in 3D space

    A unit quaternion represents a rotation in R³.

    A quaternion represents the quotient of two vectors in R³. That's what Hamilton had in mind.

    • xeonmc 5 hours ago

      in other words, dilation + rotation

  • oneshtein 5 hours ago

      /* Produce a quaternion from an axis-angle representation.*/
      function quat_from_axis(theta: number, x: number, y: number, z: number) {    
        const halfcos = Math.cos(theta * 0.5);    
        const halfsin = Math.sin(theta * 0.5);    
    
        return new Quaternion(
            halfcos,
            axis[0] * halfsin,
            axis[1] * halfsin,
            axis[2] * halfsin,
        );    
      }
    
    Function is vibe coded.
    • noodlejs 5 hours ago

      Hi! Author here. I hand wrote this website and the source code of the examples mostly comes from my own debugging tools. That method in particular is just a very minimal implementation of section 8.5.2 of this textbook (but I tried to make it friendly for the blog post).

      https://gamemath.com/book/orient.html#quaternion_geometry

      • polishdude20 4 hours ago

        Sorry, but x,y and z are not even being used in that function...

        • noodlejs 4 hours ago

          LOL ok yeah, that's a copy-paste issue. I'll fix it up here shortly.

          • xeonmc 4 hours ago

            imo it's better to express the conversion relation as exp-log pairs:

                fn exp(q: Quat) -> Quat {
                    let ijk = sqrt(q.i*q.i + q.j*q.j + q.k*q.k);
                    Quat {
                        i: exp(q.l) * sin(ijk) * q.i / ijk,
                        j: exp(q.l) * sin(ijk) * q.j / ijk,
                        k: exp(q.l) * sin(ijk) * q.k / ijk,
                        l: exp(q.l) * cos(ijk),
                    }
                }
            
                fn log(q: Quat) -> Quat {
                    let ijk = sqrt(q.i*q.i + q.j*q.j + q.k*q.k);
                    Quat {
                        i: atan2(ijk, q.l) * q.i / ijk,
                        j: atan2(ijk, q.l) * q.j / ijk,
                        k: atan2(ijk, q.l) * q.k / ijk,
                        l: 0.5 * log(q.i*q.i + q.j*q.j + q.k*q.k + q.l*q.l),
                    }
                }
    • ARob109 4 hours ago

      I've been seeing "that's vibe coded" comments a lot lately on posts. Comments that call out code that may or may not be vibe-coded. At what point should these types of posts start getting down-voted? It's not constructive, and IMO imparts a negative connotation.

      HN: Show HN Awesome New LLM can Code!! Also HN: TFA is vibe coded angry pitchfork or ugh

    • feoren 5 hours ago

      What makes you so confident that you can tell that a 3-line function is AI? Especially given that the author denies it, with evidence.

      • oneshtein 3 hours ago

        It cannot work, because x,y,z are not used at all.

        • margalabargala 3 hours ago

          This looks more like a copy paste error, where the function signature requests xyz, but the function itself uses an undefined array "axis" of which xyz correspond to indexes 0-2.

          The code is correct aside from the obvious bug.

          Bugs predate the existence of AI by decades. This particular bug doesn't look like one an AI would write.

      • CamperBob2 4 hours ago

        Then again, that's just the AI would say...