Article ID: 125693
Article Last Modified on 3/7/2005
BOOL AngleArc1(HDC hdc, int X, int Y, DWORD dwRadius,
float fStartDegrees, float fSweepDegrees)
{
float fCurrentAngle; // Current angle in radians
float fStepAngle = 0.03f; // The sweep increment value in radians
float fStartRadians; // Start angle in radians
float fEndRadians; // End angle in radians
int ix, iy; // Current point on arc
float fTwoPi = 2.0f * 3.141592f;
/* Get the starting and ending angle in radians */
if (fSweepDegrees > 0.0f) {
fStartRadians = ((fStartDegrees / 360.0f) * fTwoPi);
fEndRadians = (((fStartDegrees + fSweepDegrees) / 360.0f) *
fTwoPi);
} else {
fStartRadians = (((fStartDegrees + fSweepDegrees) / 360.0f) *
fTwoPi);
fEndRadians = ((fStartDegrees / 360.0f) * fTwoPi);
}
/* Calculate the starting point for the sweep via */
/* polar -> cartesian conversion */
ix = X + (int)((float)dwRadius * (float)cos(fStartRadians));
iy = Y - (int)((float)dwRadius * (float)sin(fStartRadians));
/* Draw a line to the starting point */
LineTo(hdc, ix, iy);
/* Calculate and draw the sweep */
for (fCurrentAngle = fStartRadians;
fCurrentAngle <= fEndRadians;
fCurrentAngle += fStepAngle) {
/* Calculate the current point in the sweep via */
/* polar -> cartesian conversion */
ix = X + (int)((float)dwRadius * (float)cos(fCurrentAngle));
iy = Y - (int)((float)dwRadius * (float)sin(fCurrentAngle));
/* Draw a line segment to current point */
LineTo(hdc, ix, iy);
}
return TRUE;
}
BOOL AngleArc2(HDC hdc, int X, int Y, DWORD dwRadius,
float fStartDegrees, float fSweepDegrees)
{
int iXStart, iYStart; // End point of starting radial line.
int iXEnd, iYEnd; // End point of ending radial line.
float fStartRadians; // Start angle in radians.
float fEndRadians; // End angle in radians.
BOOL bResult; // Function result.
float fTwoPi = 2.0f * 3.141592f;
/* Get the starting and ending angle in radians. */
if (fSweepDegrees > 0.0f) {
fStartRadians = ((fStartDegrees / 360.0f) * fTwoPi);
fEndRadians = (((fStartDegrees + fSweepDegrees) / 360.0f) * fTwoPi);
} else {
fStartRadians = (((fStartDegrees + fSweepDegrees) / 360.0f) *
fTwoPi);
fEndRadians = ((fStartDegrees / 360.0f) * fTwoPi);
}
/* Calculate a point on the starting radial line via */
/* polar -> cartesian conversion. */
iXStart = X + (int)((float)dwRadius * (float)cos(fStartRadians));
iYStart = Y - (int)((float)dwRadius * (float)sin(fStartRadians));
/* Calculate a point on the ending radial line via */
/* polar -> cartesian conversion. */
iXEnd = X + (int)((float)dwRadius * (float)cos(fEndRadians));
iYEnd = Y - (int)((float)dwRadius * (float)sin(fEndRadians));
/* Draw a line to the starting point. */
if (fSweepDegrees > 0.0f)
LineTo(hdc, iXStart, iYStart);
else
LineTo(hdc, iXEnd, iYEnd);
/* Draw the arc. */
bResult = Arc(hdc, X - dwRadius, Y - dwRadius,
X + dwRadius, Y + dwRadius,
iXStart, iYStart,
iXEnd, iYEnd);
/* Move to the ending point. Arc() will not do this and ArcTo() */
/* will not work on Win32s or Win16. */
if (fSweepDegrees < 0.0f)
MoveToEx(hdc, iXStart, iYStart, NULL);
else
MoveToEx(hdc, iXEnd, iYEnd, NULL);
return bResult;
}
Keywords: kbhowto KB125693