Details

Bug

Resolution: Duplicate

Not Evaluated

4.8.2, 5.0.0 Beta 1

None

9aa67cf0c48ff8e9e73fc19c4dcd950961b5ad54
Description
Correct interface should be
qreal qAtan2 ( qreal y, qreal x )
This reflects the correct use of std::atan(y,x) and is in accordance with mathematics. But note that the gui coordinate system is NOT in accordance with the usual rhs mathematical coordinate system.
Make sure you follow through parameters all the way through when fixing this. First parameter of qAtan2 should be first param of std::atan2. It does so today, but parameter names are misleading..
Documentation does not make sense. A direction is not returned, only an angle. A good explanation can be found at
http://www.mathworks.se/help/techdoc/ref/atan2.html
The OvenTimer example attemts to use this function (for some reason the std::atan(y,x) is used) and fails badly.
Also, an issue comes into play at the typical gui coordinate system has y positive downwards and not upwards, whilst x positive to the right as is usual. In a sense comparing this to the mathematically normal y positive upwards, is like comparing a left handed to a right handed coordinate system. This can be confusing and easily causes errors in code; typically using aTan2(y,x) instead of aTan2(y,x) fixes this. I rewrote the OvenTimer that shows a correct use of aTan2. The angle returned is in accordance with above webpage, and hence implicitly gives a 360 degree direction.
void OvenTimer::mouseMoveEvent(QMouseEvent *event)
{
QPointF point = event>pos()  rect().center();
// original: double theta = std::atan2(point.x(), point.y()) * 180.0 / M_PI;
theta_raw = qAtan2(point.y(), point.x()) * 180.0 / M_PI;
this>setWindowTitle(QObject::tr("theta,x,y, %1 x%2 y%3")
.arg((int)theta_raw)
.arg(point.x())
.arg(point.y()));
update();
}
Send me an email if I can be of assistance..
Attachments
For Gerrit Dashboard: QTBUG27090  

#  Subject  Branch  Project  Status  CR  V 
34004,2  Fix the name of the arguments of qAtan2 to match std::atan2  master  qt/qtbase  Status: MERGED  +2  0 
76273,1  Fix the name of the arguments of qAtan2 to match std::atan2  4.8  qt/qt  Status: MERGED  +2  0 