Bonjour
une nouvelle tracasserie à vous proposer
je réalise la motorisation de mon télescope
moteurs pas à pas + arduino +pc
pour fonctionner, le soft a besoin de connaitre l'altitude et l'azimut de l'objet pour en assurer le suivi
on m'a passé un bout de code en VB que j'ai transcrit en Pascal mais j'ai dû me tromper car les fonctions ne renvoient pas les valeurs correctes
les fonctions VB
le Pascal
Code vb : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86 Function Angle_horaire(AD As Date, Longitude As Single, Date_choisie As Date, Heure_choisie As Date, Zone As Integer) As Single Dim Dayz, Monthz, Yearz, Hourz, Minutez, Secondz As Integer Dim AD_in_degre, A, B, C, D, JJ, T, H1, HSH, HS, AngleH, AngleT, PI As Single PI = 3.14159 Dayz = Day(Date_choisie) Monthz = Month(Date_choisie) Yearz = Year(Date_choisie) Hourz = Hour(Heure_choisie) Minutez = Minute(Heure_choisie) Secondz = Second(Heure_choisie) AD_in_degre = 15 * (Hour(AD) + Minute(AD) / 60 + Second(AD) / 3600) If (Monthz < 3) Then Monthz = Monthz + 12 Yearz = Yearz - 1 End If A = Int(Yearz / 100) B = 2 - A + Int(A / 4) C = Int(365.25 * Yearz) D = Int(30.6001 * (Monthz + 1)) JJ = B + C + D + Dayz + 1720994.5 T = (JJ - 2451545) / 36525 H1 = 24110.54841 + (8640184.812866 * T) + (0.093104 * (T * T)) - (0.0000062 * (T * T * T)) HSH = H1 / 3600 HS = ((HSH / 24) - Int(HSH / 24)) * 24 AngleH = (2 * PI * HS / (23 + 56 / 60 + 4 / 3600)) * 180 / PI AngleT = ((Hourz - 12 + Minutez / 60 - Zone) * 2 * PI / (23 + 56 / 60 + 4 / 3600)) * 180 / PI Angle_horaire = AngleH + AngleT - AD_in_degre + Longitude End Function Function Convert_temps(ByVal T As Single) As String Dim H, M, S As Integer Dim Temp, Temp2 As Single H = Int(T) If H >= 24 Then H = H - 24 Temp = T - H Temp2 = Temp * 60 M = Int(Temp2) If M >= 60 Then M = 0 H = H + 1 End If Temp = Temp - M / 60 Temp2 = Temp * 3600 S = Temp2 If S >= 60 Then S = 0 M = M + 1 End If Convert_temps = H & ":" & M & ":" & S End Function Function Arsin(ByVal X As Single) As Single If (Abs(X) >= 1) Then Arsin = 0 Else Arsin = Atn(X / Sqr(-X * X + 1)) End Function Function Arcos(ByVal X As Single) As Single If (Abs(X) >= 1) Then Arcos = 0 Else Arcos = Atn(-X / Sqr(-X * X + 1)) + 2 * Atn(1) End Function Function Hauteur(Dec As Single, Latitude As Single, H As Single) As Single Dim Sin_hauteur, PI As Single PI = 3.14159 Sin_hauteur = Sin(Dec * PI / 180) * Sin(Latitude * PI / 180) - Cos(Dec * PI / 180) * Cos(Latitude * PI / 180) * Cos(H * PI / 180) Hauteur = Arsin(Sin_hauteur) * 180 / PI End Function Function Azimuth(Dec As Single, Lat As Single, H As Single, Haut As Single) As Single Dim Cosazimuth, Sinazimuth, test, Az As Single PI = 3.14159 Cosazimuth = (Sin(Dec * PI / 180) - Sin(Lat * PI / 180) * Sin(Haut * PI / 180)) / (Cos(Lat * PI / 180) * Cos(Haut * PI / 180)) Sinazimuth = (Cos(Dec * PI / 180) * Sin(H * PI / 180)) / Cos(Haut * PI / 180) If (Sinazimuth > 0) Then Az = Arcos(Cosazimuth) * 180 / PI Else Az = -Arcos(Cosazimuth) * 180 / PI If (Az < 0) Then Azimuth = 360 + Az Else Azimuth = Az End Function
la fonction angle horaire fonctionne bien
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63 Function TForm1.Angle_horaire(AD : tdate; Longitude : Single; Date_choisie : tdate; Heure_choisie : tdate; Zone : Integer) : Single ; var Date1 : TdateTime; Annee, Mois, Jour, Heure, Minute, Seconde, milliSec,xannee,xmois,xjour,xheure,xminute,xseconde,xmillisec : Word; NbJour : Integer; JourJul : Double; AD_in_degre, A, B, C, D, JJ, T, H1, HSH, HS, AngleH, AngleT, PI : Single ; begin PI := 3.14159 ; Date1 := now; decodeDateTime(now, Annee, Mois, Jour, Heure, Minute, Seconde, milliSec); decodeDateTime(ad,xannee,xmois,xjour, xheure, xminute, xseconde,xmillisec); JourJul := DateTimeToJulianDate(Date1);// + NbJour; AD_in_degre := 15 * (xheure + (xminute / 60) + (xseconde / 3600)); If (mois < 3) Then begin mois := mois + 12 ; annee := annee - 1 ; End ; A := Int(annee / 100); B := 2 - A + Int(A / 4) ; C := Int(365.25 * annee) ; D := Int(30.6001 * (mois + 1)) ; JJ := B + C + D + jour + 1720994.5 ; T := (JJ - 2451545) / 36525 ; H1 := 24110.54841 + (8640184.812866 * T) + (0.093104 * (T * T)) - (0.0000062 * (T * T * T)) ; HSH := H1 / 3600 ; HS := ((HSH / 24) - Int(HSH / 24)) * 24 ; ; AngleH := (2 * PI * HS / (23 + 56 / 60 + 4 / 3600)) * 180 / PI ; AngleT := ((heure - 12 + (Minute / 60) - Zone) * 2 * PI / (23 + 56 / 60 + 4 / 3600)) * 180 / PI ; Angle_horaire := AngleH + AngleT - AD_in_degre + Longitude ; end; function tform1.Arsin (X : Single) : Single ; begin If (Abs(X) >= 1) Then Arsin := 0 Else Arsin := arctan(X / sqr(-X * X + 1)) ; End ; Function TForm1.Arcos( X : Single) : Single; begin If (Abs(X) >= 1) Then Arcos := 0 Else Arcos := arctan(-X / Sqr(-X * X + 1)) + 2 * arctan(1); End ; Function TForm1.Hauteur(Dec : Single; Latitude : Single; H : Single) : Single ; var Sin_hauteur, PI : Single ; begin PI := 3.14159 ; Sin_hauteur := Sin(Dec * PI / 180) * Sin(Latitude * PI / 180) - Cos(Dec * PI / 180) * Cos(Latitude * PI / 180) * Cos(H * PI / 180) ; Hauteur := Arsin(Sin_hauteur) * 180 / PI; End ; Function TForm1.Azimuth(Dec: Single; Lat: Single; H: Single; Haut: Single):Single ; var Cosazimuth, Sinazimuth, test, Az, PI : Single ; begin PI := 3.14159 ; Cosazimuth := (Sin(Dec * PI / 180) - Sin(Lat * PI / 180) * Sin(Haut * PI / 180)) / (Cos(Lat * PI / 180) * Cos(Haut * PI / 180)); Sinazimuth := (Cos(Dec * PI / 180) * Sin(H * PI / 180)) / Cos(Haut * PI / 180); If (Sinazimuth > 0) Then Az := Arcos(Cosazimuth) * 180 / PI Else Az := -Arcos(Cosazimuth) * 180 / PI ; If (Az < 0) Then Azimuth := 360 + Az Else Azimuth := Az; End ;
mais "hauteur" et "azimut" non (en VB tout fonctionne)
ne connaissant rien en trigo, je me demande si les fonctions pareillement nommées en VB/Pascal donnent les mêmes résultats
j'ai pu vérifier "sin" et "cos" qui semblent bonnes
qu'en penses-vous?
merci de m'avoir lu
Partager