I am working with some simple code to draw a hexagon and I am getting unexpected results.
Code follows:
Public Class Form1
Dim bm As New Bitmap(640, 480)
Dim bmg As Graphics = Graphics.FromImage(bm)
Dim p As Pen = New Pen(Color.Black)
Dim sb As SolidBrush = New SolidBrush(Color.Black)
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
DrawHex(80, 50)
End Sub
Public Sub DrawHex(x As Integer, y As Integer)
Dim side As Integer = 25 '' the length of the side of a hex
Dim ShortSide As Single = Convert.ToSingle(System.Math.Sin(30 * System.Math.PI / 180) * side)
Dim LongSide As Single = Convert.ToSingle(System.Math.Cos(30 * System.Math.PI / 180) * side)
Dim Points(6) As PointF
Points(0) = New PointF(x, y)
Points(1) = New PointF(x + side, y)
Points(2) = New PointF(x + side + ShortSide, y + LongSide)
Points(3) = New PointF(x + side, y + LongSide + LongSide)
Points(4) = New PointF(x, y + LongSide + LongSide)
Points(5) = New PointF(x - ShortSide, y + LongSide)
bmg.DrawPolygon(p, Points)
End Sub
Private Sub Form1_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
e.Graphics.DrawImage(bm, New Point(10, 10))
End Sub
End Class
Five points of the hexagon are fine. It’s the last point that isn’t drawing correctly and I don’t understand why:

“ShortSide” and “LongSide” represent the lines of right triangles that are outside the hexagon. I’m pretty sure that the mathematics are right and I feel like I’m missing something obvious.
Thank you!
Arrays are zero based. Change it to:
will get you six points. Your last point (#7) was defaulting to (0, 0).