1 / 23

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

贝塞尔曲线 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

uta
Télécharger la présentation

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

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. 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

  3. NNum = r End Function Private Function CNum(i As Integer, n As Integer) As Long CNum = NNum(n) / (NNum(i) * NNum(n - i)) End Private Function BensteinB(t As Single, i As Integer, n As Integer) As Single If i = 0 Then BensteinB = (1 - t) ^ n Exit Function End If

  4. If i = n Then BensteinB = t ^ n Exit Function End If BensteinB = CNum(i, n) * t ^ i * (1 - t) ^ (n - i) End Function Private Function BSplineB(t As Single, k As Integer, n As Integer) As Single Dim j As Integer, r As Single r = 0

  5. For j = 0 To n - k r = r + (-1) ^ j * CNum(j, n + 1) * (t + n - k - j) ^ n Next BSplineB = r / NNum(n) End Function Private Function BZline(t As Single, x() As Single) As Single Dim i As Integer, r As Single, n As Integer n = UBound(x) r = 0

  6. For i = 0 To n r = r + BensteinB(t, i, n) * x(i) Next BZline = r End Function Private Function BSPline(t As Single, x() As Single) As Single Dim i As Integer, r As Single, n As Integer n = UBound(x) r = 0

  7. For i = 0 To n r = r + BSplineB(t, i, n) * x(i) Next BSPline = r End Function Private Sub DBZline(x() As Single, y() As Single) Dim t As Single Dim x1 As Single, y1 As Single, x0 As Single, y0 As Single t = 0

  8. 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 = y1 Next End Sub

  9. Private Sub DSPline(x() As Single, y() As Single) Dim t As Single Dim x1 As Single, y1 As Single, x0 As Single, y0 As Single t = 0 x0 = BSPline(t, x) y0 = BSPline(t, y)

  10. 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 = y1 Next End Sub

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

  12. If index = 0 Then DBZline x, y Else 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 Next End If End Sub

  13. 贝塞尔曲面

  14. 贝塞尔曲面   给定(m+1)(n+1)个空间点列bi,j(i=0,1,2,…,n;j=0,1,2,…,n)后,可以定义mn次贝塞尔曲面如下式所示:

  15. 1.双一次贝塞尔曲面  当m=n=1时,有 B0,1(t)=1-t, B1,1(t)=t 所以

  16. 2.双二次贝塞尔曲面当m=n=2时,有 B0,2(t)=(1-t)2, B1,2(t)=2t(1-t), B2,2(t)=t2 所以有

  17. 3.双二次贝塞尔曲面当m=n=3时,有 B0,3(t)=(1-t)3, B1,3(t)=3t(1-t)2, B2,3(t)= 3 (1-t)2t B3,3(t)= t3 所以有

  18. B样条曲面

  19. 给定(m+1)(n+1)个空间点列bi,j(i=0,1,2,…,n;j=0,1,2,…,n)后,可以定义mn次B样条曲面如下式所示:给定(m+1)(n+1)个空间点列bi,j(i=0,1,2,…,n;j=0,1,2,…,n)后,可以定义mn次B样条曲面如下式所示:

  20. 实验曲线的绘制方法

  21. 1.最小二乘法  对于一系列的数据点(xi,yi)和所要绘制的曲线y=f(x),用什么样的标准来评价这条曲线是处于较为合理的状态呢?通常用数据点的坐标值与曲线上对应的坐标之差作为评判的标准。 i=f(xi)-yi 常用的评判方法是:使残差的平方和达到最小-最小二乘法。

More Related