贝塞尔曲线 B 样条曲线 程序

• Published on
12-Jan-2016

• View
87

0

Embed Size (px)

DESCRIPTION

B . Option Explicit Private Function NNum(n As Integer) As Long Dim i As Integer, r As Long If n = 0 Or n = 1 Then NNum = 1 Exit Function End If r = 1 For i = 2 To n r = r * i Next. NNum = r End Function Private Function CNum(i As Integer, n As Integer) As Long - PowerPoint PPT Presentation

Transcript

• B

• Option ExplicitPrivate Function NNum(n As Integer) As LongDim i As Integer, r As LongIf n = 0 Or n = 1 Then NNum = 1 Exit FunctionEnd Ifr = 1For i = 2 To n r = r * iNext

• NNum = rEnd FunctionPrivate Function CNum(i As Integer, n As Integer) As LongCNum = NNum(n) / (NNum(i) * NNum(n - i))End Private Function BensteinB(t As Single, i As Integer, n As Integer) As SingleIf i = 0 Then BensteinB = (1 - t) ^ n Exit FunctionEnd If

• If i = n Then BensteinB = t ^ n Exit FunctionEnd IfBensteinB = CNum(i, n) * t ^ i * (1 - t) ^ (n - i)End FunctionPrivate Function BSplineB(t As Single, k As Integer, n As Integer) As SingleDim j As Integer, r As Singler = 0

• For j = 0 To n - k r = r + (-1) ^ j * CNum(j, n + 1) * (t + n - k - j) ^ nNextBSplineB = r / NNum(n)End FunctionPrivate Function BZline(t As Single, x() As Single) As SingleDim i As Integer, r As Single, n As Integern = UBound(x)r = 0

• For i = 0 To n r = r + BensteinB(t, i, n) * x(i)NextBZline = rEnd FunctionPrivate Function BSPline(t As Single, x() As Single) As SingleDim i As Integer, r As Single, n As Integern = UBound(x)r = 0

• For i = 0 To n r = r + BSplineB(t, i, n) * x(i)NextBSPline = rEnd FunctionPrivate Sub DBZline(x() As Single, y() As Single)Dim t As SingleDim x1 As Single, y1 As Single, x0 As Single, y0 As Singlet = 0

• x0 = BZline(t, x)y0 = BZline(t, y)For t = 0 To 1 Step 0.01 x1 = BZline(t, x) y1 = BZline(t, y) Pic.Line (x0, y0)-(x1, y1), RGB(255, 0, 0) x0 = x1 y0 = y1NextEnd Sub

• Private Sub DSPline(x() As Single, y() As Single)Dim t As SingleDim x1 As Single, y1 As Single, x0 As Single, y0 As Singlet = 0x0 = BSPline(t, x)y0 = BSPline(t, y)

• For t = 0 To 1 Step 0.01 x1 = BSPline(t, x) y1 = BSPline(t, y) Pic.Line (x0, y0)-(x1, y1), RGB(255, 0, 0) x0 = x1 y0 = y1NextEnd Sub

• Private Sub cmdBezier_Click(index As Integer)Dim x(5) As Single, y(5) As Single, x1(2) As Single, y1(2) As SingleDim i As Integer, j As IntegerPic.Clsx(0) = 100: x(1) = 2000: x(2) = 3000: x(3) = 4000: x(4) = 2000: x(5) = 1000y(0) = 200: y(1) = 3000: y(2) = 300: y(3) = 4000: y(4) = 5000: y(5) = 3000For i = 0 To UBound(x) - 1 Pic.Line (x(i), y(i))-(x(i + 1), y(i + 1))Next

• If index = 0 Then DBZline x, yElse For i = 0 To UBound(x) - UBound(x1) For j = 0 To UBound(x1) x1(j) = x(i + j) y1(j) = y(i + j) Next DSPline x1, y1 NextEnd IfEnd Sub

• (m+1)(n+1)bi,j(i=0,1,2,,n;j=0,1,2,,n)mn

• 1.m=n=1B0,1(t)=1-t, B1,1(t)=t

• 2. m=n=2B0,2(t)=(1-t)2, B1,2(t)=2t(1-t), B2,2(t)=t2

• 3. m=n=3B0,3(t)=(1-t)3, B1,3(t)=3t(1-t)2, B2,3(t)= 3 (1-t)2tB3,3(t)= t3

• B

• (m+1)(n+1)bi,j(i=0,1,2,,n;j=0,1,2,,n)mnB

• 1.(xi,yi)y=f(x),if(xi)-yi