Click here to Skip to main content
15,748,477 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I want to draw a line that has a hexagon at the end. with mouse move event. I can draw a circle or a square, but not a hexagon!

What I have tried:

I want draw a line that have a hexagon at the end
Updated 31-Jan-23 23:47pm
Richard MacCutchan 29-May-22 3:40am    
You have not explained what the problem is. Drawing a hexagon is a matter of drawing six line segments each of the same length. At the end of each segment you need to alter direction by 120 degrees in a clockwise direction. At the end of the sixth segment you should have a closed hexagon.
Greg Utas 29-May-22 8:25am    
And should a projection of the line (a) bisect the hexagon through two vertices, (b) through two edges, (c) form one of the hexagon's sides, or (d) I don't care as long as it's a hexagon! Decisions, decisions. :)
Richard MacCutchan 29-May-22 8:32am    
My thoughts exactly. :)
Although I have just spent the last half hour studying Hexagon[^].
moshaveran 29-May-22 9:16am    
I know how draw a hexagon. with this codes:
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(5) 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

but my problem is that I need draw a line that have a hexagon at the end.
In a new post, I will show a picture of what I want
Richard MacCutchan 29-May-22 9:28am    
That is just a question of drawing a line and drawing a hexagon, and connecting them at some common point.

1 solution

You can draw a line: I know that because your other questions indicate it.
You can draw a hexagon: you have said so.

So ... draw a line. Use one of the end points as the center of the hexagon and offset the other six points you need from that: simple geometry using the angles which depend on the orientation of the hexagon.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900