Visual Basic - Solution 3 ( Courbes de Bézier )
Interface graphique :
Code de la feuille Form1 :
Dim P(1 To 4) As XYPoint
Dim Tmax As Integer
Private Sub Command1_Click()
Dim V As XYPoint
Dim T As Double
Dim i As Integer
'Lecture des valeurs
For i = 1 To 4
P(i).X = Val(PX(i).Text)
P(i).Y = Val(PY(i).Text)
Next i
Tmax = Val(T_TMax.Text)
'Espace de travail
Picture1.Scale (-1, 1)-(1, -1)
Picture1.Cls
'Calcul et dessin
Picture1.PSet (P(1).X, P(1).Y)
For i = 1 To Tmax
T = i / Tmax
V = bezier(P, T)
Picture1.Line -(V.X, V.Y)
Next i
End Sub
Code à placer dans un module :
Public Type XYPoint
X As Single
Y As Single
End Type
Public Function bezier(P() As XYPoint, T As Double) As XYPoint
bezier.X = P(1).X * (1 - T) ^ 3 _
+ P(2).X * (1 - T) ^ 2 * 3 * T _
+ P(3).X * (1 - T) * 3 * T ^ 2 _
+ P(4).X * T ^ 3
bezier.Y = P(1).Y * (1 - T) ^ 3 _
+ P(2).Y * (1 - T) ^ 2 * 3 * T _
+ P(3).Y * (1 - T) * 3 * T ^ 2 _
+ P(4).Y * T ^ 3
End Function
( retour à l'énoncé )
|