Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8404755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T22:40:52+00:00 2026-06-09T22:40:52+00:00

I am working with some simple code to draw a hexagon and I am

  • 0

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:

enter image description here

“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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T22:40:54+00:00Added an answer on June 9, 2026 at 10:40 pm

    Arrays are zero based. Change it to:

    Dim Points(5) As PointF
    

    will get you six points. Your last point (#7) was defaulting to (0, 0).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some really simple code that's just not working: int[] manualPixels = new
So I'm just working on some simple arithmetic code. Here's what I got: echo
I'm trying to get some simple code working to log the pitch, roll, and
So I have some simple code but it seems to not be working.. any
I am working on some simple object-oriented code in MATLAB. I am trying to
I am working on some simple form validation and need some assistance. Basically, I
I am currently working on some simple custom allocators in c++ which generally works
I am working though some simple DX tutorials, and have hit an early snag.
The project I'm working on needs some simple audit logging for when a user
I'm working on a simple GUI Python script to do some simple tasks on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.