title: is it legal to take acos of 1.0f or -1.0f?
body: <p>I have a problem with my code where agents moving around suddenly disappear. This seems to be because their positions suddenly become 1.#INF000 in the x and y axis. I did a little research and someone said this can occur with acos if a value is over or under 1 and -1 respectively, but went on to say it could happen if the values were close too. I added an if statement to check to see if I'm ever taking acos of 1 or -1 and it does evaluate to 1 a few frame cycles before they disappear, however I don't really understand the problem to be able to fix it. Can anyone shed any light on this matter?</p>
  
  <pre><code>D3DXVECTOR3 D3DXVECTOR3Helper::RotToTarget2DPlane(D3DXVECTOR3 position, D3DXVECTOR3 target)//XY PLANE
  {
      //Create std::vector to target
      D3DXVECTOR3 vectorToTarget = target - position;
  
      D3DXVec3Normalize(&amp;vectorToTarget, &amp;vectorToTarget);
  
      //creates a displacement std::vector of relative 0, 0, 0
      D3DXVECTOR3 neutralDirectionalVector = D3DXVECTOR3(1, 0, 0);//set this to whatever direction your models are loaded facing   
  
      //Create the angle between them
  
      if(D3DXVec3Dot(&amp;vectorToTarget, &amp;neutralDirectionalVector) &gt;= 1.0f ||D3DXVec3Dot(&amp;vectorToTarget, &amp;neutralDirectionalVector) &lt;= -1.0f)
      {
          float i = D3DXVec3Dot(&amp;vectorToTarget, &amp;neutralDirectionalVector);
          float j = 0; //ADDED THIS IF STATEMENT
      }
  
      float angle = acos(D3DXVec3Dot(&amp;vectorToTarget, &amp;neutralDirectionalVector));
  
      if (target.y &gt; position.y)
      {
          return D3DXVECTOR3(0, 0, angle);
      }
      else
      {
          return D3DXVECTOR3(0, 0, -angle);
      }
  }//end VecRotateToTarget2DPlane()
  </code></pre>