像春天一样在c#中绘图
如何使用c#绘图类绘制弹簧形状
How to draw the spring like shape using c# drawing class
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
如何使用c#绘图类绘制弹簧形状
How to draw the spring like shape using c# drawing class
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(2)
首先,您需要考虑一个代表弹簧的公式。你可以画一个圆,当你绕着它转时,让 X 增加一点。例如:
将
i
变量视为时间,将结果x
和y
视为要绘制的坐标;你会小步地走过春天的小路。然后,您可以创建一个新的位图并在这些坐标上使用 SetPixel 方法,然后在表单的 OnPaint 方法中绘制位图它。
如果您擅长数学(我不是:P),您可能只能在位图中绘制像素 - 上面的示例并不能解决
i
i.First of all you'd need to think of a formula that would represent the spring. You could draw a circle and as you're going around it, let the X increase a bit. For instance:
See the
i
variable there as time, and the resultx
andy
the coordinates to draw; you'd traverse the path of the spring in small steps.You could then create a new
Bitmap
and use theSetPixel
method on those coordinates, and in theOnPaint
method of your form, draw the bitmap on it.If you're any good with math (I'm not :P) you might be able to only plot pixels inside the bitmap - the above example doesn't solve the problem of the minimum and maximum values for
i
.这与其说是一个 C# 问题,不如说是一个数学问题。您想要的是为您想要绘制的曲线导出参数方程。
然后,按照一定的间隔和一定的步长,用参数方程的值填充 Point 对象的数组(步长越小,最终的图形看起来就越像实际的形状)。然后就可以使用g.DrawLines(MSDN: DrawLines)来绘制曲面上的实际曲线。
通过修改Pen对象的参数,可以编辑线条的宽度、颜色等属性。
您的实际代码如下所示:
This is more of a math problem than a C# one. What you want is to derive a Parametric equation for the curve you wish to draw.
With that go and fill an array of Point objects with values for the parametric equation on a certain interval with a certain step (the smaller the step the more the final drawing will look like the actual shape). Then you can use g.DrawLines (MSDN: DrawLines) to draw the actual curve on a surface.
You can edit the width, color and other properties of the line by modifying parameters of the Pen object.
Your actual code would look like this: