Click to See Complete Forum and Search --> : How to make a circle?


cristian.muller
August 9th, 2005, 05:24 AM
Hello,
i am amazed that VC didn't bother not to make a Circle function!

How can i make a circle at x,y and with a radius r?

Thanks!

olivthill
August 9th, 2005, 08:28 AM
And they don't even have a function for drawing a square. Isn't thas scandalous? Call Microsoft and get your money back. All they have is a Rectangle and Polyline function.

By the way, they also have an Ellipse() function.

ovidiucucu
August 9th, 2005, 08:59 AM
And they don't even have a function for drawing a square. Isn't thas scandalous? Call Microsoft and get your money back. All they have is a Rectangle and Polyline function.

By the way, they also have an Ellipse() function.
:D :D :D

By the way, I was also searching for Circle function, long long time ago... ;)

cristian.muller
August 10th, 2005, 05:14 AM
It's seams that the slogan at MS is : work as little&fast as u can!

philkr
August 10th, 2005, 08:24 AM
LOL. I think he didn't get it. If I'm wrong, please don't mind.

PS: The smilie ;-) stands for ironic!

andytim
August 16th, 2005, 11:58 PM
To draw circle is very easy:

void CMyEllipseShape::CreateEllipse(CRect &rcPos)
{
double dSqrt2 = (double)sqrt(2.0);
double dRadius1 = (double)rcPos.Width() / 2.0;
double dRadius2 = (double)rcPos.Height() / 2.0;
double dCenterX = dRadius1 + (double)rcPos.left;
double dCenterY = dRadius2 + (double)rcPos.top;

// Right
m_lpShapePoints[0].x = (long)(dRadius1/dSqrt2 + dCenterX);
m_lpShapePoints[0].y = (long)(dRadius2/dSqrt2 + dCenterY);

m_lpShapePoints[1].x = (long)(dRadius1*(8-dSqrt2)/6 + dCenterX);
m_lpShapePoints[1].y = (long)(dRadius2*(7*dSqrt2-8)/6 + dCenterY);

m_lpShapePoints[2].x = (long)(dRadius1*(8-dSqrt2)/6 + dCenterX);
m_lpShapePoints[2].y = (long)(-dRadius2*(7*dSqrt2-8)/6 + dCenterY);

m_lpShapePoints[3].x = (long)(dRadius1/dSqrt2 + dCenterX);
m_lpShapePoints[3].y = (long)(-dRadius2/dSqrt2 + dCenterY);

// Bottom
m_lpShapePoints[4].x = (long)(dRadius1*(7*dSqrt2-8)/6 + dCenterX);
m_lpShapePoints[4].y = (long)(-dRadius2*(8-dSqrt2)/6 + dCenterY);

m_lpShapePoints[5].x = (long)(-dRadius1*(7*dSqrt2-8)/6 + dCenterX);
m_lpShapePoints[5].y = (long)(-dRadius2*(8-dSqrt2)/6 + dCenterY);

m_lpShapePoints[6].x = (long)(-dRadius1/dSqrt2 + dCenterX);
m_lpShapePoints[6].y = (long)(-dRadius2/dSqrt2 + dCenterY);

// Left
m_lpShapePoints[7].x = (long)(-dRadius1*(8-dSqrt2)/6 + dCenterX);
m_lpShapePoints[7].y = (long)(-dRadius2*(7*dSqrt2-8)/6 + dCenterY);

m_lpShapePoints[8].x = (long)(-dRadius1*(8-dSqrt2)/6 + dCenterX);
m_lpShapePoints[8].y = (long)(dRadius2*(7*dSqrt2-8)/6 + dCenterY);

m_lpShapePoints[9].x = (long)(-dRadius1/dSqrt2 + dCenterX);
m_lpShapePoints[9].y = (long)(dRadius2/dSqrt2 + dCenterY);

// Top
m_lpShapePoints[10].x = (long)(-dRadius1*(7*dSqrt2-8)/6 + dCenterX);
m_lpShapePoints[10].y = (long)(dRadius2*(8-dSqrt2)/6 + dCenterY);

m_lpShapePoints[11].x = (long)(dRadius1*(7*dSqrt2-8)/6 + dCenterX);
m_lpShapePoints[11].y = (long)(dRadius2*(8-dSqrt2)/6 + dCenterY);

m_lpShapePoints[12].x = (long)(dRadius1/dSqrt2 + dCenterX);
m_lpShapePoints[12].y = (long)(dRadius2/dSqrt2 + dCenterY);
}

Then you can call the following codes to draw it:

pDC->BeginPath();

pDC->PolyBezier(points,nCount);
if( ( points[0].x != points[nCount-1].x ) ||
( points[0].y != points[nCount-1].y ) )
{
pDC->MoveTo( points[nCount-1].x, points[nCount-1].y );
pDC->LineTo( points[0].x, points[0].y );
}
pDC->EndPath();
pDC->StrokeAndFillPath();

Jack

---------------------------------------------------------------------------------
XD++ MFC/C++ Flow/Diagram Library (Source Code Kit) -- http://www.********.net