Re: Digital Compass difficulty
Hi, can someone see whats wrong with this formula/code? the compas works perfectly for North, south, east, west, but not the values inbetween. its very inaccurate in between.
Code:
float dLon = dest->y() - src->y();
float y = sin(dLon) * cos(dest->x());
float x = cos(src->x()) * sin(dest->x()) - sin(src->x()) * cos(dest->x()) * cos(dLon);
float brng = atan2(x, y);
qDebug() << brng << "BRNG !!!!!!!!!!!!!!!!!!!";
brng *= 180/(4.0*atan(1.0)); // 180/pi
int deg = (((int)brng + 360) % 360);
return deg;
Please help =)
thanks,
Badeand
Added after 49 minutes:
Sorry guys I fixed it =)
This did the trick:
Code:
qreal y = dest->y() - src->y();
qreal x = (dest->x() - src->x());
qreal brng = atan2(x, y);
qDebug() << brng << "BRNG !!!!!!!!!!!!!!!!!!!";
brng *= 180/(4.0*atan(1.0)); // 180/pi
int deg = (((int)brng + 360) % 360);
return deg;
}
love,
Badeand
Re: Digital Compass difficulty
Due to the new functionality of the forum showing on the main page posts that were not replied (that means "not solved"), I assume that this one doesn't really belong there and therefore I write a post reply in order to make it rest in peace :)