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

📄 form1.vb

📁 基于vb.net的autocad二次开发凸轮模型反求与3D动画模拟根据凸轮扫描位图反求3d模型模拟凸轮运动显示凸轮位移曲线。
💻 VB
📖 第 1 页 / 共 2 页
字号:

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 窗体设计器修改此过程。
    '不要使用代码编辑器修改它。
    Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents Button1 As System.Windows.Forms.Button
    Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
    Friend WithEvents Button2 As System.Windows.Forms.Button
    Friend WithEvents RadioButton1 As System.Windows.Forms.RadioButton
    Friend WithEvents RadioButton2 As System.Windows.Forms.RadioButton
    Friend WithEvents Button3 As System.Windows.Forms.Button
    Friend WithEvents Button4 As System.Windows.Forms.Button
    Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents Label4 As System.Windows.Forms.Label
    Friend WithEvents Button5 As System.Windows.Forms.Button
    Friend WithEvents Button6 As System.Windows.Forms.Button
    Friend WithEvents Label5 As System.Windows.Forms.Label
    Friend WithEvents TextBox3 As System.Windows.Forms.TextBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.PictureBox1 = New System.Windows.Forms.PictureBox()
        Me.Label1 = New System.Windows.Forms.Label()
        Me.Label2 = New System.Windows.Forms.Label()
        Me.Button1 = New System.Windows.Forms.Button()
        Me.TextBox1 = New System.Windows.Forms.TextBox()
        Me.Button2 = New System.Windows.Forms.Button()
        Me.RadioButton1 = New System.Windows.Forms.RadioButton()
        Me.RadioButton2 = New System.Windows.Forms.RadioButton()
        Me.Button3 = New System.Windows.Forms.Button()
        Me.Button4 = New System.Windows.Forms.Button()
        Me.TextBox2 = New System.Windows.Forms.TextBox()
        Me.Label3 = New System.Windows.Forms.Label()
        Me.Label4 = New System.Windows.Forms.Label()
        Me.Button5 = New System.Windows.Forms.Button()
        Me.Button6 = New System.Windows.Forms.Button()
        Me.Label5 = New System.Windows.Forms.Label()
        Me.TextBox3 = New System.Windows.Forms.TextBox()
        Me.SuspendLayout()
        '
        'PictureBox1
        '
        Me.PictureBox1.Location = New System.Drawing.Point(8, 8)
        Me.PictureBox1.Name = "PictureBox1"
        Me.PictureBox1.Size = New System.Drawing.Size(272, 224)
        Me.PictureBox1.TabIndex = 1
        Me.PictureBox1.TabStop = False
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(352, 24)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(64, 16)
        Me.Label1.TabIndex = 6
        Me.Label1.Text = "Label1"
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(352, 152)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(80, 48)
        Me.Label2.TabIndex = 7
        Me.Label2.Text = "Label2"
        '
        'Button1
        '
        Me.Button1.Location = New System.Drawing.Point(336, 248)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(104, 48)
        Me.Button1.TabIndex = 9
        Me.Button1.Text = "Button1"
        '
        'TextBox1
        '
        Me.TextBox1.Location = New System.Drawing.Point(344, 48)
        Me.TextBox1.Name = "TextBox1"
        Me.TextBox1.Size = New System.Drawing.Size(72, 21)
        Me.TextBox1.TabIndex = 10
        Me.TextBox1.Text = "TextBox1"
        '
        'Button2
        '
        Me.Button2.Location = New System.Drawing.Point(336, 312)
        Me.Button2.Name = "Button2"
        Me.Button2.Size = New System.Drawing.Size(104, 48)
        Me.Button2.TabIndex = 11
        Me.Button2.Text = "Button2"
        '
        'RadioButton1
        '
        Me.RadioButton1.Location = New System.Drawing.Point(336, 72)
        Me.RadioButton1.Name = "RadioButton1"
        Me.RadioButton1.Size = New System.Drawing.Size(120, 40)
        Me.RadioButton1.TabIndex = 12
        Me.RadioButton1.Text = "RadioButton1"
        '
        'RadioButton2
        '
        Me.RadioButton2.Location = New System.Drawing.Point(336, 120)
        Me.RadioButton2.Name = "RadioButton2"
        Me.RadioButton2.Size = New System.Drawing.Size(120, 24)
        Me.RadioButton2.TabIndex = 13
        Me.RadioButton2.Text = "RadioButton2"
        '
        'Button3
        '
        Me.Button3.Location = New System.Drawing.Point(72, 280)
        Me.Button3.Name = "Button3"
        Me.Button3.Size = New System.Drawing.Size(88, 32)
        Me.Button3.TabIndex = 14
        Me.Button3.Text = "Button3"
        '
        'Button4
        '
        Me.Button4.Location = New System.Drawing.Point(184, 280)
        Me.Button4.Name = "Button4"
        Me.Button4.Size = New System.Drawing.Size(80, 32)
        Me.Button4.TabIndex = 15
        Me.Button4.Text = "Button4"
        '
        'TextBox2
        '
        Me.TextBox2.Location = New System.Drawing.Point(72, 248)
        Me.TextBox2.Name = "TextBox2"
        Me.TextBox2.Size = New System.Drawing.Size(56, 21)
        Me.TextBox2.TabIndex = 16
        Me.TextBox2.Text = "TextBox2"
        '
        'Label3
        '
        Me.Label3.Location = New System.Drawing.Point(352, 200)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(80, 40)
        Me.Label3.TabIndex = 8
        Me.Label3.Text = "Label3"
        '
        'Label4
        '
        Me.Label4.Location = New System.Drawing.Point(16, 248)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(48, 16)
        Me.Label4.TabIndex = 17
        Me.Label4.Text = "Label4"
        '
        'Button5
        '
        Me.Button5.Location = New System.Drawing.Point(72, 328)
        Me.Button5.Name = "Button5"
        Me.Button5.Size = New System.Drawing.Size(88, 32)
        Me.Button5.TabIndex = 18
        Me.Button5.Text = "Button5"
        '
        'Button6
        '
        Me.Button6.Location = New System.Drawing.Point(184, 328)
        Me.Button6.Name = "Button6"
        Me.Button6.Size = New System.Drawing.Size(88, 32)
        Me.Button6.TabIndex = 19
        Me.Button6.Text = "Button6"
        '
        'Label5
        '
        Me.Label5.Location = New System.Drawing.Point(144, 248)
        Me.Label5.Name = "Label5"
        Me.Label5.Size = New System.Drawing.Size(80, 16)
        Me.Label5.TabIndex = 21
        Me.Label5.Text = "Label5"
        '
        'TextBox3
        '
        Me.TextBox3.Location = New System.Drawing.Point(224, 248)
        Me.TextBox3.Name = "TextBox3"
        Me.TextBox3.Size = New System.Drawing.Size(56, 21)
        Me.TextBox3.TabIndex = 20
        Me.TextBox3.Text = "TextBox3"
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.ClientSize = New System.Drawing.Size(480, 397)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Label5, Me.TextBox3, Me.Button6, Me.Button5, Me.Label4, Me.TextBox2, Me.Button4, Me.Button3, Me.RadioButton2, Me.RadioButton1, Me.Button2, Me.TextBox1, Me.Button1, Me.Label3, Me.Label2, Me.Label1, Me.PictureBox1})
        Me.Name = "Form1"
        Me.Text = "Form1"
        Me.ResumeLayout(False)

    End Sub

#End Region

    Dim Acadapp As AutoCAD.AcadApplication
    Dim XMouseDown, YMouseDown '获得鼠标在图片上单击点的X、Y 坐标
    Dim MouseDownpointsColor As Color '获得鼠标在图片上单击点的颜色
    Dim Xp(), Yp() As Integer '动态数组,存放图形内或外轮廓各点坐标
    Dim Mpoints As Integer  '存放图形内或外轮廓各点坐标点总数
    Dim solidObj() As AutoCAD.Acad3DSolid '三维造型实体结果。
    Dim Numcurves As Integer '平面图形内、外轮廓曲线总数
    Dim splineObj() As AutoCAD.AcadEntity '第Numcurves条轮廓曲线
    Dim OutlineDone As Boolean '布尔值,判断是否已经先单击外轮廓
    Dim I As Integer '临时变量

    '创建一个新的位图对象实例
    Dim myBitmap As New Bitmap(Application.StartupPath + "\凸轮.bmp")


    Dim solidObjT As AutoCAD.Acad3DSolid '凸轮实体
    Dim gCenterY(360) As Double '滚子中心y坐标
    Dim TCenter(2) As Double '凸轮转动中心
    Dim jg As Integer '凸轮转动间隔角度
    Dim Xzhou, Yzhou As AutoCAD.Acad3DSolid  '绘制显示滚子位移曲线的坐标轴




    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Me.Text = "实例16凸轮模型反求与3D动画模拟"

        Me.Label1.Text = "精度:"
        Me.Label2.Text = "第1步:单击外轮廓区域"
        Me.Label3.Text = "第2步:单击内轮廓区域"
        Me.Label4.Text = "偏置距e"
        Me.Label5.Text = "转动间隔角度"

        Me.TextBox1.Text = 15
        Me.TextBox2.Text = 20
        Me.TextBox3.Text = 10

        Me.RadioButton1.Text = "非均匀有理B样条曲线拟合"
        Me.RadioButton2.Text = "多义线拟合"
        Me.RadioButton1.Checked = True


        Me.Button1.Text = "第3步:三维模型反求显示"
        Me.Button2.Text = "图形增强处理(可选)"
        Me.Button3.Text = "加载滚子图形"
        Me.Button4.Text = "生成数据"
        Me.Button5.Text = "3D动画"
        Me.Button6.Text = "结束"

        '装载图片
        Me.PictureBox1.SizeMode = PictureBoxSizeMode.AutoSize
        Me.PictureBox1.Image = myBitmap

        OutlineDone = False

        Call 连接AutoCAD()


    End Sub

    Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown

        '获得鼠标在图片上单击点的X、Y 坐标
        XMouseDown = e.X
        YMouseDown = e.Y

        '获得鼠标在图片上单击点的颜色
        MouseDownpointsColor = myBitmap.GetPixel(e.X, e.Y)

        On Error GoTo ErrorAttention
        If OutlineDone = False Then
            Call 求外轮廓点坐标()
            If Mpoints <= 1 Then
                MsgBox("请单击另一点")
                Exit Sub
            End If
        Else
            Call 求内轮廓点坐标()
            If Mpoints <= 1 Then
                MsgBox("请单击另一点")
                Exit Sub
            End If

            '求凸轮转动中心坐标
            Static T As Boolean
            Dim Xmin, Ymin, Xmax, Ymax
            Xmin = 10 ^ 5
            Xmax = 0
            If T = False Then
                For I = 0 To Mpoints

                    If Xmin > Xp(I) Then
                        Xmin = Xp(I)
                        Ymin = Yp(I)
                    End If

                    If Xmax < Xp(I) Then
                        Xmax = Xp(I)
                        Ymax = Yp(I)
                    End If

                Next

                TCenter(0) = (Xmax + Xmin) / 2
                TCenter(1) = -(Ymax + Ymin) / 2
                TCenter(2) = 0
                T = True
            End If

        End If
        Call 造型()
        Exit Sub
ErrorAttention:
        Err.Clear()
        MsgBox("必须先单击外轮廓")
    End Sub

    Sub 求外轮廓点坐标()
        Dim FistX, FistY '第一点
        Dim myPen As New Pen(Color.Red)

        Mpoints = -1
        For I = YMouseDown To 0 Step -1
            If myBitmap.GetPixel(XMouseDown, I).ToArgb <> MouseDownpointsColor.ToArgb Then
                Mpoints = Mpoints + 1
                ReDim Preserve Xp(Mpoints), Yp(Mpoints)
                FistX = XMouseDown
                FistY = I + 1
                Xp(Mpoints) = XMouseDown
                Yp(Mpoints) = I + 1

                '用红色描已经辨别出来的外轮廓
                Me.PictureBox1.CreateGraphics.DrawEllipse(myPen, Xp(Mpoints), Yp(Mpoints), 1, 1)
                Exit For
            End If
        Next I

        Do
            Call 搜寻轮廓边沿坐标()

            '当搜寻到与第一点坐标相同点时停止搜寻
        Loop Until FistX = Xp(Mpoints) And (FistY = Yp(Mpoints) Or FistY = Yp(Mpoints) + 1 Or FistY = Yp(Mpoints) - 1)

⌨️ 快捷键说明

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