5 comments

[ 3.3 ms ] story [ 22.7 ms ] thread
> 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.

  /* 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.
That’s nice. I’m interested in why you went for a complementary filter specifically, if it was enough for your purpose or just the first one you tried out. (I see you reference the ahrs package where there are also implementations for other attitude estimators.)
I don't why people get so excited about quaternions, like they are some mystical concept.

Personally, I think one is better off learning some Differential Geometry and Abstract Algebra to really appreciate the broader context in which these exist.