16,554
社区成员
发帖
与我相关
我的任务
分享
Public Class DrawFivePointed
'定义个直线方程的结构
Private Structure LinearElements
Dim A As Double
Dim B As Double
Dim C As Double
End Structure
'获得直线的方程A,B,C的值
Private Function LinearEquation(ByVal P1 As Point, ByVal P2 As Point) As LinearElements
Dim Line As New LinearElements
Dim a, b, c As Double
Dim x1 As Double = P1.X
Dim y1 As Double = P1.Y
Dim x2 As Double = P2.X
Dim y2 As Double = P2.Y
a = y2 - y1
b = x1 - x2
c = (x2 - x1) * y1 - (y2 - y1) * x1
If b < 0 Then
a = -1 * a
b = -1 * b
c = -1 * c
Else
If b = 0 And a < 0 Then
a = -1 * a
c = -1 * c
End If
End If
Line.A = a
Line.B = b
Line.C = c
Return Line
End Function
'获得两条直线的焦点坐标.
Private Function LineFocus(ByVal Line1 As LinearElements, ByVal Line2 As LinearElements) As Point
Dim Focus As Point
Dim A1, A2, B1, B2, C1, C2, M As Double
A1 = Line1.A
A2 = Line2.A
B1 = Line1.B
B2 = Line2.B
C1 = Line1.C
C2 = Line2.C
M = A1 * B2 - A2 * B1
If M = 0 Then
Focus.X = 0
Focus.Y = 0
Return Focus
End If
Focus.X = (C2 * B1 - C1 * B2) / M
Focus.Y = (C1 * A2 - C2 * A1) / M
Return Focus
End Function
'根据输入的五角星中心坐标、半径、起始角度、颜色绘制一个五角星。
Public Sub DrawFivePointedStar(ByVal CentrePoint As Point, _
ByVal Diameter As Int32, ByVal StarAngle As Double, _
ByVal Dc As Graphics, ByVal [Color] As Color)
Dim po(9) As Point
Dim Zx As Point = CentrePoint
Dim R As Int32 = Diameter / 2
Dim Jl As Int32 = 360 / 5
Dim Hd As Double = System.Math.PI / 180
Dim Qj As Double = StarAngle
For xh As Int16 = 0 To 4
po(xh).Y = System.Math.Sin(Jl * xh * Hd + Qj) * R + Zx.Y
po(xh).X = System.Math.Cos(Jl * xh * Hd + Qj) * R + Zx.X
Next
Dim G As Graphics = Dc
Dim Wzx(4) As LinearElements
Wzx(0) = LinearEquation(po(0), po(2))
Wzx(1) = LinearEquation(po(0), po(3))
Wzx(2) = LinearEquation(po(1), po(3))
Wzx(3) = LinearEquation(po(1), po(4))
Wzx(4) = LinearEquation(po(2), po(4))
po(5) = LineFocus(Wzx(0), Wzx(3))
po(6) = LineFocus(Wzx(0), Wzx(2))
po(7) = LineFocus(Wzx(1), Wzx(3))
po(8) = LineFocus(Wzx(2), Wzx(4))
po(9) = LineFocus(Wzx(1), Wzx(4))
Dim Fpo(9) As Point
Fpo(0) = po(0)
Fpo(1) = po(5)
Fpo(2) = po(1)
Fpo(3) = po(6)
Fpo(4) = po(2)
Fpo(5) = po(8)
Fpo(6) = po(3)
Fpo(7) = po(9)
Fpo(8) = po(4)
Fpo(9) = po(7)
Dim Pen As New Drawing.SolidBrush(Color)
G.FillPolygon(Pen, Fpo)
End Sub
End Class