Function MaPrevision(Entraxe#, R#, L1#, L2#, lig1&, lig2&)
Dim p#, pas#, inia#, inib#, N%, a(0 To 20, 1 To 4), b(0 To 20, 1 To 4)
Dim i&, min1#, min2#, j&, d#, temp#, X#, Y#
p = Application.Pi()
pas = 0.1 'pas initial
inia = Cells(lig1 - 1, 1)
inib = Cells(lig2 - 1, 1)
For N = 1 To 4 'pour atteindre une précision de 0,00001 degré
pas = pas / 10
a(0, 1) = inia
b(0, 1) = inib
For i = 0 To 20
a(i, 1) = a(0, 1) + pas * i 'angle en degré
a(i, 2) = a(i, 1) * p / 180 'angle en radian
a(i, 3) = -Entraxe / 2 - R * Cos(a(i, 2)) + (L1 - R * a(i, 2)) * Sin(a(i, 2)) 'X1
a(i, 4) = R * Sin(a(i, 2)) + (L1 - R * a(i, 2)) * Cos(a(i, 2)) 'Y1
b(i, 1) = b(0, 1) + pas * i 'angle en degré
b(i, 2) = b(i, 1) * p / 180 'angle en radian
b(i, 3) = Entraxe / 2 + R * Cos(b(i, 2)) - (L2 - R * b(i, 2)) * Sin(b(i, 2)) 'X2
b(i, 4) = R * Sin(b(i, 2)) + (L2 - R * b(i, 2)) * Cos(b(i, 2)) 'Y2
Next i
min1 = 9 ^ 99
For i = 0 To 20
min2 = 9 ^ 99
For j = 0 To 20
d = Sqr((a(i, 3) - b(j, 3)) ^ 2 + (a(i, 4) - b(j, 4)) ^ 2) 'distance des extrémités
If d < min2 Then min2 = d: temp = b(j, 1)
Next j
If min2 < min1 Then min1 = min2: inia = a(i, 1) - pas: inib = temp - pas: X = a(i, 3): Y = a(i, 4)
Next i
Next N
MaPrevision = Array(X, Y) 'vecteur horizontal
End Function