by oneshtein · 1y ago · 0 comments
/* 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. 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),
}
}HN: Show HN Awesome New LLM can Code!! Also HN: TFA is vibe coded angry pitchfork or ugh
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.
Also it's a short function. It's impossible to miss unused parame if you read your own code at all. And if you somehow don't... then it's deserved anyway.