?? form1.vb
字號:
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 + -