DOI-USGS / ale

Abstraction Layer for Ephemerides (ALE)
Other
13 stars 33 forks source link

Update quaternions to prevent sign flipping #623

Closed AustinSanders closed 1 week ago

AustinSanders commented 2 weeks ago

Licensing

This project is mostly composed of free and unencumbered software released into the public domain, and we are unlikely to accept contributions that are not also released into the public domain. Somewhere near the top of each file should have these words:

This work is free and unencumbered software released into the public domain. In jurisdictions that recognize copyright laws, the author or authors of this software dedicate any and all copyright interest in the software to the public domain.

Closes #603

We've had a few discussions on the dev team about how to accomplish this, and, for the most part, we decided on implementing these changes through subclassing. This PR does not do that, but instead makes a quick and easy change that accomplishes the same thing but without isolating the change to LineScan cameras.

In order to access the quaternions from a LineScanner, it is necessary to go the route of LineScanner.FrameChain.Rotation.quats, and there are two types of rotations -- TimeDependent and Constant, so we would need at least 3 subclasses to achieve this (a custom frame chain + two types of custom rotations). TimeDependentRotation and ConstantRotation classes have methods that instantiate other TimeDependentRotation or ConstantRotation, so a lot of the methods can't use simple inheritance -- they'd need to have their logic copied and objects changed.

Ultimately, subclassing is turning out to be pretty bloated and messy. It's still possible, but this seems significantly cleaner, and I don't think the functionality inherently needs to be isolated to LineScanners.

acpaquette commented 2 weeks ago

@AustinSanders Looks like a dawn test is failing from the change

AustinSanders commented 1 week ago

Running isd_generate on the image linked in the issue now results in quaternions that are represented correctly.

New representation:

[
        -0.00014084959512966424,
        0.06988009226932775,
        -0.9799806108855965,
        -0.18642627270348733
      ],
      [
        -5.113202307559794e-05,
        0.0698602605370718,
        -0.9799805775003425,
        -0.18643392691595587
      ],
      [
        3.8327611438555095e-05,
        0.06983938596985084,
        -0.9799806386052183,
        -0.1864414295623614
      ],
      [
        0.0001291419108749148,
        0.06981977990312137,
        -0.979980865507725,
        -0.1864475392580358
      ],

Old representation:

[
        0.00014084959512966424, <<< positive, decreasing
        -0.06988009226932775,
        0.9799806108855965,
        0.18642627270348733
      ],
      [
        5.113202307559794e-05, <<< positive, decreasing, about to flip sign
        -0.0698602605370718,
        0.9799805775003425,
        0.18643392691595587
      ],
      [
        3.8327611438555095e-05, <<< Should be negative, but flips all signs to keep scalar positive 
        0.06983938596985084,    
        -0.9799806386052183,    
        -0.1864414295623614
      ],
      [
        0.0001291419108749148, 
        0.06981977990312137,
        -0.979980865507725,
        -0.1864475392580358
      ],

Note that the positive scalar criterion is no longer enforced, and the sign performs a "natural flip" when crossing the 0 boundary, but the other quaternions do not flip.