Vous êtes sur la page 1sur 2

#include <stdio.

h>
#include <math.h> // Include this header for the pow and sqrt functions
#define TMAX 100
typedef struct point {
double x, y, z;
} point;
typedef struct Segment {
point start,end;
} Segment;
typedef struct Ligne {
int N; // Le nombre de points dans la ligne
point points[TMAX]; // Un tableau de points de taille TMAX
} Ligne;
int main() {
point p1 = {6.9, 7.3, 4.2};
point p2 = {1.0, 1.0, 1.0};
double dx, dy, dz, D, t;
printf("( %.2f --- %.2f --- %.2f )", p1.x, p1.y, p1.z);
printf("\n( %.2f --- %.2f --- %.2f )", p2.x, p2.y, p2.z);

dx = (p1.x - p2.x);
dy = (p1.y - p2.y);
dz = (p1.z - p2.z);

t = pow(dx, 2) + pow(dy, 2) + pow(dz, 2);


D = sqrt(t);

printf("\nla distance entre p1 et p2 est : %.2f", D);

Segment s = {p1, p2};

printf("\n[");
printf("(%.1f, %.1f, %.1f ) ---", s.start.x, s.start.y, s.start.z);
printf(" (%.1f, %.1f, %.1f)", s.end.x, s.end.y, s.end.z);
printf("]\n");

Ligne ligne;
double longueur = 0.0;
// Initialisation de la ligne avec 3 points
ligne.N = 3;
ligne.points[0] = (point){3.2, 5.0, 1.0};
ligne.points[1] = (point){4.6, 3.0, 0.0};
ligne.points[2] = (point){2.0, 2.5, 3.0};
// Affichage des points de la ligne
for (int i = 0; i < ligne.N; i++) {
printf("(%.1f, %.1f, %.1f) ", ligne.points[i].x, ligne.points[i].y,
ligne.points[i].z);
}
printf("\n");
// Calcul de la longueur de la ligne
for (int i = 0; i < ligne.N - 1; i++) {
dx = ligne.points[i+1].x - ligne.points[i].x;
dy = ligne.points[i+1].y - ligne.points[i].y;
dz = ligne.points[i+1].z - ligne.points[i].z;
longueur += sqrt(dx*dx + dy*dy + dz*dz);
}

// Affichage de la longueur de la ligne


printf("La longueur de la ligne est : %.2f\n", longueur);
return 0;
}

pour python
#include <stdio.h>
#include <math.h> // Include this header for the pow and sqrt functions
#define TMAX 100
typedef struct point {
double x, y, z;
} point;
typedef struct Segment {
point start,end;
} Segment;
typedef struct Ligne {
int N; // Le nombre de points dans la ligne
point points[TMAX]; // Un tableau de points de taille TMAX
} Ligne;
int main() {

Ligne ligne;
double longueur = 0.0;
// Initialisation de la ligne avec 3 points
ligne.N = 3;
ligne.points[0] = (point){3.2, 5.0, 1.0};
ligne.points[1] = (point){4.6, 3.0, 0.0};
ligne.points[2] = (point){2.0, 2.5, 3.0};
// Affichage des points de la ligne
for (int i = 0; i < ligne.N; i++) {
printf("(%.1f, %.1f, %.1f) ", ligne.points[i].x, ligne.points[i].y,
ligne.points[i].z);
}
printf("\n");
// Calcul de la longueur de la ligne
for (int i = 0; i < ligne.N - 1; i++) {
double dx = ligne.points[i+1].x - ligne.points[i].x;
double dy = ligne.points[i+1].y - ligne.points[i].y;
double dz = ligne.points[i+1].z - ligne.points[i].z;
longueur += (dx*dx + dy*dy + dz*dz);
}

// Affichage de la longueur de la ligne


printf("La longueur de la ligne est : %.2f\n", longueur);

return 0;
}

Vous aimerez peut-être aussi