CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
山寨机中的战斗机! 程序优化工程师到底对IT界有没有贡献
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  VC/MFC >  图形处理/算法

想请教一下用vc画椭圆的算法

楼主byasx()2002-03-29 23:11:34 在 VC/MFC / 图形处理/算法 提问

最好详细点小弟很菜 问题点数: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

相关问题

  • 求椭圆算法
  • 【求助】虚线[宽画笔]画椭圆的算法!
  • 椭圆公章的算法
  • 求解算法,在客户区画一个椭圆,怎样使椭圆围绕中心点旋转呢?
  • 求标准c下画线,画椭圆,填充,显示汉字(hzk16)的基本算法
  • image1.canvas.ellipse(),画椭圆
  • VC++ Tab order算法
  • 有没有椭圆曲线算法方面的资料?
  • 各位高人,帮我一下,求椭圆的算法
  • 椭圆弧算法的rx,ry代表什么?

关键词

  • ps
  • 椭圆
  • ptstart
  • etobconst
  • penblue
  • ptend
  • pie
  • blue
  • clock
  • pdc

得分解答快速导航

  • 帖主:byasx
  • mrh123
  • mrh123

相关链接

  • Visual C++类图书
  • Visual C++类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo