2023-02-02 17:24:21 +01:00
|
|
|
#include<graph.h>
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
|
|
|
|
void visuelGraphe(graphe g){
|
|
|
|
int taille=1000;
|
|
|
|
int origine=taille/2;
|
|
|
|
int distance=4*origine/5;
|
|
|
|
int tailleVert=taille/20;
|
|
|
|
InitialiserGraphique();
|
|
|
|
CreerFenetre(10,10,taille,taille);
|
|
|
|
|
|
|
|
int i,j;
|
|
|
|
int x,y;
|
|
|
|
char* nV=malloc(2);
|
2023-02-02 17:26:05 +01:00
|
|
|
*nV='0';
|
2023-02-02 17:24:21 +01:00
|
|
|
*(nV+1)='\0';
|
|
|
|
int* cX=calloc(g.ordre,sizeof(int));
|
|
|
|
int* cY=calloc(g.ordre,sizeof(int));
|
|
|
|
for(i=0;i<g.ordre;i++){
|
|
|
|
x=(int) origine+distance*cos(2*M_PI*i/g.ordre);
|
|
|
|
y=(int) origine+distance*sin(2*M_PI*i/g.ordre);
|
|
|
|
cX[i]=x+tailleVert/2;
|
|
|
|
cY[i]=y+tailleVert/2;
|
|
|
|
RemplirArc(x,y,tailleVert,tailleVert,0,360);
|
|
|
|
EcrireTexte(x,y,nV,2);
|
|
|
|
(*nV)++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-02-03 11:16:06 +01:00
|
|
|
|
|
|
|
//Version si le graphe est une matrice d'adjacence
|
2023-02-02 17:24:21 +01:00
|
|
|
for(i=0;i<g.ordre;i++){
|
|
|
|
for(j=0;j<g.ordre;j++){
|
|
|
|
if(g.adj[i][j]!=0){
|
|
|
|
DessinerSegment(cX[i],cY[i],cX[j],cY[j]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-02-03 11:16:06 +01:00
|
|
|
//Version à utiliser si le graph est un tableau de listes chaînées
|
|
|
|
/*
|
|
|
|
maillon* read;
|
|
|
|
for(i=0;i<g.ordre;i++){
|
|
|
|
read=g.voisins[i];
|
|
|
|
while(read!=NULL){
|
|
|
|
DessinerSegment(cX[i],cY[i],cX[read->valeur],cY[read->valeur]);
|
|
|
|
read=read->suivant;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
2023-02-02 17:24:21 +01:00
|
|
|
Touche();
|
|
|
|
FermerGraphique();
|
|
|
|
|
|
|
|
}
|
2023-02-10 11:20:45 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Aides matrices
|
|
|
|
//Creation matrice carrée vide :
|
|
|
|
int** creerMatriceId(int taille){
|
2023-02-10 11:49:12 +01:00
|
|
|
int** res=calloc(taille,sizeof(int*));
|
2023-02-10 11:20:45 +01:00
|
|
|
for(int i=0;i<taille;i++){
|
2023-02-10 11:49:12 +01:00
|
|
|
res[i]=calloc(taille,sizeof(int));
|
2023-02-10 11:20:45 +01:00
|
|
|
for(int j=0;j<taille;j++){
|
|
|
|
res[i][j]=(i==j)?1:0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Creation copie d'une matrice carree :
|
|
|
|
int** recopierMatrice(int **m,int taille){
|
|
|
|
int** creerMatriceId(int taille){
|
2023-02-10 11:59:54 +01:00
|
|
|
int** res=calloc(taille,sizeof(int*));
|
2023-02-10 11:20:45 +01:00
|
|
|
for(int i=0;i<taille;i++){
|
2023-02-10 11:49:12 +01:00
|
|
|
res[i]=calloc(taille,sizeof(int));
|
2023-02-10 11:20:45 +01:00
|
|
|
for(int j=0;j<taille;j++){
|
|
|
|
res[i][j]=m[i][j];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|