Am nevoie de un program in c++ ce studiaza 2 triunghiuri si verifica daca au aceiasi arie si sunt congruente
Programul va folosi o funcţie, ce determină distanţa dintre 2 puncte.
Răspunsuri la întrebare
#include <iostream>
#include <math.h>
#include <algorithm>
using namespace std;
struct punct{
double x,y;
};
struct triunghi{
punct A, B, C;
};
triunghi A, B;
double dist(double x, double y){
return sqrt(x * x + y * y);
}
double dist(punct a, punct b){
return dist(a.x-b.x, a.y-b.y);
}
int main(){
cin >> A.A.x >> A.A.y >> A.B.x >> A.B.y >> A.C.x >> A.C.y; // primul triunghi
cin >> B.A.x >> B.A.y >> B.B.x >> B.B.y >> B.C.x >> B.C.y; //al doilea triunghi
double dist11 = dist(A.A,A.B);
double dist12 = dist(A.A,A.C);
double dist13 = dist(A.B,A.C);
double semiper = (dist11+dist12+dist13) / 2;
double a1 = sqrt(semiper * (semiper - dist11) * (semiper-dist12) * (semiper - dist13)); // Aria cu formula lui Heron
double dist21 = dist(A.A,A.B);
double dist22 = dist(A.A,A.C);
double dist23 = dist(A.B,A.C);
semiper = (dist21+dist22+dist23) / 2;
double a2 = sqrt(semiper * (semiper - dist21) * (semiper-dist22) * (semiper - dist23)); // Aria cu formula lui Heron
if(a1 == a2){
cout << "Arii egale";
}else{
cout << "Arii diferite";
}
cout << endl;
double dist1[] = {dist11,dist12,dist13};
double dist2[] = {dist21, dist22, dist23};
sort(&dist1[0], &dist1[3]);
sort(&dist2[0], &dist2[3]);
double k = dist1[0] / dist2[0];
if(dist1[1] == k*dist2[1] && dist1[2] == k*dist2[2]){
cout << "Sunt asemenea";
}else cout << "Nu sunt asemenea";
}