用vb 方法画摆线.函数轨迹如下:x=at+b*sin(ct) ,y=b*(1-cos(ct))其中a,b,c为需要用inputbox输入的常数
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/18 19:47:31
用vb 方法画摆线.函数轨迹如下:x=at+b*sin(ct) ,y=b*(1-cos(ct))其中a,b,c为需要用inputbox输入的常数
用vb 方法画摆线.函数轨迹如下:x=at+b*sin(ct) ,y=b*(1-cos(ct))
其中a,b,c为需要用inputbox输入的常数
用vb 方法画摆线.函数轨迹如下:x=at+b*sin(ct) ,y=b*(1-cos(ct))其中a,b,c为需要用inputbox输入的常数
Rem 正如一楼所述,你没给出t的取值范围,这里我假设就是窗体的宽度
Rem 其实这种题最难的不是画函数,而是预估函数的最大值和最小值,只有这样才能归一化,否
Rem 则没法显示
Private Sub Command1_Click()
Rem x=at+b*sin(ct) ,y=b*(1-cos(ct))
Dim t As Integer, x As Double, y As Double, ang As Double
Dim minX As Double, MaxX As Double, minY As Double, MaxY As Double
Dim StartX As Integer, StartY As Double, LastX As Integer, LastY As Double
Dim a As Integer, b As Integer, c As Integer
' a = Val(InputBox("a是?"))
' b = Val(InputBox("b是?"))
' c = Val(InputBox("c是?"))
a = 1: b = 2: c = 3
Pi = 3.14
Me.ScaleMode = vbPixels
minX = 0: MaxX = 120
minY = 0: MaxY = 5
StartX = minX: StartY = MaxY
For t = 1 To ScaleWidth Step 1
ang = (t / Me.ScaleWidth) * 2 * Pi '仅显示一个周期
ant = t
x = (a * t + b * Sin(c * ang))
x = x * (Me.ScaleWidth - 20) / (MaxX - minX) '归一化处理
ang = (t / Me.ScaleHeight) * 2 * Pi '仅显示一个周期
ang = t
y = (b * (1 - Cos(c * ang)))
y = Me.ScaleHeight - 40 - y * Me.ScaleHeight / (MaxY - minY) '归一化处理
Rem Me.PSet (x, y), vbRed
Rem Me.Circle (x, y), 2, vbRed
LastX = x: LastY = y
Me.Line (StartX, StartY)-(LastX, LastY), vbRed
StartX = LastX: StartY = LastY
Next
End Sub