Distance sur c
amine
-
amine -
amine -
Bonjour,
Je dispose de 100 points possédant chacun des coordonnées (x,y). Je souhaiterais créer une matrice de 100 * 100 représentant la distance euclidienne entre chacun de ces points.
Etant donné que je débute sur c (CodeBlocks), quelqu'un peut-il me donner un petit coup de pouce?
Merci beaucoup,
A bientôt
Je dispose de 100 points possédant chacun des coordonnées (x,y). Je souhaiterais créer une matrice de 100 * 100 représentant la distance euclidienne entre chacun de ces points.
Etant donné que je débute sur c (CodeBlocks), quelqu'un peut-il me donner un petit coup de pouce?
Merci beaucoup,
A bientôt
4 réponses
-
je propose :
#include <math.h> typedef struct Point Point; struct Point { int x; int y; }; Point tableau_de_point[100]; int Matrice_Distance[100][100]; // initialisation du tableau for(int i=0; i < 100; i++) { tableau_de_point[i].x = ?? ; tableau_de_point[i].y = ?? ; } // ----------- // creation de la matrice de distance for(int i=0; i < 100; i++) { for(int j=0; j<100 ; j++) { Matrice_Distance[i][j] = sqrt( (tableau_de_point[i].x - tableau_de_point[j].x) * (tableau_de_point[i].x - tableau_de_point[j].x) + (tableau_de_point[i].y - tableau_de_point[j].y) * (tableau_de_point[i].y - tableau_de_point[j].y) ); } } // -----------
qu'en penses tu ? -
optimisation:
for(int i=0; i < 100; i++) { for(int j=0; j<100 ; j++) { if(j>i)Matrice_Distance[i][j] = sqrt( (tableau_de_point[i].x - tableau_de_point[j].x) * (tableau_de_point[i].x - tableau_de_point[j].x) + (tableau_de_point[i].y - tableau_de_point[j].y) * (tableau_de_point[i].y - tableau_de_point[j].y) ); else if(i==j)Matrice_Distance[i][j]=0; else Matrice_Distance[i][j]=Matrice_Distance[j][i]; } -
-