diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2017-02-24 15:49:29 +0100 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2017-07-06 14:02:48 +0000 |
commit | 368b24bfa00a5ef8fe14cd5e4690333675d7704a (patch) | |
tree | 712feb4dc1589d229438f27e291ecfdc8bd72703 /examples/sensors/accelbubble/accelbubble.qml | |
parent | 92ae0d2e5df16096893d03de3f5602d7d5d70e7d (diff) | |
download | qtsensors-368b24bfa00a5ef8fe14cd5e4690333675d7704a.tar.gz |
Be consistent about values related to pi (radian / degree ratio)
Use JavaScript's Math.PI to compute 180 / pi (the number of degrees in
one radian), rather than a hand-coded value for this constant. Store
the result in a readonly property double to avoid repeating the
computation. Tweak the pitch and roll calculations to use more apt
Math methods: use hypot rather than sqrt of a sum of squares, and
use atan2 instead of a tan of a ratio (whose denominator is always
positive, so this doesn't change which angle we get).
Task-number: QTBUG-58083
Change-Id: Ic3f865dfcbd9b02a0b93f065995d850386aef18c
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
Diffstat (limited to 'examples/sensors/accelbubble/accelbubble.qml')
-rw-r--r-- | examples/sensors/accelbubble/accelbubble.qml | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/examples/sensors/accelbubble/accelbubble.qml b/examples/sensors/accelbubble/accelbubble.qml index 37bf427..8bd036f 100644 --- a/examples/sensors/accelbubble/accelbubble.qml +++ b/examples/sensors/accelbubble/accelbubble.qml @@ -63,7 +63,7 @@ ApplicationWindow { width: 320 height: 480 visible: true - + readonly property double radians_to_degrees: 180 / Math.PI //! [1] Accelerometer { @@ -101,10 +101,10 @@ ApplicationWindow { } function calcPitch(x,y,z) { - return -(Math.atan(y / Math.sqrt(x * x + z * z)) * 57.2957795); + return -Math.atan2(y, Math.hypot(x, z)) * mainWindow.radians_to_degrees; } function calcRoll(x,y,z) { - return -(Math.atan(x / Math.sqrt(y * y + z * z)) * 57.2957795); + return -Math.atan2(x, Math.hypot(y, z)) * mainWindow.radians_to_degrees; } Image { |