MFC如何画圆?

mei1977mei 2009-10-17 11:07:32
给定两个坐标x,y;然后在给定半径r;怎么画圆?
需要用到什么函数,具体怎么操作?
新手!
路过的朋友给个答案!
先谢谢!
...全文
6004 10 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
dkbrain 2009-10-18
  • 打赏
  • 举报
回复
 CDC *pDC;
pDC=GetDC();
CPen GreenPen(PS_SOLID,1,RGB(0,255,0)),*pOldPen;
pOldPen=pDC->SelectObject(&GreenPen); //选择画笔
int x1,x2,y1,y2;
pDC->Arc(CRect(x1,y1,x2,y2),CPoint(x1,y1),CPoint(x1,y1));
pDC->SelectObject(pOldPen);
GreenPen.DeleteObject();
ReleaseDC(pDC);


Arc()是用来画圆弧的,但是起始点为同一点,或弧度为360°的就是一个圆;
这个函数和Ellipse()相比而言,它不会用画刷填充圆内部区域,即画的图就是一个圆的曲线,内部仍是透明的,不会遮盖掉你其他的画图内容。
Arc()具体怎么用,建议看看MSDN
  • 打赏
  • 举报
回复
若给定坐标(x,y)是你所要画的圆上的任意一点,则根据半径r可画无数个圆,因为圆心有无数个;
若给定坐标(x,y)就是你要画的圆的圆心,那就只能画一个圆啦,你可以先根据圆心和半径确定出圆的外接矩形rect,再用pdc->Ellipse(&rect)画圆
luckyboy101 2009-10-18
  • 打赏
  • 举报
回复
CDC::Ellipse
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.

abc_aaa_012 2009-10-18
  • 打赏
  • 举报
回复
之前面试碰到过一个画图的题目:

题目大意是:两个同心圆半径分别是8和10Px(是不是cm我没印象啦)
然后是两圆差集部分(半径2cm的圆环背景颜色为蓝色),
然后再在圆心写一个字;
当时是做图象处理的题目;
我还以为让我写一个印章呢....
abc_aaa_012 2009-10-18
  • 打赏
  • 举报
回复
帮顶...
THCNC 2009-10-18
  • 打赏
  • 举报
回复
两个坐标+半径可以绘出2个圆。

目标,求圆心。求得圆心后就可以按照3楼的方法画圆。

1,先用两个坐标点计算出这两点的中点坐标和两点之间的距离(弦长)和角度(A)。
2,由半径和二分之一弦长求得三角形另一直角边长L.
3,以中点为基点,利用极坐标公式,将长度为L的点旋转(A+90)或者(A-90),算得2个圆心坐标。
4,求得圆心后就可以按照3楼的方法画圆。



Hiiishe 2009-10-17
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 jackyjkchen 的回复:]
不要学画图,过来人的建议
[/Quote]

1楼何解?
Hiiishe 2009-10-17
  • 打赏
  • 举报
回复
Eillipse(x-r, y-r, x+r, y+r);
快乐鹦鹉 2009-10-17
  • 打赏
  • 举报
回复
pDC->Ellipse
jackyjkchen 2009-10-17
  • 打赏
  • 举报
回复
不要学画图,过来人的建议

16,547

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • AIGC Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧