Results 1 to 2 of 2

Thread: Digital Compass difficulty

  1. #1
    Join Date
    Mar 2011
    Location
    Narvik, Norway
    Posts
    13
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default 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.

    Qt Code:
    1. float Instrument::bearing(QPointF *src, QPointF *dest) {
    2.  
    3. float dLon = dest->y() - src->y();
    4.  
    5. float y = sin(dLon) * cos(dest->x());
    6. float x = cos(src->x()) * sin(dest->x()) - sin(src->x()) * cos(dest->x()) * cos(dLon);
    7. float brng = atan2(x, y);
    8.  
    9.  
    10. qDebug() << brng << "BRNG !!!!!!!!!!!!!!!!!!!";
    11. brng *= 180/(4.0*atan(1.0)); // 180/pi
    12. int deg = (((int)brng + 360) % 360);
    13.  
    14. 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:

    Qt Code:
    1. float Instrument::bearing(QPointF *src, QPointF *dest) {
    2.  
    3.  
    4. qreal y = dest->y() - src->y();
    5. qreal x = (dest->x() - src->x());
    6. qreal brng = atan2(x, y);
    7.  
    8.  
    9. qDebug() << brng << "BRNG !!!!!!!!!!!!!!!!!!!";
    10. brng *= 180/(4.0*atan(1.0)); // 180/pi
    11. int deg = (((int)brng + 360) % 360);
    12.  
    13. return deg;
    14. }
    To copy to clipboard, switch view to plain text mode 

    love,
    Badeand
    Last edited by Badeand; 15th June 2011 at 01:06.

  2. #2
    Join Date
    Jun 2011
    Location
    Finland
    Posts
    164
    Thanks
    1
    Thanked 26 Times in 26 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Maemo/MeeGo

    Default 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

Similar Threads

  1. Facing difficulty in parsing xml response in qt
    By newtolinux in forum Qt Programming
    Replies: 1
    Last Post: 14th December 2010, 13:59
  2. painting a compass
    By wagmare in forum Qt Programming
    Replies: 2
    Last Post: 15th November 2010, 07:16
  3. Replies: 1
    Last Post: 25th June 2010, 18:14
  4. Paint a compass on a GUI
    By trallallero in forum Qt Programming
    Replies: 10
    Last Post: 31st March 2010, 13:46
  5. difficulty in conversion
    By mohanakrishnan in forum Qt Programming
    Replies: 3
    Last Post: 7th December 2009, 10:31

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.