在vb.net中绘制七边形

发布于 2024-10-27 01:10:14 字数 63 浏览 5 评论 0原文

有谁有可以在vb.net中绘制等边七边形的代码吗?

所有边和角都必须相等。

谢谢

Does anyone have any code that can draw an equilateral septagon in vb.net?

All sides and angles need to be equal.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

往事风中埋 2024-11-03 01:10:14

不,但如果您认为钟面有 60 分钟,则每 8.5 分钟标记 7 边形的一个点。

No, but if you think of a clock face with 60 minutes, each 8.5 minutes marks one point of your 7-sided shape.

盛装女皇 2024-11-03 01:10:14

这是一个绘制指定边数的正多边形的函数:

Sub poly(ByVal center As PointF, ByVal radius As Double, ByVal nSides As Integer, ByVal g As Graphics)

Dim pts(nSides) As PointF
Dim Angle As Double = Math.PI * 2 / nSides
Dim i As Integer
Dim a As Double

a = Math.PI / 2 ' first point on top
For i = 0 To UBound(pts)
  pts(i) = center + New Point(radius * Math.Cos(a), -radius * Math.Sin(a))
  a = a + Angle
  Next i

g.DrawPolygon(Pens.DarkGreen, pts)
End Sub

要调用它,请在要绘制的位置设置一个图形对象。例如,要在 PictureBox1 中绘制它,您可以这样调用它:

Dim g As Graphics

PictureBox1.Image = New Bitmap(PictureBox1.Width, PictureBox1.Height) ' new bitmap
g = Graphics.FromImage(PictureBox1.Image) ' assign graphics object to g
g.FillRectangle(Brushes.White, 0, 0, PictureBox1.Width, PictureBox1.Height) ' white background
' draw 7-sided polygon in the center of the picturebox
poly(New PointF(PictureBox1.Width / 2, PictureBox1.Height / 2), PictureBox1.Height / 3, 7, g)

Here is a function to draw a regular polygon of specified number of sides:

Sub poly(ByVal center As PointF, ByVal radius As Double, ByVal nSides As Integer, ByVal g As Graphics)

Dim pts(nSides) As PointF
Dim Angle As Double = Math.PI * 2 / nSides
Dim i As Integer
Dim a As Double

a = Math.PI / 2 ' first point on top
For i = 0 To UBound(pts)
  pts(i) = center + New Point(radius * Math.Cos(a), -radius * Math.Sin(a))
  a = a + Angle
  Next i

g.DrawPolygon(Pens.DarkGreen, pts)
End Sub

To call it, setup a graphics object where you want it drawn. For example, to draw it in PictureBox1, you could call it like this:

Dim g As Graphics

PictureBox1.Image = New Bitmap(PictureBox1.Width, PictureBox1.Height) ' new bitmap
g = Graphics.FromImage(PictureBox1.Image) ' assign graphics object to g
g.FillRectangle(Brushes.White, 0, 0, PictureBox1.Width, PictureBox1.Height) ' white background
' draw 7-sided polygon in the center of the picturebox
poly(New PointF(PictureBox1.Width / 2, PictureBox1.Height / 2), PictureBox1.Height / 3, 7, g)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文