Question

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

All sides and angles need to be equal.

Thanks

No correct solution

OTHER TIPS

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

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)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top