基于vb和opengl的三维小球碰撞程序源代码
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Imports Tao.OpenGl '引入TAO命名空间,为使用OpenGL作准备
Public Class Form1
Dim sj As Integer = 0
Dim jl, jj, zl, t, v1x0, v2x0, v1y0, v2y0, v1x, v2x, v1y, v2y, m1, m2, r1, r2, x, y, x1, y1, e, p, q As Double
Dim jc As Integer = 0, pzlx As Integer = 0, locx As Integer = 0, locy As Integer = 0, f As Integer = 0, time As Integer = 0, tx As Integer = 3600
Dim str As String
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
SimpleOpenGlControl1.InitializeContexts() '初始化控件上下文
Gl.glClearColor(0.0F, 0.0F, 0.0F, 0.0F) '以全黑色消除颜色缓存,RGBA模式,各取值在0到1之间
SimpleOpenGlControl1.Width = Me.Width
SimpleOpenGlControl1.Height = Me.Height
Gl.glViewport(0, 0, Me.Width, Me.Width) '定义视口大小
Gl.glMatrixMode(Gl.GL_PROJECTION) '设置视图投影变换矩阵
Gl.glLoadIdentity() '加载单位矩阵
Gl.glOrtho(-100, 100, -100, 100, 0, -SimpleOpenGlControl1.Width) '创建平行投影区间,其中,远处物体与近处物体大小一致
Gl.glMatrixMode(Gl.GL_MODELVIEW) '将矩阵变换对象切换为模型视图变换
Gl.glLoadIdentity() '加载单位矩阵
p = 8
q = 1
str = " ***** 第二届军械杯物理竞赛作品 ***** 小球碰撞演示软件 ***** 军械工程学院学员一旅六营十八连高晛哲 ***** "
Label16.Text = 0
Label17.Text = 0
Label18.Text = 0
Label19.Text = 0
Button10.Visible = False
End Sub
Private Sub Form1_Resize(sender As Object, e As EventArgs) Handles Me.Resize
'窗体尺寸变化时控件跟随变化
SimpleOpenGlControl1.Width = Me.Width
SimpleOpenGlControl1.Height = Me.Height
TabControl1.Width = Me.Width
TabControl1.Height = Me.Height
GroupBox1.Width = Me.Width - 200
GroupBox2.Width = Me.Width - 200
GroupBox3.Width = Me.Width - 200
GroupBox1.Height = Me.Height / 4
GroupBox2.Height = Me.Height / 4
GroupBox3.Height = Me.Height / 4
ListBox1.Height = GroupBox1.Height - 30
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
If sj > 99 Then sj = 0 '实现字幕循环滚动
sj = sj + 1 'sj必须是全局变量,否则timer_tick无法保存每一次增量
Label1.Text = Microsoft.VisualBasic.Mid(str, sj, 36) '字符串取中函数,对str字符串取从第sj开始36个字符
End Sub
Private Sub RadioButton1_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton1.CheckedChanged
RadioButton3.Visible = 1
RadioButton4.Visible = 1
RadioButton5.Visible = 1
If RadioButton2.Checked = True Then
RadioButton6.Visible = 1
Radi
oButton7.Visible = 1
Else
RadioButton6.Visible = 0
RadioButton7.Visible = 0
Label8.Visible = 0
TextBox7.Visible = 0
Label9.Visible = 0
TextBox8.Visible = 0
Label10.Visible = 0
TextBox9.Visible = 0
Label4.Text = "V1"
Label5.Text = "V2"
End If
End Sub
Private Sub RadioButton2_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton2.CheckedChanged
RadioButton3.Visible = 1
RadioButton4.Visible = 1
RadioButton5.Visible = 1
If RadioButton2.Checked = True Then
RadioButton6.Visible = 1
RadioButton7.Visible = 1
Else
RadioButton6.Visible = 0
RadioButton7.Visible = 0
End If
If RadioButton6.Checked = True Then
Label4.Text = "V1"
Label5.Text = "V2"
Label8.Visible = 1
TextBox7.Visible = 1
Label9.Visible = 0
TextBox8.Visible = 0
Label10.Visible = 0
TextBox9.Visible = 0
Else
Label4.Text = "V1x"
Label5.Text = "V2x"
Label8.Visible = 0
TextBox7.Visible = 0
Label9.Visible = 1
TextBox8.Visible = 1
Label10.Visible = 1
TextBox9.Visible = 1
End If
End Sub
Private Sub RadioButton7_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton7.CheckedChanged
If RadioButton6.Checked = True Then
Label4.Text = "V1"
Label5.Text = "V2"
Label8.Visible = 1
TextBox7.Visible = 1
Label9.Visible = 0
TextBox8.Visible = 0
Label10.Visible = 0
TextBox9.Visible = 0
Else
Label4.Text = "V1x"
Label5.Text = "V2x"
Label8.Visible = 0
TextBox7.Visible = 0
Label9.Visible = 1
TextBox8.Visible = 1
Label10.Visible = 1
TextBox9.Visible = 1
End If
End Sub
Private Sub RadioButton6_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton6.CheckedChanged
If RadioButton6.Checked = True Then
Label4.Text = "V1"
Label5.Text = "V2"
Label8.Visible = 1
TextBox7.Visible = 1
Label9.Visible = 0
TextBox8.Visible = 0
Label10.Visible = 0
TextBox9.Visible = 0
Else
Label4.Text = "V1x"
Label5.Text = "V2x"
Label8.Visible = 0
TextBox7.Visible = 0
Label9.Visible = 1
TextBox8.Visible = 1
Label10.Visible = 1
TextBox9.Visible = 1
End If
End Sub
Private Sub RadioButton3_CheckedChanged(sender As Object,
e As EventArgs) Handles RadioButton3.CheckedChanged
hfxs()
End Sub
Private Sub RadioButton4_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton4.CheckedChanged
hfxs()
End Sub
Private Sub RadioButton5_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton5.CheckedChanged
hfxs()
End Sub
Private Sub hfxs()
If RadioButton3.Checked = True Then
TextBox6.Text = 1
ElseIf RadioButton4.Checked = True Then
TextBox6.Text = Rnd(1)
Else
TextBox6.Text = 0
End If
End Sub
Private Sub Button1_Click() Handles Button1.Click
If RadioButton3.Checked = True Or RadioButton4.Checked = True Or RadioButton5.Checked = True Then
Randomize()
TextBox1.Text = Rnd(1) * 4096
TextBox2.Text = Rnd(1) * 4096
TextBox3.Text = Rnd(1) * 32
TextBox4.Text = Rnd(1) * 32
TextBox5.Text = 5 + Rnd(1) * 20
If RadioButton4.Checked = True Then
TextBox6.Text = Rnd(1)
End If
If RadioButton2.Checked = True Then
If RadioButton6.Checked = True Then
TextBox7.Text = (180 - 20 + 1) * Rnd()
ElseIf RadioButton7.Checked = True Then
TextBox8.Text = CDbl((-1 - (-1) + 1) * Rnd() + (-1)) * 32
TextBox9.Text = Rnd(1) * 32
Else
MessageBox.Show("请选择参数输入方式", "错误提示")
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
TextBox6.Text = ""
End If
End If
Else
MessageBox.Show("请选择碰撞类型", "错误提示")
End If
End Sub
Private Sub Button2_Click() Handles Button2.Click
If TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Or TextBox4.Text = "" Or TextBox5.Text = "" Or TextBox6.Text = "" Then
MessageBox.Show("请输入完整的实验数据", "错误提示")
ElseIf TextBox6.Text < 0 Or TextBox6.Text > 1 Then
MessageBox.Show("恢复系数E值介于0、1之间,请检查后重试", "错误提示")
Else
If RadioButton1.Checked = True Then
m1 = TextBox1.Text
m2 = TextBox2.Text
v1x0 = TextBox3.Text
v2x0 = TextBox4.Text
m1 = Math.Sqrt(m1 * m1)
m2 = Math.Sqrt(m2 * m2)
TextBox1.Text = m1
TextBox2.Text = m2
v1x0 = Math.Sqrt(v1x0 * v1x0)
v2x0 = Math.Sqrt(v2x0 * v2x0)
TextBox3.Text = v1x0
TextBox4.Text = v2x0
If v2x0 >= v1x0 Th
en
MessageBox.Show("要求小球1速度大于小球2,程序自行转换", "错误提示")
v2x0 = TextBox3.Text
v1x0 = TextBox4.Text
End If
v1y0 = 0
v2y0 = 0
jl = TextBox5.Text
jl = Math.Sqrt(jl * jl)
TextBox5.Text = jl
e = TextBox6.Text
SimpleOpenGlControl1.Visible = True
pzlx = 1
jssj()
jssd()
jsbj()
jc = 1
ElseIf RadioButton2.Checked = True Then
m1 = TextBox1.Text
m2 = TextBox2.Text
m1 = Math.Sqrt(m1 * m1)
m2 = Math.Sqrt(m2 * m2)
TextBox1.Text = m1
TextBox2.Text = m2
v1x0 = TextBox3.Text
v2x0 = TextBox4.Text
v1x0 = Math.Sqrt(v1x0 * v1x0)
v2x0 = Math.Sqrt(v2x0 * v2x0)
TextBox3.Text = v1x0
TextBox4.Text = v2x0
jl = TextBox5.Text
jl = Math.Sqrt(jl * jl)
TextBox5.Text = jl
e = TextBox6.Text
If RadioButton7.Checked = True Then
If TextBox9.Text = "" Or TextBox8.Text = "" Then
MessageBox.Show("请输入完整的实验数据", "错误提示")
Else
v1y0 = TextBox8.Text
v2y0 = TextBox9.Text
v1y0 = -Math.Sqrt(v1y0 * v1y0)
v2y0 = Math.Sqrt(v2y0 * v2y0)
TextBox8.Text = v1y0
TextBox9.Text = v2y0
End If
ElseIf RadioButton6.Checked = True Then
If TextBox7.Text = "" Then
MessageBox.Show("请输入完整的实验数据", "错误提示")
Else
jj = TextBox7.Text
If jj > 360 Or jj < 0 Then
MessageBox.Show("程序将两小球搬移至二、三象限", "提示")
If jj > 360 Then
Do While TextBox7.Text > 360
TextBox7.Text = TextBox7.Text - 360
Loop
End If
If jj < 0 Then
Do While TextBox7.Text < 0
TextBox7.Text = TextBox7.Text + 360
Loop
End If
If TextBox7.Text > 180 Then
TextBox7.Text = 360 - TextBox7.Text
End If
jj = TextBox7.Text
End If
jj = jj / 2
jj = Math.PI * jj / 180
v1y0 = -v1x0 * Math.Sin(jj)
v1x0 = v1x0 * Math.Cos(jj)
v2y0 = v2x0 * Math.Sin(jj)
v2x0 = v2x0 * Math.Cos(jj)
TextBox8.Text = v1y0
TextBox9.Text = v2y0
End If
End If
SimpleOpenGlControl1.Visible = True
pzlx = 2
jssj()
jssd()
jsbj()
jc = 1
End If
ListBox1.Items.Clear()
ListBox1.Items.Add("小球1质量 :" & m1)
ListBox1.Items.Add("小球2质量 :" & m2)
ListBox1.Items.Add("恢复系数e :" & e)
ListBox1.Items.Add("初始时小球1与原点间距离 :" & jl)
ListBox1.Items.Add("碰撞前小球1沿x轴方向速度V1x0:" & TextBox3.Text)
ListBox1.Items.Add("碰撞前小球1沿y轴方向速度V1y0:" & TextBox8.Text)
ListBox1.Items.Add("碰撞前小球2沿x轴方向速度V2x0:" & TextBox4.Text)
ListBox1.Items.Add("碰撞前小球2沿y轴方向速度V2y0:" & TextBox9.Text)
ListBox1.Items.Add("碰撞后小球1沿x轴方向速度V1x :" & v1x)
ListBox1.Items.Add("碰撞后小球1沿y轴方向速度V1y :" & v1y)
ListBox1.Items.Add("碰撞后小球2沿x轴方向速度V2x :" & v2x)
ListBox1.Items.Add("碰撞后小球2沿y轴方向速度V2y :" & v2y)
End If
Button4.Visible = False
Button10.Visible = True
f = 0
End Sub
Private Sub jssj()
'计算碰撞时间
t = Math.Sqrt(jl * jl / (v1x0 * v1x0 + v1y0 * v1y0))
End Sub
Private Sub jsbj()
r1 = Math.Sqrt(m1)
r1 = Math.Sqrt(r1)
r2 = Math.Sqrt(m2)
r2 = Math.Sqrt(r2)
If r1 > r2 Then
If r1 > p Then
r2 = p * r2 / r1
r1 = p
End If
Else
If r2 > p Then
r1 = p * r1 / r2
r2 = p
End If
End If
If r1 < r2 Then
If r1 < q Then
r2 = q * r2 / r1
r1 = q
End If
Else
If r2 < q Then
r1 = q * r1 / r2
r2 = q
End If
End If
End Sub
Private Sub jssd()
If pzlx = 1 Then
v1x = v1x0 - (1 + e) * m2 * (v1x0 - v2x0) / (m1 + m2)
v2x = v2x0 + (1 + e) * m1 * (v1x0 - v2x0) / (m1 + m2)
v1y = 0
v2y = 0
ElseIf pzlx = 2 Then
If RadioButton5.Checked = True Then
v1x = (m1 * v1x0 + m2 * v2x0) / (m1 + m2)
v2x = v1x
v1y
= (m1 * v1y0 + m2 * v2y0) / (m1 + m2)
v2y = v1y
ElseIf RadioButton3.Checked = True Or RadioButton4.Checked = True Then
r1 = Math.Sqrt(v1x0 * v1x0 + v2x0 * v2x0 + v1y0 * v1y0 + v2y0 * v2y0 - 2 * v1x0 * v2x0 - 2 * v1y0 * v2y0)
r2 = (v2x0 - v1x0) / r1
r1 = (v2y0 - v1y0) / r1
x = v1x0 * r1 - v1y0 * r2
y = v1x0 * r2 + v1y0 * r1
x1 = v2x0 * r1 - v2y0 * r2
y1 = v2x0 * r2 + v2y0 * r1
v1y0 = y
v2y0 = y1
v1x = x
v2x = x1
v1y = v1y0 - (1 + e) * m2 * (v1y0 - v2y0) / (m1 + m2)
v2y = v2y0 + (1 + e) * m1 * (v1y0 - v2y0) / (m1 + m2)
y = v1y * r1 - v1x * r2
x = v1y * r2 + v1x * r1
y1 = v2y * r1 - v2x * r2
x1 = v2y * r2 + v2x * r1
v1x = x
v1y = y
v2x = x1
v2y = y1
End If
End If
End Sub
Private Sub jswy()
'计算小球碰撞瞬间相对位置
x1 = (v1x0 - v2x0) * (r1 + r2) / Math.Sqrt(v1x0 * v1x0 + v2x0 * v2x0 + v1y0 * v1y0 + v2y0 * v2y0 - 2 * v1x0 * v2x0 - 2 * v1y0 * v2y0)
y1 = (v1y0 - v2y0) * (r1 + r2) / Math.Sqrt(v1x0 * v1x0 + v2x0 * v2x0 + v1y0 * v1y0 + v2y0 * v2y0 - 2 * v1x0 * v2x0 - 2 * v1y0 * v2y0)
'计算小球1位移量
If zl < t Then
x = v1x0 * (zl - t) - 25 + locx
y = v1y0 * (zl - t) - 35 + locy
'计算小球2位移量
x1 = (v2x0 - v1x0) * (zl - t) + x1
y1 = (v2y0 - v1y0) * (zl - t) + y1
Else
x = v1x * (zl - t) - 25 + locx
y = v1y * (zl - t) - 35 + locy
'计算小球2位移量
x1 = (v2x - v1x) * (zl - t) + x1
y1 = (v2y - v1y) * (zl - t) + y1
End If
End Sub
Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
If jc = 1 Then
zl += 0.01
SimpleOpenGlControl1_Paint()
Me.Refresh()
End If
End Sub
Private Sub SimpleOpenGlControl1_MouseClick(sender As Object, e As MouseEventArgs) Handles SimpleOpenGlControl1.MouseClick
SimpleOpenGlControl1.Visible = 0
jc = 0
zl = 0
Button4.Visible = True
Button10.Visible = False
f = 1
End Sub
Private Sub SimpleOpenGlControl1_Paint() Handles SimpleOpenGlControl1.Paint
Gl.glClear(Gl.GL_COLOR_BUFFER_BIT Or Gl.GL_DEPTH_BUFFER_BIT) '清除颜色缓存区及深度缓存区
Gl.glEnable(Gl.GL_LIGHTING) '打开光照
Gl.glEnable(Gl.GL_LIGHT0) '启用默认光源light0,,light0-light7
Dim xiaoqiu1, xiaoqiu2 As Glu.GLUquadric '定义二次几何体对象xiaoqiu1,xiaoqiu2
jswy()
Gl.glPushMatrix() '保存模型矩阵,一
般在绘图操作前后都要有此过程
Gl.glLoadIdentity() '加载单位矩阵
Gl.glTranslatef(x, y, 0) '沿x,y,z轴平移,这个位移量将影响到小球1跟小球2
xiaoqiu1 = Glu.gluNewQuadric '创建一个新的二次几何体对象
Glu.gluSphere(xiaoqiu1, r1, 150, 150) '绘制半径为1的小球
Glu.gluDeleteQuadric(xiaoqiu1) '删除二次几何体对象
Gl.glTranslatef(x1, y1, 0) '沿x,y,z轴平移,此时小球2在小球1 x轴左边jl+a处
xiaoqiu2 = Glu.gluNewQuadric '创建一个新的二次几何体对象
Glu.gluSphere(xiaoqiu2, r2, 150, 150) '绘制半径为5的小球
Glu.gluDeleteQuadric(xiaoqiu2) '删除二次几何体对象
Gl.glPopMatrix()
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
TextBox7.Text = ""
TextBox8.Text = ""
TextBox9.Text = ""
TextBox6.Text = ""
RadioButton1.Checked = 0
RadioButton2.Checked = 0
RadioButton3.Checked = 0
RadioButton4.Checked = 0
RadioButton5.Checked = 0
RadioButton6.Checked = 0
RadioButton7.Checked = 0
End Sub
Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
If Not TextBox10.Text = "" Then
q = TextBox10.Text
End If
If Not TextBox11.Text = "" Then
p = TextBox10.Text
End If
If p < q Then
p = p + q
q = p - q
p = p - q
End If
If Not TextBox13.Text = "" Then
locx = TextBox13.Text
End If
If Not TextBox14.Text = "" Then
locy = TextBox14.Text
End If
If Not TextBox12.Text = "" Then
str = " " + TextBox12.Text + " "
Me.Refresh()
End If
If Not TextBox15.Text = "" Then
If Label16.Text = 0 And Label17.Text = 0 And Label18.Text = 0 And Label19.Text = 0 Then
ProgressBar1.Step = 0
End If
tx = TextBox15.Text
ProgressBar1.Visible = True
If Timer3.Enabled = True Then
ProgressBar1.Enabled = True
End If
ProgressBar1.Step = 80 / tx + 5
End If
End Sub
Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
Me.TopMost = True
End Sub
Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
TextBox10.Text = ""
TextBox11.Text = ""
TextBox12.Text = ""
TextBox13.Text = ""
TextBox14.Text = ""
TextBox15.Text = ""
p = 8
q = 1
locx = 0
locy = 0
Me.TopMost
= False
ProgressBar1.Visible = False
ProgressBar1.Enabled = False
ProgressBar1.Value = 0
str = " ***** 第二届军械杯物理竞赛作品 ***** 小球碰撞演示软件 ***** 军械工程学院学员一旅六营十八连高晛哲 ***** "
End Sub
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
ListBox1.Items.Add("小球1质量 :" & TextBox1.Text)
End Sub
Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles TextBox2.TextChanged
ListBox1.Items.Add("小球2质量 :" & TextBox2.Text)
End Sub
Private Sub TextBox3_TextChanged(sender As Object, e As EventArgs) Handles TextBox3.TextChanged
ListBox1.Items.Add("碰撞前小球1沿x轴方向速度V1x0:" & TextBox3.Text)
End Sub
Private Sub TextBox4_TextChanged(sender As Object, e As EventArgs) Handles TextBox4.TextChanged
ListBox1.Items.Add("碰撞前小球2沿x轴方向速度V2x0:" & TextBox4.Text)
End Sub
Private Sub TextBox6_TextChanged(sender As Object, e As EventArgs) Handles TextBox6.TextChanged
ListBox1.Items.Add("恢复系数e :" & TextBox6.Text)
End Sub
Private Sub TextBox7_TextChanged(sender As Object, e As EventArgs) Handles TextBox7.TextChanged
ListBox1.Items.Add("小球运动方向夹角 :" & TextBox7.Text)
End Sub
Private Sub TextBox5_TextChanged(sender As Object, e As EventArgs) Handles TextBox5.TextChanged
ListBox1.Items.Add("初始时小球1与原点间距离 :" & TextBox5.Text)
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
Dim file As New System.IO.StreamWriter("D:\实验数据.txt", True)
If f = 1 Then
file.WriteLine("小球1质量 :" & m1)
file.WriteLine("小球2质量 :" & m2)
file.WriteLine("碰撞前小球1沿x轴方向速度V1x0:" & TextBox3.Text)
file.WriteLine("碰撞前小球1沿y轴方向速度V1y0:" & TextBox8.Text)
file.WriteLine("碰撞前小球2沿x轴方向速度V2x0:" & TextBox4.Text)
file.WriteLine("碰撞前小球2沿y轴方向速度V2y0:" & TextBox9.Text)
file.WriteLine("碰撞后小球1沿x轴方向速度V1x :" & v1x)
file.WriteLine("碰撞后小球1沿y轴方向速度V1y :" & v1y)
file.WriteLine("碰撞后小球2沿x轴方向速度V2x :" & v2x)
file.WriteLine("碰撞后小球2沿y轴方向速度V2y :" & v2y)
file.WriteLine("碰撞后系统沿x轴动量 :" & m1 * TextBox3.Text + m2 * TextBox4.Text)
file.WriteLine("碰撞后系统沿y轴动量 :" & m1 * TextBox8.Text + m2 * TextBox9.Text)
file.WriteLine("碰撞后
系统沿x轴动量 :" & m1 * v1x + m2 * v2x)
file.WriteLine("碰撞后系统沿y轴动量 :" & m1 * v1y + m2 * v2y)
file.WriteLine("碰撞前小球1动能 :" & m1 * (TextBox3.Text * TextBox3.Text + TextBox8.Text * TextBox8.Text) / 2)
file.WriteLine("碰撞前小球2动能 :" & m2 * (TextBox4.Text * TextBox4.Text + TextBox9.Text * TextBox9.Text) / 2)
file.WriteLine("碰撞后小球1动能 :" & m1 * (v1x * v1x + v1y * v1y) / 2)
file.WriteLine("碰撞后小球2动能 :" & m2 * (v2x * v2x + v2y * v2y) / 2)
file.Close()
Else
MessageBox.Show("没有当前实验数据", "提醒")
End If
End Sub
Private Sub Timer3_Tick(sender As Object, e As EventArgs) Handles Timer3.Tick
time += 1
Label19.Text = time
If time > 99 Then
time = 0
Label18.Text += 1
ProgressBar1.PerformStep()
End If
If Label18.Text > 59 Then
Label18.Text = 0
Label17.Text += 1
End If
If Label17.Text > 59 Then
Label17.Text = 0
Label16.Text += 1
End If
If Not TextBox15.Text = "" Then
If tx <= Label16.Text * 3600 + Label17.Text * 60 + Label18.Text Then
tx = tx + TextBox15.Text
ProgressBar1.Value = 0
MessageBox.Show("您现在已用时:" + Label16.Text + "时" + Label17.Text + "分" + Label18.Text + "秒", "提醒")
End If
End If
End Sub
Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click
If Timer3.Enabled = False Then
Timer3.Enabled = True
Button8.Text = "暂 停"
Else
Timer3.Enabled = False
Button8.Text = "计 时"
End If
End Sub
Private Sub Button9_Click(sender As Object, e As EventArgs) Handles Button9.Click
Label16.Text = 0
Label17.Text = 0
Label18.Text = 0
Label19.Text = 0
End Sub
Private Sub Button10_Click(sender As Object, e As EventArgs) Handles Button10.Click
If Timer2.Enabled = True Then
Timer2.Enabled = False
Button10.Text = "演 示"
Else
Timer2.Enabled = True
Button10.Text = "暂 停"
End If
End Sub
End Class