CONNEXION
  • RetourJeux
    • Sorties
    • Hit Parade
    • Les + populaires
    • Les + attendus
    • Soluces
    • Tous les Jeux
    • Gaming
  • RetourActu Gaming
    • News
    • Astuces
    • Tests
    • Previews
    • Toute l'actu gaming
  • RetourBons plans
    • Bons plans
    • Bons plans Smartphone
    • Bons plans Hardware
    • Bons plans Image et Son
    • Bons plans Amazon
    • Bons plans Cdiscount
    • Bons plans Decathlon
    • Bons plans Fnac
    • Tous les Bons plans
  • RetourJVTech
    • Actus High-Tech
    • Intelligence Artificielle
    • Smartphones
    • Mobilité urbaine
    • Hardware
    • Image et son
    • Tutoriels
    • Tests produits High-Tech
    • Guides d'achat High-Tech
    • JVTech
  • RetourCulture
    • Actus Culture
    • Culture
  • RetourVidéos
    • A la une
    • Gaming Live
    • Vidéos Tests
    • Vidéos Previews
    • Gameplay
    • Trailers
    • Chroniques
    • Replay Web TV
    • Toutes les vidéos
  • RetourForums
    • Hardware PC
    • PS5
    • Switch 2
    • Xbox Series
    • Switch
    • Pokemon pocket
    • FC 25 Ultimate Team
    • League of Legends
    • Tous les Forums
  • PC
  • PS5
  • Xbox Series
  • Switch 2
  • PS4
  • One
  • Switch
  • iOS
  • Android
  • MMO
  • RPG
  • FPS
En ce moment Genshin Impact Valhalla Breath of the wild Animal Crossing GTA 5 Red dead 2
Liste des sujets

[root] graphique

Killer1995
Killer1995
Niveau 7
26 mai 2016 à 18:10:54

Salut !

J'ai un problème pour afficher plusieurs graphiques et les réunir que sur un seul. J'ai essayé de cehrcehr sur le net mais sans succès. Je sais que c'est possible mais je n'y arrive pas. je vous mets mon main et mon fichier.cpp plus bas:

main.cpp:

  1. include <iostream>
  2. include <iomanip>
  3. include <cmath>
  4. include <vector>
  5. include "TString.h"
  6. include "EDO.h"
  7. include "EDOtest.h"
  8. include "Vecteur.h"
  9. include "TGraph.h"
  10. include "TFile.h"
  11. include "TCanvas.h"
  12. include "TLegend.h"
  13. include "TAxis.h"
  14. include "TApplication.h"
  15. include <TROOT.h>

using namespace std;

int main (int argc, char **argv)
{

TApplication theApp("App", &argc, argv);
TFile *fichier_root=TFile::Open("RK.root","RECREATE");

//Terre:
double A[4]={149600000000.0,0.0, 0.0, 29000.0};// on a xterre (au périhélie), vxterre, yterre, vyterre (donc la vitesse max, car au périhélie). Idem pour toutes les planètes.
Vecteur y0(4, A);
double x0=0.0;
double xf=31558144.0;//période de révolution. Idem pour toutes les planètes

//Mercure:
double B[4]={46001272000.0,0.0, 0.0, 58980.0};// x, vx, y, vy
Vecteur y10(4, B);
double x10=0.0;
double xf1=7603200.0;

//Venus:
double C[4]={107476259000.0,0.0, 0.0, 35260.0};// x, vx, y, vy
Vecteur y20(4, C);
double x20=0.0;
double xf2=19440000.0;

EDO2 Mercure(1000); //calcul position avec rk2 pour Mercure
Mercure.rk2(x10, y10 , xf1);
Mercure.ecrirexyz("Mercure.dat");
Mercure.ecrirexyzROOT("Mercure.root",m);

m++;//rouge

EDO2 Venus(1000); //calcul position avec rk2 pour Venus
Venus.rk2(x20, y20 , xf2);
Venus.ecrirexyz("Venus.dat");
Venus.ecrirexyzROOT("Venus.root",m);

m++;//vert

EDO2 Terre(1000);//nombre de points //calcul position avec rk2 pour Terre
Terre.rk2(x0, y0 , xf);
Terre.ecrirexyz("Terre.dat");
Terre.ecrirexyzROOT("Terre.root",m);

fichier_root->Close();

// Affichage des figures si mode interactif (pas en mode batch)
if(!gROOT->IsBatch()) theApp.Run();

return 0;
}

Killer1995
Killer1995
Niveau 7
26 mai 2016 à 18:18:45

je mets mon EDO.cpp et mon EDO.h

.cpp :

Vecteur EDO1Systeme::rk2(double x0, Vecteur y0, double xf)
{
Vecteur y;//vecteur
int D=4;
double x; //temps
y = y0;//position initiale

double h = (xf - x0)/N;//h le pas, en temps. t0=0 ; tf=31 558 144 secondes ; N=30 000
Vecteur k1(D), k2(D);//vecteurs
for (int i = 1 ; i < N+1 ; i++)
{
x = x0 + i*h;
k1 = h * evalyp(x, y);
k2 = h * evalyp(x + h/2, y + k1/2);
y = y + k2;//vecteur P
stocke (i, x, y, evalyp(x, y));
}
cout<<"y= "<<y<<endl;

return y;
}

EDO1Systeme::EDO1Systeme(int Di,int Ni) : D(Di),N(Ni)
{
yf.redim(D);
// On alloue les tableaux servant a stocker x, y, y', z, z' pour chaque point.
xtab=new double [N+1]; // [0..N] => N+1
ytab=new Vecteur [N+1];
yptab=new Vecteur [N+1];
for (int i=0;i<N+1;i++) {
ytab[i].redim(D);
yptab[i].redim(D);
}

}

EDO1Systeme::~EDO1Systeme()
{
// Merci de nettoyer derriere soi...
delete[] xtab;
delete[] ytab;
}

void EDO1Systeme::stocke(int i,double x, Vecteur y, Vecteur yp)
{
xtab[i]=x;
ytab[i]=y;
yptab[i]=yp;
}

void EDO1Systeme::ecrirexyz(const char * nom_fichier)
{
ofstream fichier( nom_fichier );

// On ecrit tout en 5 colonnes dans un fichier
for (int i= 0 ; i < N+1 ; i++)
{
fichier << setw(10) <<"t= "<< setprecision(12) << xtab[i]

<< setw(10) << "Px = "<< setprecision(12) << ytab[i](1)
<< setw(10) << "Py = "<< setprecision(12) << ytab[i](3)

<< setw(10) << "Vx = "<< setprecision(12) << yptab[i](1)
<< setw(10) << "Vy = "<< setprecision(12) << yptab[i](3)

<< setw(10) << "Ax = "<< setprecision(12) << yptab[i](2)
<< setw(10) << "Ay = "<< setprecision(12) << yptab[i](4)<<endl;
}
fichier << endl;
fichier.close();
}

void EDO1Systeme::ecrirexyzROOT(const char * nom_fichier, int G)
{

TCanvas c1("c1","dessin",1000,1000);

//TGraph graphe_new(10000); // crée un graphe de nom graphe_new avec 10000 points
TGraph graphe_SystemeSolaire (10000); // crée un graphe de nom graphe_new avec 10000 points

graphe_SystemeSolaire.SetName("Systeme Solaire"); // nom sans espace (sous lequel il sera sauvé)
graphe_SystemeSolaire.SetTitle("Systeme Solaire"); // donne un titre au graphe graphe_sinus

graphe_SystemeSolaire.SetMarkerColor(2); // donne une couleur (rouge) aux points du graphe

for(int i=0; i<N; i++)
{
graphe_SystemeSolaire.SetPoint(i-1,ytab[i](1),ytab[i](3)); // donne les coordonnées x (abscisse) et (ordonnée) sin(x) au ieme point.
}

graphe_SystemeSolaire.Draw("LP"); //A pour nouveau dessin, L pour avoir une ligne entre les points, P pour voir les points

(graphe_SystemeSolaire.GetXaxis())->SetTitle("X"); // on ajoute l'information sur l'axe X
(graphe_SystemeSolaire.GetYaxis())->SetTitle("Y"); // on ajoute l'information sur l'axe Y

graphe_SystemeSolaire.Write();

c1.SaveAs("Systeme Solaire.png");
}

double EDO2::evalys(double x, Vecteur y)
{
double n=-6.67*pow(10, -11)*1.989*pow(10,30);
double m=sqrt(y(1)*y(1)+y(3)*y(3));

return (n*y(1))/pow(m, 3);
}

double EDO2::evalyss(double x, Vecteur y)
{
double n=-6.67*pow(10, -11)*1.989*pow(10,30);
double m=sqrt(y(1)*y(1)+y(3)*y(3));

return (n*y(3))/pow(m, 3);
}

Killer1995
Killer1995
Niveau 7
26 mai 2016 à 18:20:59

et mon .h

  1. ifndef __EDO_H__
  2. define __EDO_H__
  1. include "Vecteur.h"

class EDO1Systeme {
protected:
int D,N;
Vecteur yf; // Valeurs de y(xf) stockees ici par rk4()
double *xtab;
Vecteur *ytab, *yptab;
void stocke(int i,double x, Vecteur y, Vecteur yp);
public:
EDO1Systeme(int Di, int Ni); // <--- Constructeur complet, avec allocation
// des tableaux, defini dans le .cpp
~EDO1Systeme(); // Destructeur

virtual Vecteur evalyp(double x, Vecteur y)=0;
Vecteur rk2(double x0, Vecteur y0, double xf);

Vecteur rk4(double x0, Vecteur y0, double xf);

double getyf(int i) { return yf(i); }

void ecrirexyz(const char * nom_fichier);
void ecrirexyzROOT(const char * nom_fichier, int G);
};

class EDO2 : public EDO1Systeme {
private:
public:
EDO2(int Ni) : EDO1Systeme(4,Ni) {}

Vecteur evalyp(double x, Vecteur y)
{
Vecteur v(4);
v(1)=y(2);
v(2)=evalys(x, y);
v(3)=y(4);
v(4)=evalyss(x, y);
return v;
}
double evalys(double x, Vecteur y);
double evalyss(double x, Vecteur y);

double getypf() { return getyf(2); }
};

  1. endif

PS: désolé pour le long post...

Killer1995
Killer1995
Niveau 7
26 mai 2016 à 18:32:09

justement j'ai posté sur pastebin et j'ai collé après dans le message...

Sous forums
  • Aide à l'achat Mac
  • Macintosh
  • Création de Jeux
  • Programmation
  • Création de sites web
  • Linux
  • Internet
  • Steam Deck
  • Hardware
La vidéo du moment