Angle calculation suggestion

Previous Topic Next Topic
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view

Angle calculation suggestion

under the RS_Math segment of code there is a function  called correctAngle....
the segment is as follows....
 * Corrects the given angle to the range of 0-2*Pi.
double RS_Math::correctAngle(double a) {
    return M_PI + remainder(a - M_PI, m_piX2);
It does not do as it suggests....output range is actually from 180 to 540 (PI to PI+2*PI)
0 becomes 360.
90 becomes 450.
179 becomes 539.
180 becomes 180.
180 to 360 map through correctly to 180 to 360.
361 becomes 361.
539 becomes 539.
negative numbers....
-180 to -1 map through correctly to 180 to 359.
-181 becomes 539.

Because this angle formula is use widely throughout this application it
is hard to determine how much coding is affected by this.

At the very least the associated comment documentation should be changed to reflect
the underlying function.

Proof of this behavior is an attached excel spreadsheet below that implements the
equivalent formula in a spreadsheet. The input angle argument field is highlighted in yellow
in the spreadsheet.


NOTE: the undocumented function directly below correctAngle
called correctAngleU actually performs as described by the original

It however is only referenced once by getAngleDifferenceU

double RS_Math::correctAngleU(double a) {
    return remainder(a, m_piX2);
Reply | Threaded
Open this post in threaded view

Re: Angle calculation suggestion

This post was updated on .
Someone was kind enough to point out that the remainder function does not directly
correlate to the fmod function in excel I was using to test....he also sent me a link to an online
C++11 compliant website with online compiler ide for testing.

the site he had suggested was

...this site appeared to be having problems I have found another.... example test page for the correctAngle function is here...Note it is modified from original...

correctAngle example test page for the correctAngleU function is matches original code...
however...the output range is -PI to +PI which is not as it is documented.