Public Class Form1
Private Function Cos(ByVal pAngel As Double, ByVal pRadius As Double) As Double
Dim rad As Double = 2 * Math.PI * (pAngel / 360)
Return Math.Cos(rad) * pRadius
End Function
Private Function Sin(ByVal pAngel As Double, ByVal pRadius As Double) As Double
Dim rad As Double = 2 * Math.PI * (pAngel / 360)
Return Math.Sin(rad) * pRadius
End Function
''' <summary>
''' วาดสามเหลี่ยม
''' </summary>
''' <param name="pCenterX">จุดกึ่งกลาง x</param>
''' <param name="pCenterY">จุดกึ่งกลาง y</param>
''' <param name="pRadius">รัศมีสามเหลี่ยม</param>
''' <param name="pStartAngel">มุมเริ่มต้น</param>
''' <returns>รูบสามเหลี่ยม</returns>
''' <remarks></remarks>
'''
Private Function makeTriangel(ByVal pCenterX As Integer, ByVal pCenterY As Integer, ByVal pRadius As Integer, ByVal pStartAngel As Integer) As Bitmap
Dim p0 As New Point(pCenterX + Cos(pStartAngel, pRadius), pCenterY + Sin(pStartAngel, pRadius))
Dim p1 As New Point(pCenterX + Cos(pStartAngel + 120, pRadius), pCenterY + Sin(pStartAngel + 120, pRadius))
Dim p2 As New Point(pCenterX + Cos(pStartAngel + 240, pRadius), pCenterY + Sin(pStartAngel + 240, pRadius))
Dim bmp As New Bitmap(Me.Width, Me.Height)
Dim g As Graphics = Graphics.FromImage(bmp)
g.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
g.DrawEllipse(New Pen(Color.Gray, 5), pCenterX - pRadius \ 2, pCenterY - pRadius \ 2, pRadius, pRadius)
g.DrawEllipse(New Pen(Color.Gray, 5), pCenterX - pRadius, pCenterY - pRadius, pRadius * 2, pRadius * 2)
g.DrawLines(New Pen(Color.Red, 5), New Point() {p0, p1, p2, p0})
Return bmp
End Function
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Me.BackgroundImage = makeTriangel(Me.Width \ 2, Me.Height \ 2, 150, 180)
End Sub
End Class