Public Class Form1 ''' <summary>正多角形の頂点座標を取得します。</summary> ''' <param name="number">頂点数</param> ''' <param name="radius">半径</param> ''' <param name="origin">中心座標</param> ''' <param name="radian">開始角</param> Public Shared Function GetRegularPolygonF(number As Integer, radius As Single, origin As PointF, Optional radian As Single = 0F) As PointF() If number < 3 Then Throw New ArgumentOutOfRangeException("number", number, "3 以上を指定してください。") End If Dim vertex(number - 1) As PointF Dim theta As Double = Math.PI * 2.0R / number For n = 0 To number - 1 Dim d As Double = n * theta + radian vertex(n).X = origin.X + CSng(radius * Math.Cos(d)) vertex(n).Y = origin.Y + CSng(radius * Math.Sin(d)) Next Return vertex End Function Private number As Integer = 12 Private radius As Single = 120.0F Private center As New PointF(150.0F, 200.0F) Private points As PointF() = {} Private isLoading As Boolean = True Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load isLoading = True points = GetRegularPolygonF(number, radius, center) ListBox1.DataSource = points TextBox1.Text = number.ToString() TextBox2.Text = radius.ToString("F2") TextBox3.Text = center.X.ToString("F2") TextBox4.Text = center.Y.ToString("F2") isLoading = False End Sub Private Sub UpdateCoordinate() Try number = CInt(TextBox1.Text) radius = CSng(TextBox2.Text) center.X = CSng(TextBox3.Text) center.Y = CSng(TextBox4.Text) points = GetRegularPolygonF(number, radius, center) Catch ex As Exception points = New PointF() {} center = PointF.Empty End Try End Sub Private Sub TextBoxes_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged, TextBox2.TextChanged, TextBox3.TextChanged, TextBox4.TextChanged If isLoading Then Return End If UpdateCoordinate() ListBox1.DataSource = points PictureBox1.Invalidate() End Sub Private Sub PictureBox1_Paint(sender As Object, e As PaintEventArgs) Handles PictureBox1.Paint Try e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.HighQuality e.Graphics.PixelOffsetMode = Drawing2D.PixelOffsetMode.HighQuality e.Graphics.Clear(Color.White) Using redPen As New Pen(Brushes.Red, 3) e.Graphics.DrawPolygon(redPen, points) '正多角形 End Using '中心座標 e.Graphics.FillEllipse(Brushes.Black, center.X - 2, center.Y - 2, 5, 5) Catch ex As Exception e.Graphics.Clear(Color.Yellow) End Try End Sub End Class