Click to See Complete Forum and Search --> : draw points inside an arc area


jinmissing
December 6th, 2006, 06:05 AM
Sorry, i'm facing trouble for using function which draw a pixel at specific coordinates to fill up a an arc area. I'm looking for any algorithm which can be help.

For example, i have a cirlce with radius = 50 pixel, and i want to filled up the arc area from 45 degree to 60 degree with JUST using draw pixel function. Is there any way to do it?

what i'm doing now is 3 loop, first loop is looping from 45 degree to 60 degree. Second and third loop is looping from center of the circle to the maximum avalaible coordinates. But I'm not sure for the algorithm to doing the second and third loop, any help will be appreciate

Maximus_X
December 6th, 2006, 07:55 AM
I put down a sample code that draw an arc area.

void DrawLaserArea(CDC* pDC, int xCenter,int T_SWORD yCenter,
int radiusX, int radiusY, COLORREF color , BOOL b_UpOrDown )
{
CPen pen(PS_SOLID, 1, RGB(225,207,17));
CPen *pmyOldPen;

double Yaxis = 0.0f, Xaxis = 0.0f;

pmyOldPen = pDC->SelectObject(&pen);

Yaxis = radiusY;
Xaxis = 1;
Yaxis = static_cast<T_SWORD> (sqrt((double)radiusX*radiusY - 1) + 0.5);

while (Xaxis < Yaxis)
{
if (b_UpOrDown)
{
pDC->SetPixel( static_cast<int>(xCenter + Xaxis), static_cast<int> (yCenter - Yaxis), color);
pDC->SetPixel( static_cast<int>(xCenter - Xaxis), static_cast<int> (yCenter - Yaxis), color);
pDC->SetPixel( static_cast<int>(xCenter + Yaxis), static_cast<int> (yCenter - Xaxis), color);
pDC->SetPixel( static_cast<int>(xCenter - Yaxis), static_cast<int> (yCenter - Xaxis), color);
}
else
{
pDC->SetPixel( static_cast<int>(xCenter + Xaxis), static_cast<int> (yCenter + Yaxis), color);
pDC->SetPixel( static_cast<int>(xCenter - Xaxis), static_cast<int> (yCenter + Yaxis), color);
pDC->SetPixel( static_cast<int>(xCenter + Yaxis), static_cast<int> (yCenter + Xaxis), color);
pDC->SetPixel( static_cast<int>(xCenter - Yaxis), static_cast<int> (yCenter + Xaxis), color);
}

Xaxis += 1;
Yaxis = static_cast<int> (sqrt((double)radiusX*radiusY - Xaxis*Xaxis) + 0.5);
}

pDC->SelectObject(pmyOldPen);
}


Please analyze this code and addapt it to your expectations. If you will test it you will see that this code draw a arc area from 0 to 180 grads if b_UpOrDown = TRUE or from 180 to 160 grads if b_UpOrDown = FALSE.

Enjoy! ;)