|
Tipp 0216
|
Berechnung von Kurven
|
|
|
Autor/Einsender: Datum: |
|
Richard Schubert 01.04.2002 |
|
Entwicklungsumgebung: |
|
VB 5 |
|
|
Dieser Tipp zeigt, dank der von Pierre Bézier entwickelten Gleichung zur Berechnung von Kurven, wie man Punkte mit Kurven so verbindet, dass eine fließender Weg entsteht. Die Berechnung kann für KI- oder andere Wegberechungsprobleme angewandt werden. Die Erweiterung für eine Kamerafahrt in 3D ist damit auch ohne weitere Probleme möglich.
|
|
|
Option Explicit
Private Type SplinePoint
X As Single
Y As Single
End Type
Dim Quit As Boolean
Dim CSP As SplinePoint
Dim SP(50) As SplinePoint
Dim TP(100) As SplinePoint
Dim CurrentPoint As Integer
Dim CurrentPos As Single
Private Sub Start_Cmd_Click()
Dim n As Long
DrawWidth = 3
Quit = False
CurrentPos = 0
TP(0).X = SP(0).X
TP(0).Y = SP(0).Y
For n = 1 To CurrentPoint - 2
TP(n * 2 - 1).X = SP(n).X + (SP(n - 1).X - SP(n + 1).X) / 5
TP(n * 2 - 1).Y = SP(n).Y + (SP(n - 1).Y - SP(n + 1).Y) / 5
TP(n * 2).X = SP(n).X - (SP(n - 1).X - SP(n + 1).X) / 5
TP(n * 2).Y = SP(n).Y - (SP(n - 1).Y - SP(n + 1).Y) / 5
Next
TP(n * 2 - 1).X = SP(CurrentPoint - 1).X
TP(n * 2 - 1).Y = SP(CurrentPoint - 1).Y
Do
DoEvents
CurrentPos = CurrentPos + 0.001
subGetSplinePoint SP(Int(CurrentPos)), _
TP(Int(CurrentPos) * 2), TP(Int(CurrentPos) * 2 + 1), _
SP(Int(CurrentPos) + 1), CurrentPos - Int(CurrentPos), CSP
PSet (CSP.X, CSP.Y)
If CurrentPos > CurrentPoint - 1 Then Quit = True
Loop Until Quit = True
End Sub
Private Sub subGetSplinePoint(P1 As SplinePoint, _
P2 As SplinePoint, P3 As SplinePoint, P4 As SplinePoint, _
u As Single, P As SplinePoint)
P.X = P1.X * (1 - u) ^ 3 + _
P2.X * 3 * u * (1 - u) ^ 2 + _
P3.X * 3 * u ^ 2 * (1 - u) + _
P4.X * u ^ 3
P.Y = P1.Y * (1 - u) ^ 3 + _
P2.Y * 3 * u * (1 - u) ^ 2 + _
P3.Y * 3 * u ^ 2 * (1 - u) + _
P4.Y * u ^ 3
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, _
X As Single, Y As Single)
SP(CurrentPoint).X = X
SP(CurrentPoint).Y = Y
DrawWidth = 3
PSet (X, Y)
CurrentPoint = CurrentPoint + 1
If CurrentPoint = 2 Then Start_Cmd.Enabled = True
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, _
UnloadMode As Integer)
Quit = True
End Sub
|
|
|
|
|
Windows-Version |
95 |
|
|
98/SE |
|
|
ME |
|
|
NT |
|
|
2000 |
|
|
XP |
|
|
Vista |
|
|
Win
7 |
|
|
|
VB-Version |
VBA 5 |
|
|
VBA 6 |
|
|
VB 4/16 |
|
|
VB 4/32 |
|
|
VB 5 |
|
|
VB 6 |
|
|
|
|
Download (2,8 kB)
|
Downloads bisher: [ 2353 ]
|
|
|