title: box2d difference between angles of two bodies
body: <p>Working with box2d and cocos2d, I've calculated two vectors:</p>
  
  <ul>
  <li>one is the vector pointing in the direction the car is travelling. (center of the vehicle to it's north point).</li>
  <li>two is the vector pointing in the direction of the target. (center to the vehicle to the target center.)</li>
  </ul>
  
  <p>I need to rotate the vehicle to also point in the direction of the target. This is done by setting the vehicle's steering either 90 degrees to turn right or -90 to turn left.</p>
  
  <p>At the moment i'm querying the box2d body of the vehicle for its angle, then calculating the angle of the target direction vector using:</p>
  
  <pre><code>if(vector.y == 0){ vector.y = 0.000001f; }
  float baseRadians = atan(vector.x/vector.y);
  if(vector.y &lt; 0){ baseRadians += PI_CONSTANT; } //Adjust for -Y
  return -1 * baseRadians;
  </code></pre>
  
  <p>The following is crude and where I need help...! </p>
  
  <p>I then compare the angle of the vehicle against the angle returned from the direction vector and set the steering as follows:</p>
  
  <pre><code>if(vehicleAngle &lt; targetAngle)
          {
              steeringInput = -90.0;    
          }
          else if(vehicleAngle &gt; targetAngle)
          {
              steeringInput = 90.0;    
          }
          else
          {
              steeringInput = 0.0;     
          }
  </code></pre>
  
  <p>The problem is two fold:</p>
  
  <ul>
  <li>The target angle jumps from -4.71 to 1.57 radians, causing the vehicle to switch to the wrong direction </li>
  <li>The vehicle angle is continous and keeps increasing rather than staying within a range.</li>
  </ul>
  
  <p>Is there a way to get both the target vector and the vehicle angle in a set range where, for example, if the target angle is 0-360 and the van angle is 0-360, i can then compare them accurately?</p>
  
  <p>Any other way to do this...? Any help appreciated!</p>