#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 det;
double a1,b1,c1,a2,b2,c2,X,Y;
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 apartine_abscisa(double X)
{
return (((v[0].x<=X && X<=v[1].x) || (v[0].x>=X && X>=v[1].x)) && ((v[2].x<=X && X<=v[3].x) || (v[2].x>=X && X>=v[3].x)));
}
bool apartine_ordonata(double X)
{
return (((v[0].y<=X && X<=v[1].y) || (v[0].y>=X && X>=v[1].y)) && ((v[2].y<=X && X<=v[3].y) || (v[2].y>=X && X>=v[3].y)));
}
bool apartine_segmentului(double X,double Y)
{
return (apartine_abscisa(X) && apartine_ordonata(Y));
}
bool comparator(double px,double py,double qx,double qy)
{
return (px==py && qx==qy);
}
int main()
{
ifstream fin("z.in");
punct t;
int i;
for(i=1;i<=4;i++)
{
fin>>t.x>>t.y;
v.push_back(t);
}
//Ecuatia A1A2
a1=v[0].y-v[1].y;
b1=v[1].x-v[0].x;
c1=v[0].x*v[1].y-v[1].x*v[0].y;
//Ecuatia A3A4
a2=v[2].y-v[3].y;
b2=v[3].x-v[2].x;
c2=v[2].x*v[3].y-v[3].x*v[2].y;
//Calculam det
det=a1*b2-a2*b1;
if(det!=0)
{
double detX,detY;
detX=(-c1)*b2+c2*b1;
detY=(-c2)*a1+a2*c1;
X=detX/det;
Y=detY/det;
if(apartine_segmentului(X,Y)==true)
{
cout<<"Intersectia este ["<<X<<", "<<Y<<"]\n";
}
else
{
cout<<"Intersectia este vida\n";
}
}
else if(det==0)
{
double rang12,rang13,rang23;
rang23=b1*c2-b2*c1;
rang13=a1*c2-a2*c1;
if(rang13!=0 || rang23!=0)//rangul lui M barat e 2
{
cout<<"Intersectia e vida\n";
}
else//rangul lui M barat e 1
{
cout<<"Punctele sunt coliniare\n";
vector<pair<double,double>> newie_v;
for(i=0;i<=3;i++)
{
newie_v.push_back({v[i].x,v[i].y});
}
sort(newie_v.begin(),newie_v.end());
vector<punct> new_v;
for(i=0;i<=3;i++)
{
punct p;
p.x=newie_v[i].first;
p.y=newie_v[i].second;
new_v.push_back(p);
}
if(((comparator(new_v[1].x,v[1].x,new_v[1].y,v[1].y)==true) && (comparator(new_v[2].x,v[2].x,new_v[2].y,v[2].y)==true)) || ((comparator(new_v[1].x,v[3].x,new_v[1].y,v[3].y)==true) && (comparator(new_v[2].x,v[0].x,new_v[2].y,v[0].y)==true)))
cout<<"Intersectia este vida totusi\n";
else
cout<<"Intersectia este segmentul: [("<<new_v[1].x<<", "<<new_v[1].y<<"),("<<new_v[2].x<<", "<<new_v[2].y<<")]\n";
}
}
fin.close();
return 0;
}