First, you'll probably want a function that gives you the angle between two vectors. Here's how to write it:
The magnitude of the cross product of two vectors is equal to the product of the magnitudes of the vectors times the sine of the angle between them.
Let A = vector from P1 --> P2;
Let B = vector from P2 --> P3;
Let θ be the angle
|A × B| = |A| |B| sin(θ)
and therefore
sin(θ) = ( |A × B| ) / (|A| |B| )
the magnitude of the cross product of two 2D vectors is calculated like this:
|A × B| = Ax By - Bx Ay
And the magnitude of the dot product of two vectors is equal to the product of the magnitudes of the vectors times the cosine of the angle between them.
A·B = |A| |B| cos(θ)
and therefore
cos(θ) = (A·B) / ( |A| |B| )
the dot product is calculated like this:
A·B = Ax Bx + Ay By
|A| = sqrt( Ax Ax + Ay Ay )
|B| = sqrt( Bx Bx + By By )
that gives you sin(θ) and cos(θ).
You can call atan2 to get θ from sin(θ) and cos(θ).
θ = atan2( sin(θ), cos(θ) )
In code now:
/// <summary>
/// Calculates the angle between two 2-D vectors.
/// </summary>
/// <returns>angle in radians</returns>
static double AngleBetweenVectors( double Ax, double Ay, double Bx, double By )
{
double magA = Math.Sqrt( Ax * Ax + Ay * Ay );
double magB = Math.Sqrt( Bx * Bx + By * By );
double magAmagB = magA * magB;
if( magA * magB == 0 ) throw new Exception( "Vectors must be non-zero length" );
double sinTheta = (Ax * By - Bx * Ay) / magAmagB;
double cosTheta = (Ax * Bx + Ay * By) / magAmagB;
double theta = Math.Atan2( sinTheta, cosTheta );
return theta;
}
Result is in radians. Multiply by 180/Math.PI to get degrees. If you find that clockwise and counterclockwise are reversed because of your coordinate system, just take the negative of your result.
The arc drawing function uses the x-axis as its reference point, so you need to find the angle between your vector and the x axis (1,0). You have to provide start and end angles. A little bit of conditional checking to verify that the arc is going in the direction you want will likely be necessary, and you can adjust the angles such that thetaStart > thetaEnd or thetaStart < thetaEnd as necessary.
You also gonna wanna check this link