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

📄 form1.vb

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

Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows 窗体设计器生成的代码 "

    Public Sub New()
        MyBase.New()

        '该调用是 Windows 窗体设计器所必需的。
        InitializeComponent()

        '在 InitializeComponent() 调用之后添加任何初始化

    End Sub

    '窗体重写处置以清理组件列表。
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Windows 窗体设计器所必需的
    Private components As System.ComponentModel.IContainer

    '注意:以下过程是 Windows 窗体设计器所必需的
    '可以使用 Windows 窗体设计器修改此过程。
    '不要使用代码编辑器修改它。
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        components = New System.ComponentModel.Container()
        Me.Text = "Form1"
    End Sub

#End Region

    Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
        Dim g As Graphics = e.Graphics
        '定义转换矩阵
        Dim mat As New Matrix()
        mat.Translate(0, 0)
        '定义顶点,添加基数样条曲线到路径
        Dim point1 As New Point(10, 100)
        Dim point2 As New Point(80, 20)
        Dim point3 As New Point(150, 300)
        Dim point4 As New Point(200, 100)
        Dim point5 As New Point(300, 200)
        Dim point6 As New Point(500, 150)
        Dim points As Point() = {point1, point2, point3, point4, point5, point6}
        Dim gp As New GraphicsPath()
        gp.AddCurve(points)
        g.DrawPath(New Pen(Color.Black, 2), gp)
        '展平曲线
        gp.Flatten(mat, 5)
        '获得路径上的关键点
        Dim p() As PointF = gp.PathPoints
        '给出要与曲线求交的直线段
        Dim line1 As New CLine(New PointF(20, 400), New PointF(400, 50))
        line1.Draw(g, Pens.Blue)
        Dim interNum As Integer = -1
        Dim intersec As Single()
        Dim interPoints(5) As PointF
        Dim i As Integer
        '根据展平以后得到的多条直线段逐个与给定的直线段求交点
        '最终得到的交点即可看作给定直线段与曲线的交点
        For i = 0 To gp.PointCount - 2
            Dim line2 As New CLine(p(i), p(i + 1))
            intersec = LineLine(line1, line2)
            If intersec(0) > 0 Then
                interNum += 1
                interPoints(interNum) = New PointF(intersec(1), intersec(2))
            End If
        Next
        '用红色填充圆表示交点
        For i = 0 To interNum
            g.FillEllipse(Brushes.Red, interPoints(i).X - 3, interPoints(i).Y - 3, 6, 6)
        Next
    End Sub


End Class

⌨️ 快捷键说明

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