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.
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;
float Instrument::bearing(QPointF *src, QPointF *dest) {
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;
To copy to clipboard, switch view to plain text mode
Please help =)
thanks,
Badeand
Added after 49 minutes:
Sorry guys I fixed it =)
This did the trick:
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;
}
float Instrument::bearing(QPointF *src, QPointF *dest) {
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;
}
To copy to clipboard, switch view to plain text mode
love,
Badeand
Bookmarks