Skip to content

RotateGestureDetector getRotationDegreesDelta returns values close to 360 on small angle change #36

Open
@stanleyguevara

Description

@stanleyguevara

Performing minuscule rotations while having rotation line between fingers horizontal causes to getRotationDegreesDelta to output values close to 360, e.g. -359.4 or 359.2.

This is caused by Math.atan2 used to calculate diff angle having ambiguity around +-180*. All is fine and well when performed rotation is shown 1:1 on screen, but I'm scaling it to get more precise moment with small values, so when the received values are 0.015, 0.020, 0.017, -359.4, 0.021... it causes a sudden jerk.

IMO it's a bug because nobody expects sudden 360 for minuscule finger motion when calling getRotationDegreesDelta. The real change of angle is certainly NOT a 360 degree.

My workaround was:

val raw = detector.rotationDegreesDelta
val diffRotation = if (abs(raw) > 300) {   // or some other arbitrary value above 180*
    if (raw < 0) {
        360 + raw
    } else {
        raw - 360
    }
} else raw

I think better fix (without arbitrary 300* value) can be done on library side by checking if one angle falls close to 180* and other close to -180*, so it's passing through discontinous part of Math.atan2 and can be accounted for.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions