Page 1 of 1

Angles and ship navigation

PostPosted: Thu Aug 18, 2005 8:30 pm
by BeyondtheTech
I'm having a serious problem with angles.

Suppose I'm traveling at 0 or 10 degrees (right), and I choose to go 270 or 350 degrees. The ship always chooses to go the long way around. My logic is faulty and doesn't seem to want to go the shorter angle, not that I can seem to determine it anyway.

What statements can I use to get the delta angle in plus or minus?

Thanks. I'm stumped.

PostPosted: Fri Aug 19, 2005 7:24 pm
by NyahKitty
I'm not that far along in writing code, but wouldn't you want a test loop that checks to see which would be the shortest route to the new heading?

PostPosted: Fri Aug 19, 2005 8:24 pm
by jazz_e_bob
Code: Select all
// which is the best direction to turn to get to new angle?

int bestRotationFor( double currentAngle, double newAngle )
{
  double toRight;
  double toLeft;
  double AL = myAngle;
  double AR = newAngle;
 
  if ( AR > AL )
  {
    toRight = AL + 360 - AR;
    toLeft = AR - AL;
  }
  else
  {
    toRight = AL - AR;
    toLeft = 360 - AL + AR;
  }


  if ( toRight < toLeft )
    return ROTATING_RIGHT;
  else
    return ROTATING_LEFT;
}