#include #include typedef struct { double x; double y; double z; } sommet; typedef struct { sommet s1; sommet s2; sommet s3; } triangle; double calculerDistance(sommet s1, sommet s2) { return sqrt(pow(s2.x - s1.x, 2.0) + pow(s2.y - s1.y, 2.0) + pow(s2.z - s1.z, 2.0)); } double calculerPerimetre(triangle t) { return calculerDistance(t.s1, t.s2) + calculerDistance(t.s2, t.s3) + calculerDistance(t.s3, t.s1); } double calculerAire(triangle t) { double s = calculerPerimetre(t) / 2.0; double a = calculerDistance(t.s1, t.s2); double b = calculerDistance(t.s2, t.s3); double c = calculerDistance(t.s3, t.s1); return sqrt(s*(s-a)*(s-b)*(s-c)); } void afficherSommet(sommet s) { printf("("); printf("%.3lf",s.x); printf(","); printf("%.3lf", s.y); printf(","); printf("%.3lf", s.z); printf(")"); } void afficherTriangle(triangle t) { printf("("); afficherSommet(t.s1); printf(","); afficherSommet(t.s2); printf(","); afficherSommet(t.s3); printf(")"); } int main(void) { triangle t = { { -2.2,-0.3,6.4 }, { 3.1,-2.3,4.1 }, { 3.6, 2.7,0.4 } }; //triangle t = { { 4.0, 0.0,1.4 }, // { 0.0, 0.0,1.4 }, // { 0.0, 3.0,1.4 } }; afficherTriangle(t); printf("\n"); printf("Perimetre = %lf\n", calculerPerimetre(t)); printf("Aire = %lf\n", calculerAire(t)); printf("\n"); return 0; }