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

webmite
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)
ie
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.

correctAngle.xls

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

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

webmite
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

http://ideone.com/

...this site appeared to be having problems today...so I have found another....

http://cpp.sh

....my example test page for the correctAngle function is here...Note it is modified from original...

correctAngle
http://cpp.sh/2i7qp

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

correctAngleU
http://cpp.sh/4yswt