News for hackers. Stuff that matters.
Re:An interactive guide to sensor fusion with quaternions by polishdude20 on Friday August 15, 2025 @02:28PM (#44915875)
Sorry, but x,y and z are not even being used in that function...
Re:An interactive guide to sensor fusion with quaternions by noodlejs on Friday August 15, 2025 @02:39PM (#44916003)
LOL ok yeah, that's a copy-paste issue. I'll fix it up here shortly.
Re:An interactive guide to sensor fusion with quaternions by xeonmc on Friday August 15, 2025 @02:45PM (#44916074)
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),
        }
    }