#include <iostream>
#include <math.h>
#include <fstream>
#include <bits/stdc++.h>
using namespace std;
typedef struct
{
double x,y;
}punct;
const int inf=1e9;
vector<punct> v,I,J;
double dist(punct a,punct b)
{
return (sqrt((b.x-a.x)*(b.x-a.x)+(b.y-a.y)*(b.y-a.y)));
}
double arie(punct a,punct b,punct c)
{
double p,arie,len_a,len_b,len_c;
len_a=dist(a,b);
len_b=dist(b,c);
len_c=dist(a,c);
p=(len_a+len_b+len_c)/2;
arie=sqrt(p*(p-len_a)*(p-len_b)*(p-len_c));
return arie;
}
bool coliniare(punct a,punct b,punct c)
{
int ok=0;
double a1,a2;
if(a.x==b.x && b.x==c.x)
{
return true;
}
if(a.y==b.y && b.y==c.y)
{
return true;
}
if(((a.x-b.x)*(b.y-c.y)-(b.x-c.x)*(a.y-b.y))==0)
{
return true;
}
return false;
}
void afisare(vector<punct> q)
{
int i;
for(i=0;i<q.size();i++)
{
cout<<q[i].x<<" "<<q[i].y<<" ";
}
}
bool linie()
{
punct extrem_1,extrem_2;
double y_min=inf,y_max=-inf,x_min=inf,x_max=-inf;
punct intern_1,intern_2;
int i,int_1,int_2,ext_1,ext_2;
vector<pair<int,int> > new_v;
if(coliniare(v[0],v[1],v[2])==true && coliniare(v[1],v[2],v[3])==true)
{
for(i=0;i<=3;i++)
{
new_v.push_back({v[i].x,v[i].y});
}
sort(new_v.begin(),new_v.end());
for(i=0;i<=3;i++)
{
v[i].x=new_v[i].first;
v[i].y=new_v[i].second;
}
// afisare(v);
extrem_1.x=v[0].x;
extrem_1.y=v[0].y;
extrem_2.x=v[3].x;
extrem_2.y=v[3].y;
intern_1.x=v[1].x;
intern_1.y=v[1].y;
intern_2.x=v[2].x;
intern_2.y=v[2].y;
I.push_back(extrem_1);
I.push_back(extrem_2);
J.push_back(intern_1);
J.push_back(intern_2);
return true;
}
else
{
return false;
}
}
int comparator(double dif1,double dif2)
{
if(abs(dif1-dif2)<0.001)
return 1;
else
return 0;
}
bool triunghi()
{
int i,max=0;
punct last_p,a,b,c;
if(arie(v[0],v[1],v[2])>max)
{
max=arie(v[0],v[1],v[2]);
last_p=v[3];
a=v[0];
b=v[1];
c=v[2];
}
if(arie(v[1],v[2],v[3])>max)
{
max=arie(v[1],v[2],v[3]);
last_p=v[0];
a=v[1];
b=v[2];
c=v[3];
}
if(arie(v[0],v[2],v[3])>max)
{
max=arie(v[0],v[2],v[3]);
last_p=v[1];
a=v[0];
b=v[2];
c=v[3];
}
if(arie(v[0],v[1],v[3])>max)
{
max=arie(v[0],v[1],v[3]);
last_p=v[2];
a=v[0];
b=v[1];
c=v[3];
}
if(comparator(arie(a,b,c),arie(a,b,last_p)+arie(a,c,last_p)+arie(b,c,last_p))==1)
{
I.push_back(a);
I.push_back(b);
I.push_back(c);
J.push_back(last_p);
return true;
}
else
{
return false;
}
}
double side(punct a,punct b,punct c)
{
return ((b.x-a.x)*(c.y-a.y)-(b.y-a.y)*(c.x-a.x));
}
void patrulater()
{
punct a,b;
a.x=v[0].x;
a.y=v[0].y;
b.x=v[1].x;
b.y=v[1].y;
if((side(a,b,v[2])<0 && side(a,b,v[3])>0) || (side(a,b,v[2])>0 && side(a,b,v[3])<0))
{
I.push_back(a);
I.push_back(b);
J.push_back(v[2]);
J.push_back(v[3]);
return;
}
a.x=v[0].x;
a.y=v[0].y;
b.x=v[2].x;
b.y=v[2].y;
if((side(a,b,v[1])<0 && side(a,b,v[3])>0) || (side(a,b,v[1])>0 && side(a,b,v[3])<0))
{
I.push_back(a);
I.push_back(b);
J.push_back(v[1]);
J.push_back(v[3]);
return;
}
a.x=v[0].x;
a.y=v[0].y;
b.x=v[3].x;
b.y=v[3].y;
if((side(a,b,v[2])<0 && side(a,b,v[1])>0) || (side(a,b,v[2])>0 && side(a,b,v[1])<0))
{
I.push_back(a);
I.push_back(b);
J.push_back(v[1]);
J.push_back(v[2]);
return;
}
a.x=v[1].x;
a.y=v[1].y;
b.x=v[2].x;
b.y=v[2].y;
if((side(a,b,v[0])<0 && side(a,b,v[3])>0) || (side(a,b,v[0])>0 && side(a,b,v[3])<0))
{
I.push_back(a);
I.push_back(b);
J.push_back(v[0]);
J.push_back(v[3]);
return;
}
a.x=v[1].x;
a.y=v[1].y;
b.x=v[3].x;
b.y=v[3].y;
if((side(a,b,v[0])<0 && side(a,b,v[2])>0) || (side(a,b,v[0])>0 && side(a,b,v[2])<0))
{
I.push_back(a);
I.push_back(b);
J.push_back(v[0]);
J.push_back(v[2]);
return;
}
a.x=v[2].x;
a.y=v[2].y;
b.x=v[3].x;
b.y=v[3].y;
if((side(a,b,v[0])<0 && side(a,b,v[1])>0) || (side(a,b,v[0])>0 && side(a,b,v[1])<0))
{
I.push_back(a);
I.push_back(b);
J.push_back(v[0]);
J.push_back(v[1]);
return;
}
}
int main()
{
ifstream fin("in.txt");
punct t;
for(int i=1;i<=4;i++)
{fin>>t.x>>t.y;
v.push_back(t);}
if(linie()==true)
{
cout<<"Punctele sunt coliniare pe o linie\n";
cout<<"I = ";
afisare(I);
cout<<"\n";
cout<<"J = ";
afisare(J);
cout<<"\n";
}
else if(triunghi()==true)
{
cout<<"Punctele sunt intr-un triunghi\n";
cout<<"I = ";
afisare(I);
cout<<"\n";
cout<<"J = ";
afisare(J);
cout<<"\n";
}
else
{
patrulater();
cout<<"Punctele sunt intr-un patrulater\n";
cout<<"I = ";
afisare(I);
cout<<"\n";
cout<<"J = ";
afisare(J);
cout<<"\n";
}
fin.close();
return 0;
}