
Type: Bug

Status: Closed

Priority: Not Evaluated

Resolution: Duplicate

Affects Version/s: 4.8.2, 5.0.0 Beta 1

Fix Version/s: 5.0.0 RC 1

Component/s: Core: Other

Labels:None

Commits:9aa67cf0c48ff8e9e73fc19c4dcd950961b5ad54
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..