在GDI +中画一个圆 [英] Draw a Circle in GDI+

查看:171
本文介绍了在GDI +中画一个圆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在gdi +中绘制圆,我想使用DrawLine函数
我知道公式是x ^ 2 + Y ^ 2 = r ^ 2
((实际上我的数学很差!))

但是我该如何按计时器刻度圈呢??
我的意思是,这只是时间问题而已
(例如,每秒钟绘制一个直径的圆)
最后您看到一个彩色的圆圈.


请发布摘要代码.:rose:
我有这样的东西

how can I draw a circle in gdi+ , I wanna use DrawLine function
I know the formula is x^2+Y^2=r^2
((actually my math was weak!))

but how can i make a circle by timer tick ??
I mean it draw the circle by a matter of time
(for example by each second draw one diameter of the circle)
at last you see a colored circle .


please post snippet code .:rose:
I have something like this

private void timer1_Tick(object sender, EventArgs e)
{

Graphics gr;
            
            gr = this.panel1.CreateGraphics();

            if ((Math.Pow(x, 2.0) + Math.Pow(y, 2.0)) == Math.Pow(4, 2.0))
            {
                gr.DrawLine(Pens.Blue, x1, y2, 200, 200);
            }
x1+=10;
y2+=10;
}

推荐答案

我不确定为什么要使用计时器进行绘制,但是如果它是一个圆,则由于某种原因,您不想使用Graphics :: DrawEllipse方法,则应该先确定参数方程式(单击 [ ^ ])

我拒绝让您重用代码,因为我认为您可以自己实施这种特殊的练习,从而从中受益.这是这样做的方法:

1.圆的参数方程为:
I''m not sure why you are using a timer to draw, but if it is a circle you want, and for some reason you do not want to use the Graphics::DrawEllipse methot, than you should deffinately look at parametric equations first (Click[^])

I refuse to give you a redy to use code, as I think you can benefit from implementing this particullar exercise yourself. This is the way to do it:

1. The parametric equation for a circle is:
x = a * cos(t)
y = a * sin(t) 


半径在哪里

2.使用计时器,您必须增加参数t的值.这实际上是以弧度为单位的角度,但是您稍后可以阅读.
重要的是,通过更改值,您可以得出下一个要点.请记住,增量值必须足够小,否则最终将绘制多边形,而不是圆形.好吧,无论如何,您都可以绘制一个多边形-但是使用小步骤,至少可以使它看起来像一个圆形:)

3.每次增加t都会得到x和y的新值-这是圆上的当前点.通过从上一个点到当前点画一条线,就可以画出圆.

4.开始时,t应该等于0

5.达到t == 2 * PI应该使您整整一圈!

希望能对您有所帮助-让我知道如何进行:)



要回答您的问题的第二个修订版:


where a is the radious

2. Using the timer you have to increment the value of t - the parameter. This actually is the angle in radians, but you can read about that later.
The important thing is that by changing the value you get the next point to draw. Remember that the increment value needs to be small enough, otherwise you will end up drawing a polygon, not a circle. Well you draw a polygon anyway - but using small steps you can at least make it look like a circle :)

3. Each time you increment t you get the new values of x and y - this is the current point on your circle. By drawing a line from the previous point to the current point you draw the circle.

4. t should equal 0 when you start

5. reaching t == 2 * PI should get you a full circle!

Hope this helps - let me know how it goes :)



To answer the second revision of your question:

"but how can i make a circle by timer tick ??
I mean it draw the circle by a matter of time
(for example by each second draw one diameter of the circle)
at last you see a colored circle ."



我从您的编辑中猜测,您需要的是一种通过圆圈表示的进度指示器.在这种情况下,我*强烈*建议您使用以下功能:



I''m guessing from your edit that what you need is a kind of a progress indicator by means of a circle. In that case I *strongly* suggest you use the following function:

Graphics.FillPie( Brushes.Green, myRectangle, 0, (float)( 360 * ElapsedTime ) / MaxTime )



其中:



Where:

myRectangle is the area in which the part of the circle will be drawn
ElapsedTime is the time that passed since the drawing of the circle began
MaxTime is the point in time when the circle should be fully drawn



如果您仍然想使用线来绘制整个圆-我的第一个答案仍然适用-稍作修改-您可以将线从圆心绘制到新计算的点,而不是先前绘制的点.但是请相信我-这种方法并不优雅,可能看起来很难看.想想FillPie方法吧!



If you still want to use lines to draw the full circle - my first answer still applies - with small modifications - you draw the line from the center of the circle to the newly calculated point, and not to the previously painted point. But trust me - this method is not elegant and will probably look ugly. Think about the FillPie method instead!


nimanaqipoor写道:
nimanaqipoor wrote:

我如何通过计时器绕圈?

how can i make a circle by timer ?



那没有任何意义.请编辑您的问题以阐明您的意思.



That doesn''t make any sense. Please edit your question to clarify what you mean.


这篇关于在GDI +中画一个圆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆