online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code    Language
#include <iostream> #include <math.h> #include <cstdlib> #include<bits/stdc++.h> using namespace std; typedef struct ANGLE_DEG; struct ANGLE_DEG { double Deg; double Min; double Sec; }; double orthodromie(double Long1, double Lat1, double Long2, double Lat2); double orthodromie_2(double Long1, double Lat1, double Long2, double Lat2); double Calcul_Direct(double Long_centre, double Lat_centre , double Lat0, double R_Rech); void Angle_Rad_Deg(double Ang_Rad, ANGLE_DEG *Angle_Deg); double Long0_Lat0(double Lat0, double Long_centre, double Lat_centre, double R_Rech); double Rterre = 6371; // Rayon de la terre en km // pour 1 minute -> 1 mile marin = 1852.22 metres double Rterre_Pol = 6356.988; // Rayon polaire de la terre en km double Rterre_Equa = 6378.388; // Rayon equatorial de la terre en km // double Rterre_Pol = 6371; // Rayon polaire de la terre en km //double Rterre_Equa = 6371; // Rayon equatorial de la terre en km double Pi = 4 * atan(1); int main(int argc, char *argv[]) { int Lat_Deg, Lat_Min, Lat_Sec; int Long_Deg, Long_Min, Long_Sec; double Lat_centre, Long_centre, Lat0, Lat0_max, Lat0_min; double R_Rech; double Phi, Pas_Lat0; ANGLE_DEG Lat; ANGLE_DEG Long; int i; double Lat0_Long0(double Long0, double Long_centre, double Lat_centre, double R_Rech); /* // Entrée Latitude cout << "Latitude du centre de recherche en Degres Minute Seconde \n Entrer Valeur degres ? " << endl; cin >> Lat_Deg; cout << "\n Entrer Valeur minutes ? " << endl; cin >> Lat_Min; cout << "\n Entrer Valeur secondes ? " << endl; cin >> Lat_Sec; cout << "Latitude du centre de recherche = " << Lat_Deg << " Degres " << Lat_Min << " Minutes " << Lat_Sec << "Secondes" << endl; Lat_centre = Lat_Deg + Lat_Min / 60.0 + Lat_Sec / 3600.0 ; Lat_centre = Lat_centre * Pi / 180.0; // Conversion en radians cout << "Latitude du centre de recherche en radians = " << Lat_centre << endl; // Entrée Longitude cout << "\n Longitude du centre de recherche en Degres Minute Seconde \n Entrer Valeur degres ? " << endl; cin >> Long_Deg; cout << "\n Entrer Valeur minutes ? " << endl; cin >> Long_Min; cout << "\n Entrer Valeur secondes ? " << endl; cin >> Long_Sec; cout << "Longitude du centre de recherche = " << Long_Deg << " Degres " << Long_Min << " Minutes " << Long_Sec << "Secondes" << endl; Long_centre = Long_Deg + Long_Min / 60.0 + Long_Sec / 3600.0 ; Long_centre = Long_centre * Pi / 180.0; // Conversion en radians cout << "Longitude du centre de recherche en radians = " << Long_centre << endl; cout << " Entrer la Valeur du rayon de recherche en km \n " << endl; cin >> R_Rech; cout << " Rayon de recherche en km \n " << R_Rech << endl; */ Long_centre = Pi/20.0; Lat_centre = Pi/4.0; R_Rech = 450.0; // en km // Calcul du rayon de la terre en fonction de Lat_centre Rterre = sqrt(Rterre_Equa * Rterre_Equa * cos(Lat_centre) * cos(Lat_centre) + Rterre_Pol * Rterre_Pol * sin(Lat_centre)* sin(Lat_centre)); cout << " Rterre equatorial = " << Rterre_Equa << " km" << endl; cout << " Rterre polaire = " << Rterre_Pol << " km" << endl; cout << " Rterre calcul = " << Rterre << " km" << endl; // Calcul Lat0_min et Lat0_max Phi = R_Rech / Rterre; cout << " Phi = " << Phi <<endl; Lat0_max = Lat_centre + Phi; Lat0_min = Lat_centre - Phi; cout << setprecision (12) << " Lat_centre = " << Lat_centre <<endl; cout << setprecision (12) <<" Long_centre = " << Long_centre <<endl; cout << setprecision (12) << " Lat0_min = " << Lat0_min <<endl; cout << setprecision (12) << " Lat0_max = " << Lat0_max <<endl; cout << setprecision (8) << " Rayon de recherche en km = " << R_Rech << " Rayon de recherche en miles = " << R_Rech/1.862 << endl; cout << " Pi/2 = " << Pi/2.0 <<endl; if (Lat0_min >= Pi/2.0 || Lat0_max >= Pi/2.0) { cout << " CALCUL IMPOSSIBLE Lat0_max >= 90°" << endl; system ("PAUSE"); } // Verif cout << " ORTHO LAT0 MAX = " << orthodromie(Long_centre, Lat_centre,Long_centre, Lat0_max) << endl; cout << " ORTHO LAT0 MIN = " << orthodromie(Long_centre, Lat_centre,Long_centre, Lat0_min) << endl; Pas_Lat0 = (Lat0_max - Lat0_min) / 180.0; // en radians 1 degres cout << " Pas_Lat0 = " << Pas_Lat0 << endl; Phi = Pas_Lat0 * Pi / 180.0; cout << " Phi en degres = " << Phi <<endl; double Lg0, Lg1; FILE * Fichier; Fichier = fopen ("Toto.txt", "w+a"); fprintf(Fichier, "%s %f %s \n", " Rterre equatorial = ", Rterre_Equa, " km" ); fprintf(Fichier, "%s %f %s \n", " Rterre polaire = ", Rterre_Pol, " km" ); fprintf(Fichier, "%s %f %s \n", " Rterre calcul = ", Rterre, " km" ); fprintf(Fichier, "%s %12.11f %s %12.11f \n", "Lat_centre = ", Lat_centre, " Long_centre = " , Long_centre); fprintf(Fichier, "%s %12.11f %s %12.11f \n", "Lat0_min = ", Lat0_min, " Lat0_max = ", Lat0_max); fprintf(Fichier, "%s %6.2f %s \n\n\n", "Rayon de recherche = ", R_Rech, " km"); for (i = 0; i <= 180; i++) { Lat0 = Lat0_min + Pas_Lat0 * i ; // Methode Dichotomie Lg0 = Lat0_Long0(Lat0, Long_centre, Lat_centre, R_Rech); Lg1 = 2 * Long_centre - Lg0; Angle_Rad_Deg(Lat0, &Lat); Angle_Rad_Deg(Lg0, &Long); // fprintf(Fichier, " Lat0 = %12.11f Lg0 = %f Lat0 = %2.0d deg %2.0d ' %2.0d '' Lg0 = %2.0d deg %3.1d ' %3.1d ''\n", // Lat0, Lg0, int(Lat.Deg),int(Lat.Min), int(Lat.Sec), int(Long.Deg), int(Long.Min), int(Long.Sec)); fprintf(Fichier, "%12.11f %12.11f \n", Lat0, Lg0); printf( " Methode Dichotomie Lat0 = %12.11f Lg0 = %12.11f Lat0 = %2.0d deg %2.0d ' %2.0d '' Lg0 = %2.0d deg %3.1d ' %3.1d ''\n", Lat0, Lg0, int(Lat.Deg),int(Lat.Min), int(Lat.Sec), int(Long.Deg), int(Long.Min), int(Long.Sec)); Angle_Rad_Deg(Lat0, &Lat); Angle_Rad_Deg(Lg1, &Long); printf( " Methode Dichotomie Lat0 = %12.11f Lg1 = %12.11f Lat0 = %2.0d deg %2.0d ' %2.0d '' Lg1 = %2.0d deg %3.1d ' %3.1d ''\n", Lat0, Lg1, int(Lat.Deg),int(Lat.Min), int(Lat.Sec), int(Long.Deg), int(Long.Min), int(Long.Sec)); // Methode Directe Lg0 = Calcul_Direct(Long_centre, Lat_centre , Lat0, R_Rech); Lg1 = 2 * Long_centre - Lg0; Angle_Rad_Deg(Lat0, &Lat); Angle_Rad_Deg(Lg0, &Long); printf( " Methode directe Lat0 = %12.11f Lg0 = %12.11f Lat0 = %2.0d deg %2.0d ' %2.0d '' Lg0 = %2.0d deg %3.1d ' %3.1d ''\n", Lat0, Lg0, int(Lat.Deg),int(Lat.Min), int(Lat.Sec), int(Long.Deg), int(Long.Min), int(Long.Sec)); Angle_Rad_Deg(Lat0, &Lat); Angle_Rad_Deg(Lg1, &Long); printf( " Methode directe Lat0 = %12.11f Lg0 = %12.11f Lat0 = %2.0d deg %2.0d ' %2.0d '' Lg1 = %2.0d deg %3.1d ' %3.1d ''\n\n", Lat0, Lg0, int(Lat.Deg),int(Lat.Min), int(Lat.Sec), int(Long.Deg), int(Long.Min), int(Long.Sec)); } fclose(Fichier); return 0; } //****************************************************************************** // orthodromie // Calcul la longueur de la route orthonomique entre les points de // longitude (Long1, Long2) et de latitude (Lat1, Lat2) exprimes en Radians // orthodromie en km //****************************************************************************** double orthodromie(double Long1, double Lat1, double Long2, double Lat2) { double Corde; Corde = pow((sin(Long1) * cos(Lat1) - sin(Long2) * cos(Lat2)), 2); Corde = Corde + pow((cos(Long1) * cos(Lat1) - cos(Long2) * cos(Lat2)),2); Corde = Corde + pow((sin(Lat1) - sin(Lat2)),2); Corde = sqrt(Corde); return( 2.0 * Rterre * (asin(Corde / 2.0))); } //****************************************************************************** // orthodromie_2 // Calcul la longueur de la route orthonomique entre les points de // longitude (Long1, Long2) et de latitude (Lat1, Lat2) exprimes en Radians // orthodromie en km // Pour calculer cette distance, on utilise la formule des cosinus de la trigonométrie sphérique. // Soient Lat1, Lat2 les latitudes de A et B et Long1, Long2 leurs longitudes. // Pour cela on considère le triangle ABC tel que C soit le pôle nord. // Les cotés du triangle sont a (complémentaire de Lat1 pour A), b (complémentaire de Long2 pour B), // et l'angle γ du triangle en C vaut Long2 − Long2 (différence des longitudes). // L'arc AB vaut : // c = arccos[sin(la).sin(lb) + cos(la).cos(lb).cos(LB − LA)] // Si on exprime c en radian, la distance entre A et B est dAB = R.c km (R est le rayon terrestre moyen). double orthodromie_2(double Long1, double Lat1, double Long2, double Lat2) { double c ; c = acos(sin(Lat1) * sin(Lat2) + (cos(Lat1) * cos(Lat2) * cos(Long2 - Long1))); return( Rterre * c); } // Calcul Direct : Inversion de orthodromie_2 double Calcul_Direct(double Long_centre, double Lat_centre , double Lat0, double R_Rech) { double c, Lg0; c = R_Rech / Rterre; Lg0 = Long_centre + acos(( cos(c) - sin(Lat_centre) * sin(Lat0)) / (cos(Lat_centre) * cos(Lat0))); return Lg0; } // Transformation des angles de radians en degres minute seconde void Angle_Rad_Deg(double Angle_Rad, ANGLE_DEG *Angle_Deg) { Angle_Deg-> Deg = Angle_Rad * 180.0/Pi; Angle_Deg-> Min = (Angle_Deg -> Deg - int(Angle_Deg -> Deg)) * 60.0 ; Angle_Deg-> Sec = (Angle_Deg-> Min - int(Angle_Deg-> Min)) * 60.0; } double Lat0_Long0(double Lat0, double Long_centre, double Lat_centre, double R_Rech) //********************************************************************************************************** // Renvoie la longitude Long0 en fonction de la latitude Lat0 et des coordonées du centre de recherches : // (Long_centre, Lat_centre en radians) et du Rayon de recherche en km Methode par dichotomie //********************************************************************************************************** { int i; double Ortho0 = 0.0; double Epsilon = 0.000000001; // précision du calcul double Pas = R_Rech /100.0; // Valeur initiale du pas double Long0_1; double Long_Depart = Long_centre ; T10: for ( i = 0; i < 50; i++) { Long0_1 = Long_Depart + Pas * i; Ortho0 = orthodromie(Long0_1, Lat0, Long_centre, Lat_centre); if(abs(Ortho0 - R_Rech )<= Epsilon) { return ( Long0_1); } if ((Ortho0 - R_Rech) >= 0) { Long_Depart = Long0_1 - Pas; Pas = Pas /2.0; // system ("PAUSE"); goto T10; } else { Long_Depart = Long0_1 + Pas; Pas = Pas /2.0; // system ("PAUSE"); goto T10; } } }
Rterre equatorial = 6378.388000 km Rterre polaire = 6356.988000 km Rterre calcul = 6367.696990 km Lat_centre = 0.78539816340 Long_centre = 0.15707963268 Lat0_min = 0.71472897158 Lat0_max = 0.85606735521 Rayon de recherche = 450.00 km 0.71472897158 0.15707963268 0.71551418482 0.17145415085 0.71629939807 0.17735859710 0.71708461131 0.18185511997 0.71786982455 0.18561711274 0.71865503779 0.18890605650 0.71944025104 0.19185636445 0.72022546428 0.19454806016 0.72101067752 0.19703339374 0.72179589076 0.19934873213 0.72258110401 0.20152060562 0.72336631725 0.20356908002 0.72415153049 0.20550977240 0.72493674373 0.20735512340 0.72572195698 0.20911523623 0.72650717022 0.21079845007 0.72729238346 0.21241174423 0.72807759670 0.21396103023 0.72886280995 0.21545136771 0.72964802319 0.21688712714 0.73043323643 0.21827211454 0.73121844967 0.21960966852 0.73200366291 0.22090273677 0.73278887616 0.22215393719 0.73357408940 0.22336560713 0.73435930264 0.22453984358 0.73514451588 0.22567853619 0.73592972913 0.22678339467 0.73671494237 0.22785597163 0.73750015561 0.22889768186 0.73828536885 0.22990981861 0.73907058210 0.23089356749 0.73985579534 0.23185001832 0.74064100858 0.23278017541 0.74142622182 0.23368496639 0.74221143507 0.23456524993 0.74299664831 0.23542182243 0.74378186155 0.23625542393 0.74456707479 0.23706674330 0.74535228804 0.23785642278 0.74613750128 0.23862506205 0.74692271452 0.23937322184 0.74770792776 0.24010142710 0.74849314101 0.24081016991 0.74927835425 0.24149991200 0.75006356749 0.24217108711 0.75084878073 0.24282410303 0.75163399397 0.24345934347 0.75241920722 0.24407716979 0.75320442046 0.24467792251 0.75398963370 0.24526192271 0.75477484694 0.24582947331 0.75556006019 0.24638086022 0.75634527343 0.24691635338 0.75713048667 0.24743620777 0.75791569991 0.24794066422 0.75870091316 0.24842995033 0.75948612640 0.24890428108 0.76027133964 0.24936385963 0.76105655288 0.24980887789 0.76184176613 0.25023951709 0.76262697937 0.25065594837 0.76341219261 0.25105833319 0.76419740585 0.25144682387 0.76498261910 0.25182156394 0.76576783234 0.25218268858 0.76655304558 0.25253032493 0.76733825882 0.25286459245 0.76812347206 0.25318560323 0.76890868531 0.25349346226 0.76969389855 0.25378826767 0.77047911179 0.25407011102 0.77126432503 0.25433907748 0.77204953828 0.25459524606 0.77283475152 0.25483868978 0.77361996476 0.25506947585 0.77440517800 0.25528766583 0.77519039125 0.25549331578 0.77597560449 0.25568647638 0.77676081773 0.25586719306 0.77754603097 0.25603550609 0.77833124422 0.25619145070 0.77911645746 0.25633505717 0.77990167070 0.25646635086 0.78068688394 0.25658535234 0.78147209719 0.25669207741 0.78225731043 0.25678653713 0.78304252367 0.25686873792 0.78382773691 0.25693868150 0.78461295016 0.25699636502 0.78539816340 0.25704178097 0.78618337664 0.25707491724 0.78696858988 0.25709575712 0.78775380312 0.25710427923 0.78853901637 0.25710045759 0.78932422961 0.25708426148 0.79010944285 0.25705565550 0.79089465609 0.25701459946 0.79167986934 0.25696104835 0.79246508258 0.25689495225 0.79325029582 0.25681625629 0.79403550906 0.25672490052 0.79482072231 0.25662081986 0.79560593555 0.25650394394 0.79639114879 0.25637419704 0.79717636203 0.25623149790 0.79796157528 0.25607575964 0.79874678852 0.25590688953 0.79953200176 0.25572478889 0.80031721500 0.25552935289 0.80110242825 0.25532047029 0.80188764149 0.25509802333 0.80267285473 0.25486188739 0.80345806797 0.25461193082 0.80424328121 0.25434801462 0.80502849446 0.25406999216 0.80581370770 0.25377770885 0.80659892094 0.25347100184 0.80738413418 0.25314969960 0.80816934743 0.25281362153 0.80895456067 0.25246257756 0.80973977391 0.25209636764 0.81052498715 0.25171478129 0.81131020040 0.25131759698 0.81209541364 0.25090458163 0.81288062688 0.25047548990 0.81366584012 0.25003006350 0.81445105337 0.24956803050 0.81523626661 0.24908910445 0.81602147985 0.24859298348 0.81680669309 0.24807934939 0.81759190634 0.24754786654 0.81837711958 0.24699818071 0.81916233282 0.24642991782 0.81994754606 0.24584268257 0.82073275930 0.24523605686 0.82151797255 0.24460959815 0.82230318579 0.24396283760 0.82308839903 0.24329527801 0.82387361227 0.24260639155 0.82465882552 0.24189561726 0.82544403876 0.24116235824 0.82622925200 0.24040597852 0.82701446524 0.23962579956 0.82779967849 0.23882109636 0.82858489173 0.23799109302 0.82937010497 0.23713495778 0.83015531821 0.23625179738 0.83094053146 0.23534065066 0.83172574470 0.23440048127 0.83251095794 0.23343016928 0.83329617118 0.23242850160 0.83408138443 0.23139416082 0.83486659767 0.23032571238 0.83565181091 0.22922158944 0.83643702415 0.22808007526 0.83722223740 0.22689928233 0.83800745064 0.22567712761 0.83879266388 0.22441130283 0.83957787712 0.22309923881 0.84036309036 0.22173806194 0.84114830361 0.22032454088 0.84193351685 0.21885502056 0.84271873009 0.21732533944 0.84350394333 0.21573072467 0.84428915658 0.21406565741 0.84507436982 0.21232369717 0.84585958306 0.21049724879 0.84664479630 0.20857724724 0.84743000955 0.20655272191 0.84821522279 0.20441017831 0.84900043603 0.20213269391 0.84978564927 0.19969854753 0.85057086252 0.19707904842 0.85135607576 0.19423490613 0.85214128900 0.19110972338 0.85292650224 0.18761720503 0.85371171549 0.18361253579 0.85449692873 0.17881425376 0.85528214197 0.17249817745 0.85606735521 0.15707963268

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text
×

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue