CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Threaded View

  1. #5
    Join Date
    Nov 2002
    Location
    California
    Posts
    4,556

    Re: heading in a cartesian coordinate system question

    Understand that you are using a compass-style definition of headings, which differs from standard angular measurements used by most trig functions by direction (clockwise vs. counterclockwise) and by 90 degrees (or, pi/2 radians, since most trig functions use radians, not degrees).

    With that understanding, look at the atan2() function. To get the compass heading in degrees from point b to point a, use the following:
    Code:
    double compass_heading = 90.0 - 57.29578 * atan2( by-ay, bx-ax );
    if (compass_heading >= 360.0)
      compass_heading -= 360.;
    if (compass_heading < 0.0)
      compass_heading += 360.;
    In your case, where point a is at the origin, ay=ax=0, which simplifies the equation a bit.

    To determine if the actual heading is "close enough" to the compass heading, just test against limits:
    Code:
    double limit = 30.0;  /* in degrees */
    double actual_heading = /* whatever */;
    if ( fabs( actual_heading - compass_heading ) < limit
    {
      /* it's close enough
    }
    else
    {
      /* it's not close enough */
    }
    fabs() is the floating point absolute value function.

    Mike
    Last edited by MikeAThon; April 18th, 2012 at 04:59 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured