Skip to content

Commit e3a499f

Browse files
committed
Added quaternions checking to prevent negative sqrt argument
1 parent 6ff3484 commit e3a499f

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/flightlog.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,13 @@ export function FlightLog(logData) {
737737
z: srcFrame[imuQuaternion[2]] / scaleFromFixedInt16,
738738
w: 1.0,
739739
};
740-
q.w = Math.sqrt(1.0 - (q.x ** 2 + q.y ** 2 + q.z ** 2));
740+
741+
const m = q.x ** 2 + q.y ** 2 + q.z ** 2;
742+
if (m < 1.0) {
743+
q.w = Math.sqrt(1.0 - m);
744+
} else {
745+
q.w = 0.0;
746+
}
741747
const xx = q.x ** 2,
742748
xy = q.x * q.y,
743749
xz = q.x * q.z,

0 commit comments

Comments
 (0)