Dim xx() As Single
Dim yy() As Single
Dim i As Integer
Dim s1 As Single
Dim s2 As Single
Dim s3 As Single
Dim s4 As Single
Dim al, bl, cl, dl, el, fl As Single
Dim ar, br, cr, dr, er, fr As Single
Dim wl As Single
Dim wr As Single
Dim k As Single
Private Sub Form_Load()
Form1.Scale (-100, -100)-(100, 100)
Form1.Line (-100, 0)-(100, 0), vbRed
Form1.Line (0, -100)-(0, 100), vbRed
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
i = i + 1
ReDim Preserve xx(1 To i)
ReDim Preserve yy(1 To i)
xx(i) = X
yy(i) = Y
1
Form1.Circle (X, Y), 2, vbBlue
End Sub
Private Sub 画抛物线_Click()
s1 = 0
s2 = s1 + Sqr((xx(1) - xx(2)) ^ 2 + (yy(1) - yy(2)) ^ 2)
s3 = s2 + Sqr((xx(2) - xx(3)) ^ 2 + (yy(2) - yy(3)) ^ 2)
s4 = s3 + Sqr((xx(3) - xx(4)) ^ 2 + (yy(3) - yy(4)) ^ 2)
cl = ((s3 - s1) * (xx(2) - xx(1)) - (s2 - s1) * (xx(3) - xx(1))) / ((s3 - s1) * (s2 ^ 2 - s1 ^ 2) - (s2 - s1)
* (s3 ^ 2 - s1 ^ 2))
bl = ((xx(2) - xx(1) - cl * (s2 ^ 2 - s1 ^ 2))) / (s2 - s1)
al = xx(1) - bl * s1 - cl * s1 ^ 2
fl = ((s3 - s1) * (yy(2) - yy(1)) - (s2 - s1) * (yy(3) - yy(1))) / ((s3 - s1) * (s2 ^ 2 - s1 ^ 2) - (s2 - s1)
* (s3 ^ 2 - s1 ^ 2))
el = ((yy(2) - yy(1) - fl * (s2 ^ 2 - s1 ^ 2))) / (s2 - s1)
dl = yy(1) - el * s1 - fl * s1 ^ 2
cr = ((s4 - s2) * (xx(3) - xx(2)) - (s3 - s2) * (xx(4) - xx(2))) / ((s4 - s2) * (s3 ^ 2 - s2 ^ 2) - (s3 - s2)
* (s4 ^ 2 - s2 ^ 2))
br = ((xx(3) - xx(2) - cr * (s3 ^ 2 - s2 ^ 2))) / (s3 - s2)
ar = xx(2) - br * s2 - cr * s2 ^ 2
fr = ((s4 - s2) * (yy(3) - yy(2)) - (s3 - s2) * (yy(4) - yy(2))) / ((s4 - s2) * (s3 ^ 2 - s2 ^ 2) - (s3 - s2)
* (s4 ^ 2 - s2 ^ 2))
er = ((yy(3) - yy(2) - fr * (s3 ^ 2 - s2 ^ 2))) / (s3 - s2)
dr = yy(2) - er * s2 - fr * s2 ^ 2
For s = s1 To s3
X1 = al + bl * s + cl * s ^ 2
Y1 = dl + el * s + fl * s ^ 2
Form1.PSet (X1, Y1), vbRed
Next
For s = s2 To s4
X1 = ar + br * s + cr * s ^ 2
Y1 = dr + er * s + fr * s ^ 2
Form1.PSet (X1, Y1), vbRed
Next
End Sub
Private Sub 曲线拟合_Click()
For s = s2 To s3
X = ((1 - (s - s2) / (s3 - s2)) ^ 2 * (1 + 2 * (s - s2) / (s3 - s2))) * (al + bl * s + cl * s ^ 2) + (((s
- s2) / (s3 - s2)) ^ 2 * (3 - 2 * (s - s2) / (s3 - s2))) * (ar + br * s + cr * s ^ 2)
Y = ((1 - (s - s2) / (s3 - s2)) ^ 2 * (1 + 2 * (s - s2) / (s3 - s2))) * (dl + el * s + fl * s ^ 2) + (((s -
s2) / (s3 - s2)) ^ 2 * (3 - 2 * (s - s2) / (s3 - s2))) * (dr + er * s + fr * s ^ 2)
Form1.PSet (X, Y), vbRed
Next
End Sub
2