4个点
(a1,b1) (a2,b2)组成一条线
(c1,d1) (c2,d2)组成一条线
x= (
(a2-a1)(c2-c1)(d2-b2)
+(b2-b1)*(c2-c1)*a2
-(d2-d1)*(a2-a1)*c2
)
/
(
(b2-b1)*(c2-c1)
-(d2-d1)*(a2-a1)
);
y= (b2-b1)/(a2-a1)*(x-a2)+b2;
#include<cstdio>
#include<cmath>
using namespace std;
int n;
struct left{
double x,y;
}l[100];
struct right{
double x,y;
}r[100];
struct up{
double x,y;
}u[100];
struct down{
double x,y;
}d[100];
struct coor{
double x,y;
}co[100];
void init()
{
for(int i=1;i<=n;i++)
{
scanf("%lf",&d[i].x);
d[i].y = 0.0;
}
d[0].x = 0.0;
d[0].y = 0.0;
d[n+1].x = 1.0;
d[n+1].y = 0.0;
for(int i=1;i<=n;i++)
{
scanf("%lf",&u[i].x);
u[i].y = 1.0;
}
u[0].x = 0.0;
u[0].y = 1.0;
u[n+1].x = 1.0;
u[n+1].y = 1.0;
for(int i=1;i<=n;i++)
{
scanf("%lf",&l[i].y);
l[i].x = 0.0;
}
l[0].y = 0.0;
l[0].x = 0.0;
l[n+1].y = 1.0;
l[n+1].x = 0.0;
for(int i=1;i<=n;i++)
{
scanf("%lf",&r[i].y);
r[i].x = 1.0;
}
r[0].y = 0.0;
r[0].x = 1.0;
r[n+1].y = 1.0;
r[n+1].x = 1.0;
}
void toCalCoor(int sym,int a,int b)
{
co[sym].x = ((r[a].x-l[a].x)*(u[b].x-d[b].x)*(u[b].y-r[a].y)
+(r[a].y-l[a].y)*(u[b].x-d[b].x)*r[a].x
-(u[b].y-d[b].y)*(r[a].x-l[a].x)*u[b].x )
/
((r[a].y-l[a].y)*(u[b].x-d[b].x)
-(u[b].y-d[b].y)*(r[a].x-l[a].x));
co[sym].y = (r[a].y-l[a].y)/(r[a].x-l[a].x)*(co[sym].x-r[a].x)+r[a].y;
//计算相交点的坐标
}
double toCalArea(int i,int j)
{
double area = 0.0;
toCalCoor(0,i,j);
toCalCoor(1,i+1,j);
toCalCoor(2,i+1,j+1);
toCalCoor(3,i,j+1);
for(int k=0;k<4;k++)
area+=co[k].x*co[(k+1)%4].y-co[k].y*co[(k+1)%4].x;
return fabs(area*0.5);
}
int main()
{
while(scanf("%d",&n)&&n)
{
double ans = -1.0;
init();
for(int i=0;i<=n;i++)
for(int j=0;j<=n;j++)
{
double s = toCalArea(i,j);
if(ans<s)ans = s;
}
printf("%f\n",ans);
}
return 0;
}