⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 threepcircle.vb

📁 苏金明编写的《用VB.NET和VC#.NET开发交互式CAD系统》一书的源代码
💻 VB
字号:
Imports System.Math
Imports System.Windows.Forms

Public Class ThreePCircle
    Inherits DrawCircle

    Private m_Point1, m_Point2, m_Point3 As PointF

    Public Property Point1() As PointF
        Get
            Return m_Point1
        End Get
        Set(ByVal Value As PointF)
            m_Point1 = Value
        End Set
    End Property

    Public Property Point2() As PointF
        Get
            Return m_Point2
        End Get
        Set(ByVal Value As PointF)
            m_Point2 = Value
        End Set
    End Property

    Public Property Point3() As PointF
        Get
            Return m_Point3
        End Get
        Set(ByVal Value As PointF)
            m_Point3 = Value
        End Set
    End Property

    Public ReadOnly Property Center() As PointF
        Get
            Return CircleCenter()
        End Get
    End Property

    Public ReadOnly Property Radius() As Single
        Get
            Return Sqrt((m_Point1.X - Center.X) * (m_Point1.X - Center.X) + _
                    (m_Point1.X - Center.X) * (m_Point1.X - Center.X))
        End Get
    End Property

    '无参构造函数
    Public Sub New()
    End Sub

    '构造函数,用已知的两点构造圆
    Public Sub New(ByVal p1 As PointF, ByVal p2 As PointF, ByVal p3 As PointF)
        m_Point1 = p1
        m_Point2 = p2
        m_Point3 = p3
    End Sub

    Private Function CircleCenter() As PointF
        Dim x0 As Single, y0 As Single
        Dim x1 As Single = m_Point1.X
        Dim y1 As Single = m_Point1.Y
        Dim x2 As Single = m_Point2.X
        Dim y2 As Single = m_Point2.Y
        Dim x3 As Single = m_Point3.X
        Dim y3 As Single = m_Point3.Y
        Dim A1 As Single = x1 - x3
        Dim B1 As Single = y1 - y3
        Dim A2 As Single = x2 - x3
        Dim B2 As Single = y2 - y3
        Dim C1 As Single = (x1 * x1 - x3 * x3 + y1 * y1 - y3 * y3) / 2
        Dim C2 As Single = (x2 * x2 - x3 * x3 + y2 * y2 - y3 * y3) / 2
        Dim D As Single = A1 * B2 - A2 * B1
        If D = 0 Then
            MessageBox.Show("找不到圆心。")
        Else
            x0 = (C1 * B2 - C2 * B1) / D
            y0 = (A1 * C2 - A2 * C1) / D
        End If
        Return (New PointF(x0, y0))
    End Function

    '绘圆
    Public Overrides Sub Draw(ByVal g As Graphics)
        g.DrawEllipse(Pens.Red, Center.X - Radius, _
              Center.X - Radius, Radius * 2, Radius * 2)
    End Sub

End Class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -