想请教一下用vc画椭圆的算法
最好详细点小弟很菜 问题点数:50、回复次数:4Top
1 楼mrh123(先郁闷到2006年再说)回复于 2002-03-29 23:20:54 得分 20
用CDC类的Pie()函数。
CDC* pDC;
BOOL Pie( LPCRECT lpRect, POINT ptStart, POINT ptEnd );
Example:pDC->Pie(rect,ptstart,ptend);
其中rect为包围椭圆的矩形,ptstart和ptend分别为起点和重点,如果ptstart == ptend,那么就是椭圆,否则为扇形,方向为逆时针。Top
2 楼mrh123(先郁闷到2006年再说)回复于 2002-03-29 23:21:47 得分 30
如果你有MSDN,那有现成的例子,如下:
void CCurvesView::OnDraw(CDC* pDC)
{
// Fill the client area with a simple pie chart. A
// big blue slice covers 75% of the pie, from
// 6 o'clock to 3 o'clock. This portion is filled
// with blue and has a blue edge. The remaining 25%
// is filled with a red, diagonal hatch and has
// a red edge.
// Get the client area.
CRect rectClient;
GetClientRect(rectClient);
// Make a couple of pens and similar brushes.
CPen penBlue, penRed;
CBrush brushBlue, brushRed;
CBrush* pOldBrush;
CPen* pOldPen;
brushBlue.CreateSolidBrush(RGB(0, 0, 255));
brushRed.CreateHatchBrush(HS_FDIAGONAL, RGB(255, 0, 0));
penBlue.CreatePen(PS_SOLID | PS_COSMETIC, 1, RGB(0, 0, 255));
penRed.CreatePen(PS_SOLID | PS_COSMETIC, 1, RGB(255, 0, 0));
// Draw from 3 o'clock to 6 o'clock, counterclockwise,
// in a blue pen with a solid blue fill.
pOldPen = pDC->SelectObject(&penBlue);
pOldBrush = pDC->SelectObject(&brushBlue);
pDC->Pie(rectClient,
CPoint(rectClient.right, rectClient.CenterPoint().y),
CPoint(rectClient.CenterPoint().x, rectClient.right));
// Draw the remaining quarter slice from 6 o'clock
// to 3 o'clock, counterclockwise, in a red pen with
// the hatched brush.
pDC->SelectObject(&penRed);
pDC->SelectObject(&brushRed);
// Same parameters, but reverse start and end points.
pDC->Pie(rectClient,
CPoint(rectClient.CenterPoint().x, rectClient.right),
CPoint(rectClient.right, rectClient.CenterPoint().y));
// Restore the previous pen.
pDC->SelectObject(pOldPen);
}
Top
3 楼mrh123(先郁闷到2006年再说)回复于 2002-03-29 23:22:49 得分 0
void CCurvesView::OnDraw(CDC* pDC)
{
// Fill the client area with a simple pie chart. A
// big blue slice covers 75% of the pie, from
// 6 o'clock to 3 o'clock. This portion is filled
// with blue and has a blue edge. The remaining 25%
// is filled with a red, diagonal hatch and has
// a red edge.
// Get the client area.
CRect rectClient;
GetClientRect(rectClient);
// Make a couple of pens and similar brushes.
CPen penBlue, penRed;
CBrush brushBlue, brushRed;
CBrush* pOldBrush;
CPen* pOldPen;
brushBlue.CreateSolidBrush(RGB(0, 0, 255));
brushRed.CreateHatchBrush(HS_FDIAGONAL, RGB(255, 0, 0));
penBlue.CreatePen(PS_SOLID | PS_COSMETIC, 1, RGB(0, 0, 255));
penRed.CreatePen(PS_SOLID | PS_COSMETIC, 1, RGB(255, 0, 0));
// Draw from 3 o'clock to 6 o'clock, counterclockwise,
// in a blue pen with a solid blue fill.
pOldPen = pDC->SelectObject(&penBlue);
pOldBrush = pDC->SelectObject(&brushBlue);
pDC->Pie(rectClient,
CPoint(rectClient.right, rectClient.CenterPoint().y),
CPoint(rectClient.CenterPoint().x, rectClient.right));
// Draw the remaining quarter slice from 6 o'clock
// to 3 o'clock, counterclockwise, in a red pen with
// the hatched brush.
pDC->SelectObject(&penRed);
pDC->SelectObject(&brushRed);
// Same parameters, but reverse start and end points.
pDC->Pie(rectClient,
CPoint(rectClient.CenterPoint().x, rectClient.right),
CPoint(rectClient.right, rectClient.CenterPoint().y));
// Restore the previous pen.
pDC->SelectObject(pOldPen);
}
Top
4 楼wuzhibiao(流氓兔儿)回复于 2002-03-29 23:24:02 得分 0
BOOL Ellipse( int x1, int y1, int x2, int y2 );
BOOL Ellipse( LPCRECT lpRect );
Return Value
Nonzero if the function is successful; otherwise 0.
Parameters
x1
Specifies the logical x-coordinate of the upper-left corner of the ellipse’s bounding rectangle.
y1
Specifies the logical y-coordinate of the upper-left corner of the ellipse’s bounding rectangle.
x2
Specifies the logical x-coordinate of the lower-right corner of the ellipse’s bounding rectangle.
y2
Specifies the logical y-coordinate of the lower-right corner of the ellipse’s bounding rectangle.
lpRect
Specifies the ellipse’s bounding rectangle. You can also pass a CRect object for this parameter.
Remarks
Draws an ellipse. The center of the ellipse is the center of the bounding rectangle specified by x1, y1, x2, and y2, or lpRect. The ellipse is drawn with the current pen, and its interior is filled with the current brush.
The figure drawn by this function extends up to, but does not include, the right and bottom coordinates. This means that the height of the figure is y2 – y1 and the width of the figure is x2 – x1.
If either the width or the height of the bounding rectangle is 0, no ellipse is drawn
用上面的函数
Top
5 楼hnyyy(前进)回复于 2002-03-29 23:38:07 得分 0
你是说画任意方向的椭圆吧?用PolyBezier(...)绘制速度很快
下面的代码没有优化,供参考
double A=...;//长半轴
double B=...;//短半轴
double F=...;//角度
x,y是中点;用的是MM_LOMETRIC
CPoint p[13],p1[13];
const double EToBConst = 0.2761423749154;
double c=sin(F);double d=cos(F);
CSize offset((int)(2*A* EToBConst), (int)(2*B * EToBConst));
p[0].x =p[1].x =p[11].x = p[12].x = int(-A);
p[5].x =p[6].x = p[7].x = int(A);
p[2].x = p[10].x = - offset.cx;
p[4].x = p[8].x = offset.cx;
p[3].x = p[9].x = 0;
p[2].y = p[3].y = p[4].y =int( B);
p[8].y = p[9].y = p[10].y = int(-B);
p[7].y = p[11].y = -offset.cy;
p[1].y = p[5].y = offset.cy;
p[0].y = p[12].y = p[6].y = 0;
for(int i=0;i<=12;i++)//坐标旋转公式
{
p1[i].x=int(x+p[i].x*d+p[i].y*c);
p1[i].y=int(y-(-p[i].x*c+p[i].y*d));
}
pDC->PolyBezier(p1,13);Top




