Always return a CCW rotation from a 3 point arc method
<p>I'm trying to create 3 point arcs from a table into a autocad (R12/lt2) DXF file.
the problem comes is that the file seems to ALWAYS save arcs in a CCW rotation. so the method below works properly if the pont data i feed it is CCW but does not work if the rotation is CW the arc's angles gets 'flipped'.I can't seem to figure out a way to detect when a CW arc's data is detected to rectify the error</p>

<p>The method calculates the arc with 3 points on the arc's circumference (not the start, center and end point)</p>

<p>Here is My method:</p>

<pre><code>public static List&lt;double&gt; threePointArch(double startX, double startY, double midX, double midY, double endX, double endY)
{
    List&lt;double&gt; returnValues = new List&lt;double&gt;();
    //Calculate center point from 3 points on a circle
    //calculate Line R
    double lineR = (midY - endY) / (midX - endX);
    //Calculate Line T
    double lineT = (startY - midY) / (startX - midX);
    //calculate x Center
    double centerX = ((lineR * lineT * (startY - endY)) + (lineR * (midX + startX)) - (lineT * (endX + midX))) / (2 * (lineR - lineT));
    //calculate y Center by subsitution
    double centerY = ((endY + midY) / 2) + ((centerX - ((endX + midX) / 2)) * (-1 / lineR));
    //Calculate Raduis
    double raduis = Math.Sqrt((startX - centerX) * (startX - centerX) + (startY - centerY) * (startY - centerY));

    //Calculate Start Angle
    double startAngle = Math.Atan2(startY - centerY, startX - centerX) * (180 / Math.PI);
    //Calculate End Angle
    double endtAngle = Math.Atan2(endY - centerY, endX - centerX) * (180 / Math.PI);

    //if (endtAngle &lt; 0)
    //{
    //    endtAngle = endtAngle + 360;
    //}

    returnValues.Add(centerX);
    returnValues.Add(centerY);
    returnValues.Add(raduis);
    returnValues.Add(startAngle);
    returnValues.Add(endtAngle);
    return returnValues;
}
</code></pre>

<p>I have been trying for 3 weeks now with every fix i could think of, i tried calculating the midpoint angle to see if it is less than the endpoint angle, I tried to see if the startpoint angle is less than the endpoint angle(with several variations of this)This math is over my head!!</p>

<p><strong>Edit:</strong></p>

<p>I found some information <a href="https://stackoverflow.com/questions/24178416/arc-via-3-points-in-specific-direction">Here</a>
and i came up with this(added above the return):</p>

<pre><code>  //calculate rotation
  double midAngle = Math.Atan2(midY - centerY, midX - centerX) * (180 / Math.PI);
  if (midAngle - startAngle &gt; +180.0) midAngle -= 360.0;
  if (midAngle - startAngle &lt; -180.0) midAngle += 360.0;
  if (endtAngle - midAngle &gt; +180.0) endtAngle -= 360.0;
  if (endtAngle - midAngle &lt; -180.0) endtAngle += 360.0;

  string dir = "none";
  if (midAngle - startAngle &lt; 0)
      dir = "CW";
  if (midAngle - startAngle &gt; 0)
      dir = "CCW";
  if (midAngle - startAngle == 0)
      dir = "none";

  if (dir == "CW")
  {
      double startAngletmp = startAngle;
      startAngle = endtAngle;
      endtAngle = startAngletmp;
  }
</code></pre>

<p>It seems to work for the most part but if i can get some confirmation by a math Head, that would be great</p>