Skip to content

Instantly share code, notes, and snippets.

@LingDong-
Last active Mar 10, 2021
Embed
What would you like to do?
// Image Warping
// with
// Closed Form Solutions to Homographic and Bilinear Methods
// and
// Some Other Funny Methods
final char HOMOGRAPHIC = 0;
final char BILINEAR = 1;
final char BIANGULAR = 2;
final char BARYCENTRIC = 3;
int method = HOMOGRAPHIC; // try change me
//Utils -----------------------------------------------
float FLT_EPS = 0.01;
float DBL_EPS = 0.0001;
int sampler(PImage img, int x, int y){
x = min(max(x,0),img.width-1);
y = min(max(y,0),img.height-1);
return img.pixels[y*img.width+x];
}
int mix(int a, int b, float t){
return color(
red(a)*(1-t)+red(b)*t,
green(a)*(1-t)+green(b)*t,
blue(a)*(1-t)+blue(b)*t
);
}
int sampler(PImage img, float x, float y){
int x0 = (int)x;
int x1 = x0+1;
float xf = x - x0;
int y0 = (int)y;
int y1 = y0+1;
float yf = y - y0;
int a = sampler(img,x0,y0);
int b = sampler(img,x1,y0);
int c = sampler(img,x1,y1);
int d = sampler(img,x0,y1);
return mix(mix(a,b,xf),mix(d,c,xf),yf);
}
float disturb(float x){
float EPS = FLT_EPS;
return x + random(-EPS,EPS);
}
double disturb(double x){
double EPS = DBL_EPS;
return x + Math.random()*EPS*2-EPS;
}
int[] quadRoi(
float ax, float ay, float bx, float by, float cx, float cy, float dx, float dy
){
int xmin = (int)floor(min(min(ax,bx),min(cx,dx)));
int xmax = (int)ceil (max(max(ax,bx),max(cx,dx)));
int ymin = (int)floor(min(min(ay,by),min(cy,dy)));
int ymax = (int)ceil (max(max(ay,by),max(cy,dy)));
return new int[]{xmin,ymin,xmax,ymax};
}
//Quadcentric (Bilinear) method -----------------------------------------------
float[] cart2quad(
float x,float y,
float ax,float ay,
float bx,float by,
float cx,float cy,
float dx,float dy){
x = disturb( x); y = disturb( y);
ax = disturb(ax); ay = disturb(ay);
bx = disturb(bx); by = disturb(by);
cx = disturb(cx); cy = disturb(cy);
dx = disturb(dx); dy = disturb(dy);
float u = (ay*cx - ax*cy - 2*ay*dx + by*dx + 2*ax*dy - bx*dy + ay*x -
by*x + cy*x - dy*x - ax*y + bx*y - cx*y + dx*y + sqrt(pow(by*dx - bx*dy
- by*x + cy*x - dy*x + ay*(cx - 2*dx + x) + bx*y - cx*y + dx*y -
ax*(cy - 2*dy + y),2) + 4*(ay*(cx - dx) + by*(-cx + dx) - (ax -
bx)*(cy - dy))*(ay*(dx - x) + dy*x - dx*y + ax*(-dy +
y))))/(2*(ay*(cx - dx) + by*(-cx + dx) - (ax - bx)*(cy - dy)));
float v = (2*ay*bx - 2*ax*by - ay*cx + ax*cy + by*dx - bx*dy - ay*x + by*x -
cy*x + dy*x + ax*y - bx*y + cx*y - dx*y + sqrt(pow(by*dx - bx*dy - by*x
+ cy*x - dy*x + ay*(cx - 2*dx + x) + bx*y - cx*y + dx*y - ax*(cy -
2*dy + y),2) + 4*(ay*(cx - dx) + by*(-cx + dx) - (ax - bx)*(cy -
dy))*(ay*(dx - x) + dy*x - dx*y + ax*(-dy + y))))/(2*(ay*(bx - cx) +
ax*(-by + cy) + by*dx - cy*dx - bx*dy + cx*dy));
return new float[]{u,v};
}
float[] cart2quadParams(
float ax,float ay,
float bx,float by,
float cx,float cy,
float dx,float dy
){
float n = by*dx-bx*dy;
float k = 2* ((ay*(cx - dx) + by*(-cx + dx) - (ax - bx)*(cy - dy)));
float d = (2*(ay*(bx - cx) + ax*(-by + cy) + by*dx - cy*dx - bx*dy + cx*dy));
float s = ax-bx+cx-dx;
float r = ay-by+cy-dy;
if (k == 0 || d == 0){
float EPS = FLT_EPS;
if (k == 0){
cx -= EPS;
ax -= EPS;
cy -= EPS;
}else{
bx -= EPS;
by -= EPS;
}
return cart2quadParams(ax,ay,bx,by,cx,cy,dx,dy);
}
return new float[]{ax,ay,bx,by,cx,cy,dx,dy,n,k,d,s,r};
}
float[] cart2quadFromParams(
float x,float y,float[]P){
float ax = P[0], ay = P[1], bx = P[2], by = P[3], cx = P[4], cy = P[5];
float dx = P[6], dy = P[7], n = P[8], k = P[9], d = P[10], s = P[11], r = P[12];
r *= x;
s *= y;
float f = n + r + ay*(cx - 2*dx) - s - ax*(cy - 2*dy);
float t = sqrt(f*f + 2*k*(ay*(dx - x) + dy*x - dx*y + ax*(-dy + y)));
float m = r - s;
float q = n + t;
float u = (ay*cx - ax*cy - 2*ay*dx + 2*ax*dy + q + m)/k;
float v = (2*ay*bx - 2*ax*by - ay*cx + ax*cy + q - m)/d;
return new float[]{u,v};
}
float[] quad2cart(
float u,float v,
float ax,float ay,
float bx,float by,
float cx,float cy,
float dx,float dy){
float x = (ax*(1-u)+bx*u)*(1-v)+(dx*(1-u)+cx*u)*v;
float y = (ay*(1-v)+dy*v)*(1-u)+(by*(1-v)+cy*v)*u;
return new float[]{x,y};
}
void warpQuadcentric(PImage src, PImage dst,
float ax0, float ay0, float bx0, float by0, float cx0, float cy0, float dx0, float dy0,
float ax1, float ay1, float bx1, float by1, float cx1, float cy1, float dx1, float dy1
){
src.loadPixels();
dst.loadPixels();
int[] roi = quadRoi(ax1,ay1,bx1,by1,cx1,cy1,dx1,dy1);
float[] P = cart2quadParams(ax1,ay1,bx1,by1,cx1,cy1,dx1,dy1);
for (int i = roi[1]; i <= roi[3]; i++){
if (i < 0 || i > dst.height) continue;
for (int j = roi[0]; j <= roi[2]; j++){
if (j < 0 || j > dst.width) continue;
//float[] uv = cart2quad(j,i,ax1,ay1,bx1,by1,cx1,cy1,dx1,dy1);
float[] uv = cart2quadFromParams(j,i,P);
if (Float.isNaN(uv[0]) || Float.isNaN(uv[1]) || uv[0] < 0 || uv[0] > 1 || uv[1] < 0 || uv[1] > 1) continue;
float[] xy = quad2cart(uv[0],uv[1],ax0,ay0,bx0,by0,cx0,cy0,dx0,dy0);
int val = sampler(src,xy[0],xy[1]);
dst.pixels[i*dst.width+j] = val;
}
}
dst.updatePixels();
}
//Barycentric method -----------------------------------------------
//(Not suitable solution, illustrative purpose only)
float[] cart2bary(float x,float y,float ax,float ay,float bx,float by,float cx,float cy){
float ax_cx = ax-cx;
float ay_cy = ay-cy;
float x_cx = x-cx;
float y_cy = y-cy;
float bx_cx = bx-cx;
float by_cy = by-cy;
float d = ((by_cy)*ax_cx-(bx_cx)*ay_cy);
float u = 0;
float v = 0;
if (d != 0){
u = ((x_cx)*by_cy-(y_cy)*bx_cx)/d;
v = ((y_cy)*ax_cx-(x_cx)*ay_cy)/d;
}
return new float[]{u,v};
}
float[] bary2cart(float u,float v,float ax,float ay,float bx,float by,float cx,float cy){
float t = 1 - u - v;
float x = ax * u + bx * v + cx * t;
float y = ay * u + by * v + cy * t;
return new float[]{x,y};
}
void warpBarycentric(PImage src, PImage dst,
float ax0, float ay0, float bx0, float by0, float cx0, float cy0, float dx0, float dy0,
float ax1, float ay1, float bx1, float by1, float cx1, float cy1, float dx1, float dy1
){
src.loadPixels();
dst.loadPixels();
int[] roi = quadRoi(ax1,ay1,bx1,by1,cx1,cy1,dx1,dy1);
for (int i = roi[1]; i <= roi[3]; i++){
if (i < 0 || i > dst.height) continue;
for (int j = roi[0]; j <= roi[2]; j++){
if (j < 0 || j > dst.width) continue;
boolean up = true;
float[] uv = cart2bary(j,i,ax1,ay1,bx1,by1,cx1,cy1);
if (uv[0] < 0 || uv[1] < 0 || (1-uv[0]-uv[1]) < 0){
uv = cart2bary(j,i,ax1,ay1,dx1,dy1,cx1,cy1);
up = false;
}
if (uv[0] < 0 || uv[1] < 0 || (1-uv[0]-uv[1]) < 0){
continue;
}
float[] xy;
if (up){
xy = bary2cart(uv[0],uv[1],ax0,ay0,bx0,by0,cx0,cy0);
}else{
xy = bary2cart(uv[0],uv[1],ax0,ay0,dx0,dy0,cx0,cy0);
}
int val = sampler(src,xy[0],xy[1]);
dst.pixels[i*dst.width+j] = val;
}
}
dst.updatePixels();
}
//Homography method -----------------------------------------------
float[] computeHMatrix(
double x1,double y1,double x2,double y2,double x3,double y3,double x4,double y4,
double u1,double v1,double u2,double v2,double u3,double v3,double u4,double v4
){
x1 = disturb(x1); y1 = disturb(y1);
x2 = disturb(x2); y2 = disturb(y2);
x3 = disturb(x3); y3 = disturb(y3);
x4 = disturb(x4); y4 = disturb(y4);
u1 = disturb(u1); v1 = disturb(v1);
u2 = disturb(u2); v2 = disturb(v2);
u3 = disturb(u3); v3 = disturb(v3);
u4 = disturb(u4); v4 = disturb(v4);
double a = -((-(v1*(v1 - v2)*(u3*v1 - u1*v3)*(u3*(v1 - v2) + u1*(v2 - v3)
+ u2*(-v1 + v3))*(x1*x1)*x3*(-(u3*v1*v2*x1*x3) + u3*v1*v4*x1*x3 +
u3*v1*v2*x2*x3 - u3*v2*v4*x2*x3 + u4*v1*v2*x1*x4 - u4*v1*v3*x1*x4 -
u4*v1*v2*x2*x4 + u4*v2*v3*x2*x4 + u4*v1*v3*x3*x4 - u4*v2*v3*x3*x4 -
u3*v1*v4*x3*x4 + u3*v2*v4*x3*x4 + u2*x2*(v1*v3*(x1 - x3) + v3*v4*(x3
- x4) + v1*v4*(-x1 + x4)) + u1*x1*(v2*v3*(-x2 + x3) + v2*v4*(x2 - x4)
+ v3*v4*(-x3 + x4)))*(u2*v3*x2*x3*y1 - u2*v4*x2*x3*y1 -
u1*v3*x1*x3*y2 + u1*v4*x1*x3*y2 - u2*v1*x1*x2*y3 + u1*v2*x1*x2*y3 -
u1*v4*x1*x2*y3 + u2*v4*x1*x2*y3 + u2*v1*x1*x2*y4 - u1*v2*x1*x2*y4 +
u1*v4*x1*x2*y4 - u2*v4*x1*x2*y4 + u1*v3*x1*x3*y4 - u1*v4*x1*x3*y4 -
u2*v3*x2*x3*y4 + u2*v4*x2*x3*y4 + u3*x3*(v1*x1*(y2 - y4) + v2*x2*(-y1
+ y4) + v4*(x2*y1 - x1*y2 + x1*y4 - x2*y4)) + u4*(v3*x3*(-(x2*y1) +
x1*y2 - x1*y4 + x2*y4) + v1*x1*(-(x3*y2) + x2*y3 - x2*y4 + x3*y4) +
v2*x2*(x3*(y1 - y4) + x1*(-y3 + y4))))) - (u1*v2*x1*x2*x3 -
u1*v3*x1*x2*x3 - u4*v1*x1*x2*x4 - u1*v2*x1*x2*x4 + u4*v2*x1*x2*x4 +
u1*v4*x1*x2*x4 + u4*v1*x1*x3*x4 + u1*v3*x1*x3*x4 - u4*v3*x1*x3*x4 -
u1*v4*x1*x3*x4 - u4*v2*x2*x3*x4 + u4*v3*x2*x3*x4 + u3*x3*(v1*x1*(x2 -
x4) + v4*(x1 - x2)*x4 + v2*x2*(-x1 + x4)) + u2*x2*(v3*x3*(x1 - x4) +
v4*(-x1 + x3)*x4 + v1*x1*(-x3 + x4)))*(v1*x1*(-(u1*v2*x1*x2) -
u3*v1*x1*x3 + u1*v3*x1*x3 + u3*v2*x2*x3 + u2*x2*(v1*x1 -
v3*x3))*(-(v3*(-x1 + x3)*(v1*(u4*(-v1 + v2) + u2*(v1 - v4) + u1*(-v2
+ v4))*(u1*(-v2 + v3)*y1 + u2*(v1 - v3)*y2 + u3*(-v1 + v2)*y3) -
u1*(u4*(v1 - v2) + u1*(v2 - v4) + u2*(-v1 + v4))*(v1*v2*(y1 - y2) +
v2*v3*(y2 - y3) + v1*v3*(-y1 + y3)) - v1*(u3*(-v1 + v2) + u2*(v1 -
v3) + u1*(-v2 + v3))*(u1*(-v2 + v4)*y1 + u2*(v1 - v4)*y2 + u4*(-v1 +
v2)*y4) + u1*(u3*(v1 - v2) + u1*(v2 - v3) + u2*(-v1 + v3))*(v1*v2*(y1
- y2) + v2*v4*(y2 - y4) + v1*v4*(-y1 + y4)))) + (u3*v1 -
u1*v3)*x3*((u4*(v1 - v2) + u1*(v2 - v4) + u2*(-v1 + v4))*(v1*v2*(y1 -
y2) + v2*v3*(y2 - y3) + v1*v3*(-y1 + y3)) + (u3*(-v1 + v2) + u2*(v1 -
v3) + u1*(-v2 + v3))*(v1*v2*(y1 - y2) + v2*v4*(y2 - y4) + v1*v4*(-y1
+ y4)))) - (u2*v1*v3*x2*(x1 - x3) + u3*v1*v2*(-x1 + x2)*x3 +
u1*v2*v3*x1*(-x2 + x3))*(-(x1*(-(v1*x1) + v3*x3)*(v1*(u4*(-v1 + v2) +
u2*(v1 - v4) + u1*(-v2 + v4))*(u1*(-v2 + v3)*y1 + u2*(v1 - v3)*y2 +
u3*(-v1 + v2)*y3) - u1*(u4*(v1 - v2) + u1*(v2 - v4) + u2*(-v1 +
v4))*(v1*v2*(y1 - y2) + v2*v3*(y2 - y3) + v1*v3*(-y1 + y3)) -
v1*(u3*(-v1 + v2) + u2*(v1 - v3) + u1*(-v2 + v3))*(u1*(-v2 + v4)*y1 +
u2*(v1 - v4)*y2 + u4*(-v1 + v2)*y4) + u1*(u3*(v1 - v2) + u1*(v2 - v3)
+ u2*(-v1 + v3))*(v1*v2*(y1 - y2) + v2*v4*(y2 - y4) + v1*v4*(-y1 +
y4)))) + (u3*v1 - u1*v3)*x1*x3*((u4*(v1 - v2) + u1*(v2 - v4) +
u2*(-v1 + v4))*(v1*v2*(y1 - y2) + v2*v3*(y2 - y3) + v1*v3*(-y1 + y3))
+ (u3*(-v1 + v2) + u2*(v1 - v3) + u1*(-v2 + v3))*(v1*v2*(y1 - y2) +
v2*v4*(y2 - y4) + v1*v4*(-y1 + y4))))))/(-((u1*u4*(v2*x2 - v3*x3)*(x1
- x4) + u3*u4*(v1*x1 - v2*x2)*(x3 - x4) - u1*u3*(x1 - x3)*(v2*x2 -
v4*x4) + u2*(-(u4*(v1*x1 - v3*x3)*(x2 - x4)) + u3*(x2 - x3)*(v1*x1 -
v4*x4) + u1*(x1 - x2)*(v3*x3 - v4*x4)))*(v1*x1*(-(u1*v2*x1*x2) -
u3*v1*x1*x3 + u1*v3*x1*x3 + u3*v2*x2*x3 + u2*x2*(v1*x1 -
v3*x3))*(-(v3*(-x1 + x3)*(v1*(u4*(-v1 + v2) + u2*(v1 - v4) + u1*(-v2
+ v4))*(u1*(-v2 + v3)*y1 + u2*(v1 - v3)*y2 + u3*(-v1 + v2)*y3) -
u1*(u4*(v1 - v2) + u1*(v2 - v4) + u2*(-v1 + v4))*(v1*v2*(y1 - y2) +
v2*v3*(y2 - y3) + v1*v3*(-y1 + y3)) - v1*(u3*(-v1 + v2) + u2*(v1 -
v3) + u1*(-v2 + v3))*(u1*(-v2 + v4)*y1 + u2*(v1 - v4)*y2 + u4*(-v1 +
v2)*y4) + u1*(u3*(v1 - v2) + u1*(v2 - v3) + u2*(-v1 + v3))*(v1*v2*(y1
- y2) + v2*v4*(y2 - y4) + v1*v4*(-y1 + y4)))) + (u3*v1 -
u1*v3)*x3*((u4*(v1 - v2) + u1*(v2 - v4) + u2*(-v1 + v4))*(v1*v2*(y1 -
y2) + v2*v3*(y2 - y3) + v1*v3*(-y1 + y3)) + (u3*(-v1 + v2) + u2*(v1 -
v3) + u1*(-v2 + v3))*(v1*v2*(y1 - y2) + v2*v4*(y2 - y4) + v1*v4*(-y1
+ y4)))) - (u2*v1*v3*x2*(x1 - x3) + u3*v1*v2*(-x1 + x2)*x3 +
u1*v2*v3*x1*(-x2 + x3))*(-(x1*(-(v1*x1) + v3*x3)*(v1*(u4*(-v1 + v2) +
u2*(v1 - v4) + u1*(-v2 + v4))*(u1*(-v2 + v3)*y1 + u2*(v1 - v3)*y2 +
u3*(-v1 + v2)*y3) - u1*(u4*(v1 - v2) + u1*(v2 - v4) + u2*(-v1 +
v4))*(v1*v2*(y1 - y2) + v2*v3*(y2 - y3) + v1*v3*(-y1 + y3)) -
v1*(u3*(-v1 + v2) + u2*(v1 - v3) + u1*(-v2 + v3))*(u1*(-v2 + v4)*y1 +
u2*(v1 - v4)*y2 + u4*(-v1 + v2)*y4) + u1*(u3*(v1 - v2) + u1*(v2 - v3)
+ u2*(-v1 + v3))*(v1*v2*(y1 - y2) + v2*v4*(y2 - y4) + v1*v4*(-y1 +
y4)))) + (u3*v1 - u1*v3)*x1*x3*((u4*(v1 - v2) + u1*(v2 - v4) +
u2*(-v1 + v4))*(v1*v2*(y1 - y2) + v2*v3*(y2 - y3) + v1*v3*(-y1 + y3))
+ (u3*(-v1 + v2) + u2*(v1 - v3) + u1*(-v2 + v3))*(v1*v2*(y1 - y2) +
v2*v4*(y2 - y4) + v1*v4*(-y1 + y4)))))) + (-(u3*v1*v2*x1*x3) +
u3*v1*v4*x1*x3 + u3*v1*v2*x2*x3 - u3*v2*v4*x2*x3 + u4*v1*v2*x1*x4 -
u4*v1*v3*x1*x4 - u4*v1*v2*x2*x4 + u4*v2*v3*x2*x4 + u4*v1*v3*x3*x4 -
u4*v2*v3*x3*x4 - u3*v1*v4*x3*x4 + u3*v2*v4*x3*x4 + u2*x2*(v1*v3*(x1 -
x3) + v3*v4*(x3 - x4) + v1*v4*(-x1 + x4)) + u1*x1*(v2*v3*(-x2 + x3) +
v2*v4*(x2 - x4) + v3*v4*(-x3 + x4)))*(-((u2*u3*v1*x1*(x2 - x3) +
u1*u2*v3*(x1 - x2)*x3 + u1*u3*v2*x2*(-x1 + x3))*(-(x1*(-(v1*x1) +
v3*x3)*(v1*(u4*(-v1 + v2) + u2*(v1 - v4) + u1*(-v2 + v4))*(u1*(-v2 +
v3)*y1 + u2*(v1 - v3)*y2 + u3*(-v1 + v2)*y3) - u1*(u4*(v1 - v2) +
u1*(v2 - v4) + u2*(-v1 + v4))*(v1*v2*(y1 - y2) + v2*v3*(y2 - y3) +
v1*v3*(-y1 + y3)) - v1*(u3*(-v1 + v2) + u2*(v1 - v3) + u1*(-v2 +
v3))*(u1*(-v2 + v4)*y1 + u2*(v1 - v4)*y2 + u4*(-v1 + v2)*y4) +
u1*(u3*(v1 - v2) + u1*(v2 - v3) + u2*(-v1 + v3))*(v1*v2*(y1 - y2) +
v2*v4*(y2 - y4) + v1*v4*(-y1 + y4)))) + (u3*v1 -
u1*v3)*x1*x3*((u4*(v1 - v2) + u1*(v2 - v4) + u2*(-v1 +
v4))*(v1*v2*(y1 - y2) + v2*v3*(y2 - y3) + v1*v3*(-y1 + y3)) +
(u3*(-v1 + v2) + u2*(v1 - v3) + u1*(-v2 + v3))*(v1*v2*(y1 - y2) +
v2*v4*(y2 - y4) + v1*v4*(-y1 + y4))))) + (-(u1*v2*x1*x2) -
u3*v1*x1*x3 + u1*v3*x1*x3 + u3*v2*x2*x3 + u2*x2*(v1*x1 -
v3*x3))*(-(x1*(-(u3*v1*x1) + u1*v3*x3)*(v1*(u4*(-v1 + v2) + u2*(v1 -
v4) + u1*(-v2 + v4))*(u1*(-v2 + v3)*y1 + u2*(v1 - v3)*y2 + u3*(-v1 +
v2)*y3) - u1*(u4*(v1 - v2) + u1*(v2 - v4) + u2*(-v1 + v4))*(v1*v2*(y1
- y2) + v2*v3*(y2 - y3) + v1*v3*(-y1 + y3)) - v1*(u3*(-v1 + v2) +
u2*(v1 - v3) + u1*(-v2 + v3))*(u1*(-v2 + v4)*y1 + u2*(v1 - v4)*y2 +
u4*(-v1 + v2)*y4) + u1*(u3*(v1 - v2) + u1*(v2 - v3) + u2*(-v1 +
v3))*(v1*v2*(y1 - y2) + v2*v4*(y2 - y4) + v1*v4*(-y1 + y4)))) +
u1*(u3*v1 - u1*v3)*x1*x3*((u4*(v1 - v2) + u1*(v2 - v4) + u2*(-v1 +
v4))*(v1*v2*(y1 - y2) + v2*v3*(y2 - y3) + v1*v3*(-y1 + y3)) +
(u3*(-v1 + v2) + u2*(v1 - v3) + u1*(-v2 + v3))*(v1*v2*(y1 - y2) +
v2*v4*(y2 - y4) + v1*v4*(-y1 + y4)))))));
double b = (u1*v2*x1*x2*x3 -
u1*v3*x1*x2*x3 - u4*v1*x1*x2*x4 - u1*v2*x1*x2*x4 + u4*v2*x1*x2*x4 +
u1*v4*x1*x2*x4 + u4*v1*x1*x3*x4 + u1*v3*x1*x3*x4 - u4*v3*x1*x3*x4 -
u1*v4*x1*x3*x4 - u4*v2*x2*x3*x4 + u4*v3*x2*x3*x4 + u3*x3*(v1*x1*(x2 -
x4) + v4*(x1 - x2)*x4 + v2*x2*(-x1 + x4)) + u2*x2*(v3*x3*(x1 - x4) +
v4*(-x1 + x3)*x4 + v1*x1*(-x3 + x4)))/(u3*v1*v2*x1*x3 -
u3*v1*v4*x1*x3 - u3*v1*v2*x2*x3 + u3*v2*v4*x2*x3 - u4*v1*v2*x1*x4 +
u4*v1*v3*x1*x4 + u4*v1*v2*x2*x4 - u4*v2*v3*x2*x4 - u4*v1*v3*x3*x4 +
u4*v2*v3*x3*x4 + u3*v1*v4*x3*x4 - u3*v2*v4*x3*x4 + u1*x1*(v2*v3*(x2 -
x3) + v3*v4*(x3 - x4) + v2*v4*(-x2 + x4)) + u2*x2*(v1*v3*(-x1 + x3) +
v1*v4*(x1 - x4) + v3*v4*(-x3 + x4))) + ((u1*u4*(v2*x2 - v3*x3)*(x1 -
x4) + u3*u4*(v1*x1 - v2*x2)*(x3 - x4) - u1*u3*(x1 - x3)*(v2*x2 -
v4*x4) + u2*(-(u4*(v1*x1 - v3*x3)*(x2 - x4)) + u3*(x2 - x3)*(v1*x1 -
v4*x4) + u1*(x1 - x2)*(v3*x3 - v4*x4)))*(-(v1*(v1 - v2)*(u3*v1 -
u1*v3)*(u3*(v1 - v2) + u1*(v2 - v3) + u2*(-v1 +
v3))*(x1*x1)*x3*(-(u3*v1*v2*x1*x3) + u3*v1*v4*x1*x3 + u3*v1*v2*x2*x3 -
u3*v2*v4*x2*x3 + u4*v1*v2*x1*x4 - u4*v1*v3*x1*x4 - u4*v1*v2*x2*x4 +
u4*v2*v3*x2*x4 + u4*v1*v3*x3*x4 - u4*v2*v3*x3*x4 - u3*v1*v4*x3*x4 +
u3*v2*v4*x3*x4 + u2*x2*(v1*v3*(x1 - x3) + v3*v4*(x3 - x4) +
v1*v4*(-x1 + x4)) + u1*x1*(v2*v3*(-x2 + x3) + v2*v4*(x2 - x4) +
v3*v4*(-x3 + x4)))*(u2*v3*x2*x3*y1 - u2*v4*x2*x3*y1 - u1*v3*x1*x3*y2
+ u1*v4*x1*x3*y2 - u2*v1*x1*x2*y3 + u1*v2*x1*x2*y3 - u1*v4*x1*x2*y3 +
u2*v4*x1*x2*y3 + u2*v1*x1*x2*y4 - u1*v2*x1*x2*y4 + u1*v4*x1*x2*y4 -
u2*v4*x1*x2*y4 + u1*v3*x1*x3*y4 - u1*v4*x1*x3*y4 - u2*v3*x2*x3*y4 +
u2*v4*x2*x3*y4 + u3*x3*(v1*x1*(y2 - y4) + v2*x2*(-y1 + y4) +
v4*(x2*y1 - x1*y2 + x1*y4 - x2*y4)) + u4*(v3*x3*(-(x2*y1) + x1*y2 -
x1*y4 + x2*y4) + v1*x1*(-(x3*y2) + x2*y3 - x2*y4 + x3*y4) +
v2*x2*(x3*(y1 - y4) + x1*(-y3 + y4))))) - (u1*v2*x1*x2*x3 -
u1*v3*x1*x2*x3 - u4*v1*x1*x2*x4 - u1*v2*x1*x2*x4 + u4*v2*x1*x2*x4 +
u1*v4*x1*x2*x4 + u4*v1*x1*x3*x4 + u1*v3*x1*x3*x4 - u4*v3*x1*x3*x4 -
u1*v4*x1*x3*x4 - u4*v2*x2*x3*x4 + u4*v3*x2*x3*x4 + u3*x3*(v1*x1*(x2 -
x4) + v4*(x1 - x2)*x4 + v2*x2*(-x1 + x4)) + u2*x2*(v3*x3*(x1 - x4) +
v4*(-x1 + x3)*x4 + v1*x1*(-x3 + x4)))*(v1*x1*(-(u1*v2*x1*x2) -
u3*v1*x1*x3 + u1*v3*x1*x3 + u3*v2*x2*x3 + u2*x2*(v1*x1 -
v3*x3))*(-(v3*(-x1 + x3)*(v1*(u4*(-v1 + v2) + u2*(v1 - v4) + u1*(-v2
+ v4))*(u1*(-v2 + v3)*y1 + u2*(v1 - v3)*y2 + u3*(-v1 + v2)*y3) -
u1*(u4*(v1 - v2) + u1*(v2 - v4) + u2*(-v1 + v4))*(v1*v2*(y1 - y2) +
v2*v3*(y2 - y3) + v1*v3*(-y1 + y3)) - v1*(u3*(-v1 + v2) + u2*(v1 -
v3) + u1*(-v2 + v3))*(u1*(-v2 + v4)*y1 + u2*(v1 - v4)*y2 + u4*(-v1 +
v2)*y4) + u1*(u3*(v1 - v2) + u1*(v2 - v3) + u2*(-v1 + v3))*(v1*v2*(y1
- y2) + v2*v4*(y2 - y4) + v1*v4*(-y1 + y4)))) + (u3*v1 -
u1*v3)*x3*((u4*(v1 - v2) + u1*(v2 - v4) + u2*(-v1 + v4))*(v1*v2*(y1 -
y2) + v2*v3*(y2 - y3) + v1*v3*(-y1 + y3)) + (u3*(-v1 + v2) + u2*(v1 -
v3) + u1*(-v2 + v3))*(v1*v2*(y1 - y2) + v2*v4*(y2 - y4) + v1*v4*(-y1
+ y4)))) - (u2*v1*v3*x2*(x1 - x3) + u3*v1*v2*(-x1 + x2)*x3 +
u1*v2*v3*x1*(-x2 + x3))*(-(x1*(-(v1*x1) + v3*x3)*(v1*(u4*(-v1 + v2) +
u2*(v1 - v4) + u1*(-v2 + v4))*(u1*(-v2 + v3)*y1 + u2*(v1 - v3)*y2 +
u3*(-v1 + v2)*y3) - u1*(u4*(v1 - v2) + u1*(v2 - v4) + u2*(-v1 +
v4))*(v1*v2*(y1 - y2) + v2*v3*(y2 - y3) + v1*v3*(-y1 + y3)) -
v1*(u3*(-v1 + v2) + u2*(v1 - v3) + u1*(-v2 + v3))*(u1*(-v2 + v4)*y1 +
u2*(v1 - v4)*y2 + u4*(-v1 + v2)*y4) + u1*(u3*(v1 - v2) + u1*(v2 - v3)
+ u2*(-v1 + v3))*(v1*v2*(y1 - y2) + v2*v4*(y2 - y4) + v1*v4*(-y1 +
y4)))) + (u3*v1 - u1*v3)*x1*x3*((u4*(v1 - v2) + u1*(v2 - v4) +
u2*(-v1 + v4))*(v1*v2*(y1 - y2) + v2*v3*(y2 - y3) + v1*v3*(-y1 + y3))
+ (u3*(-v1 + v2) + u2*(v1 - v3) + u1*(-v2 + v3))*(v1*v2*(y1 - y2) +
v2*v4*(y2 - y4) + v1*v4*(-y1 + y4)))))))/((-(u3*v1*v2*x1*x3) +
u3*v1*v4*x1*x3 + u3*v1*v2*x2*x3 - u3*v2*v4*x2*x3 + u4*v1*v2*x1*x4 -
u4*v1*v3*x1*x4 - u4*v1*v2*x2*x4 + u4*v2*v3*x2*x4 + u4*v1*v3*x3*x4 -
u4*v2*v3*x3*x4 - u3*v1*v4*x3*x4 + u3*v2*v4*x3*x4 + u2*x2*(v1*v3*(x1 -
x3) + v3*v4*(x3 - x4) + v1*v4*(-x1 + x4)) + u1*x1*(v2*v3*(-x2 + x3) +
v2*v4*(x2 - x4) + v3*v4*(-x3 + x4)))*(-((u1*u4*(v2*x2 - v3*x3)*(x1 -
x4) + u3*u4*(v1*x1 - v2*x2)*(x3 - x4) - u1*u3*(x1 - x3)*(v2*x2 -
v4*x4) + u2*(-(u4*(v1*x1 - v3*x3)*(x2 - x4)) + u3*(x2 - x3)*(v1*x1 -
v4*x4) + u1*(x1 - x2)*(v3*x3 - v4*x4)))*(v1*x1*(-(u1*v2*x1*x2) -
u3*v1*x1*x3 + u1*v3*x1*x3 + u3*v2*x2*x3 + u2*x2*(v1*x1 -
v3*x3))*(-(v3*(-x1 + x3)*(v1*(u4*(-v1 + v2) + u2*(v1 - v4) + u1*(-v2
+ v4))*(u1*(-v2 + v3)*y1 + u2*(v1 - v3)*y2 + u3*(-v1 + v2)*y3) -
u1*(u4*(v1 - v2) + u1*(v2 - v4) + u2*(-v1 + v4))*(v1*v2*(y1 - y2) +
v2*v3*(y2 - y3) + v1*v3*(-y1 + y3)) - v1*(u3*(-v1 + v2) + u2*(v1 -
v3) + u1*(-v2 + v3))*(u1*(-v2 + v4)*y1 + u2*(v1 - v4)*y2 + u4*(-v1 +
v2)*y4) + u1*(u3*(v1 - v2) + u1*(v2 - v3) + u2*(-v1 + v3))*(v1*v2*(y1
- y2) + v2*v4*(y2 - y4) + v1*v4*(-y1 + y4)))) + (u3*v1 -
u1*v3)*x3*((u4*(v1 - v2) + u1*(v2 - v4) + u2*(-v1 + v4))*(v1*v2*(y1 -
y2) + v2*v3*(y2 - y3) + v1*v3*(-y1 + y3)) + (u3*(-v1 + v2) + u2*(v1 -
v3) + u1*(-v2 + v3))*(v1*v2*(y1 - y2) + v2*v4*(y2 - y4) + v1*v4*(-y1
+ y4)))) - (u2*v1*v3*x2*(x1 - x3) + u3*v1*v2*(-x1 + x2)*x3 +
u1*v2*v3*x1*(-x2 + x3))*(-(x1*(-(v1*x1) + v3*x3)*(v1*(u4*(-v1 + v2) +
u2*(v1 - v4) + u1*(-v2 + v4))*(u1*(-v2 + v3)*y1 + u2*(v1 - v3)*y2 +
u3*(-v1 + v2)*y3) - u1*(u4*(v1 - v2) + u1*(v2 - v4) + u2*(-v1 +
v4))*(v1*v2*(y1 - y2) + v2*v3*(y2 - y3) + v1*v3*(-y1 + y3)) -
v1*(u3*(-v1 + v2) + u2*(v1 - v3) + u1*(-v2 + v3))*(u1*(-v2 + v4)*y1 +
u2*(v1 - v4)*y2 + u4*(-v1 + v2)*y4) + u1*(u3*(v1 - v2) + u1*(v2 - v3)
+ u2*(-v1 + v3))*(v1*v2*(y1 - y2) + v2*v4*(y2 - y4) + v1*v4*(-y1 +
y4)))) + (u3*v1 - u1*v3)*x1*x3*((u4*(v1 - v2) + u1*(v2 - v4) +
u2*(-v1 + v4))*(v1*v2*(y1 - y2) + v2*v3*(y2 - y3) + v1*v3*(-y1 + y3))
+ (u3*(-v1 + v2) + u2*(v1 - v3) + u1*(-v2 + v3))*(v1*v2*(y1 - y2) +
v2*v4*(y2 - y4) + v1*v4*(-y1 + y4)))))) + (-(u3*v1*v2*x1*x3) +
u3*v1*v4*x1*x3 + u3*v1*v2*x2*x3 - u3*v2*v4*x2*x3 + u4*v1*v2*x1*x4 -
u4*v1*v3*x1*x4 - u4*v1*v2*x2*x4 + u4*v2*v3*x2*x4 + u4*v1*v3*x3*x4 -
u4*v2*v3*x3*x4 - u3*v1*v4*x3*x4 + u3*v2*v4*x3*x4 + u2*x2*(v1*v3*(x1 -
x3) + v3*v4*(x3 - x4) + v1*v4*(-x1 + x4)) + u1*x1*(v2*v3*(-x2 + x3) +
v2*v4*(x2 - x4) + v3*v4*(-x3 + x4)))*(-((u2*u3*v1*x1*(x2 - x3) +
u1*u2*v3*(x1 - x2)*x3 + u1*u3*v2*x2*(-x1 + x3))*(-(x1*(-(v1*x1) +
v3*x3)*(v1*(u4*(-v1 + v2) + u2*(v1 - v4) + u1*(-v2 + v4))*(u1*(-v2 +
v3)*y1 + u2*(v1 - v3)*y2 + u3*(-v1 + v2)*y3) - u1*(u4*(v1 - v2) +
u1*(v2 - v4) + u2*(-v1 + v4))*(v1*v2*(y1 - y2) + v2*v3*(y2 - y3) +
v1*v3*(-y1 + y3)) - v1*(u3*(-v1 + v2) + u2*(v1 - v3) + u1*(-v2 +
v3))*(u1*(-v2 + v4)*y1 + u2*(v1 - v4)*y2 + u4*(-v1 + v2)*y4) +
u1*(u3*(v1 - v2) + u1*(v2 - v3) + u2*(-v1 + v3))*(v1*v2*(y1 - y2) +
v2*v4*(y2 - y4) + v1*v4*(-y1 + y4)))) + (u3*v1 -
u1*v3)*x1*x3*((u4*(v1 - v2) + u1*(v2 - v4) + u2*(-v1 +
v4))*(v1*v2*(y1 - y2) + v2*v3*(y2 - y3) + v1*v3*(-y1 + y3)) +
(u3*(-v1 + v2) + u2*(v1 - v3) + u1*(-v2 + v3))*(v1*v2*(y1 - y2) +
v2*v4*(y2 - y4) + v1*v4*(-y1 + y4))))) + (-(u1*v2*x1*x2) -
u3*v1*x1*x3 + u1*v3*x1*x3 + u3*v2*x2*x3 + u2*x2*(v1*x1 -
v3*x3))*(-(x1*(-(u3*v1*x1) + u1*v3*x3)*(v1*(u4*(-v1 + v2) + u2*(v1 -
v4) + u1*(-v2 + v4))*(u1*(-v2 + v3)*y1 + u2*(v1 - v3)*y2 + u3*(-v1 +
v2)*y3) - u1*(u4*(v1 - v2) + u1*(v2 - v4) + u2*(-v1 + v4))*(v1*v2*(y1
- y2) + v2*v3*(y2 - y3) + v1*v3*(-y1 + y3)) - v1*(u3*(-v1 + v2) +
u2*(v1 - v3) + u1*(-v2 + v3))*(u1*(-v2 + v4)*y1 + u2*(v1 - v4)*y2 +
u4*(-v1 + v2)*y4) + u1*(u3*(v1 - v2) + u1*(v2 - v3) + u2*(-v1 +
v3))*(v1*v2*(y1 - y2) + v2*v4*(y2 - y4) + v1*v4*(-y1 + y4)))) +
u1*(u3*v1 - u1*v3)*x1*x3*((u4*(v1 - v2) + u1*(v2 - v4) + u2*(-v1 +
v4))*(v1*v2*(y1 - y2) + v2*v3*(y2 - y3) + v1*v3*(-y1 + y3)) +
(u3*(-v1 + v2) + u2*(v1 - v3) + u1*(-v2 + v3))*(v1*v2*(y1 - y2) +
v2*v4*(y2 - y4) + v1*v4*(-y1 + y4)))))));
double c = (-(u1*v2*v4*x1*x2*x3)
+ u1*v3*v4*x1*x2*x3 + u4*v1*v3*x1*x2*x4 + u1*v2*v3*x1*x2*x4 -
u4*v2*v3*x1*x2*x4 - u1*v3*v4*x1*x2*x4 - u4*v1*v2*x1*x3*x4 -
u1*v2*v3*x1*x3*x4 + u4*v2*v3*x1*x3*x4 + u1*v2*v4*x1*x3*x4 +
u4*v1*v2*x2*x3*x4 - u4*v1*v3*x2*x3*x4 + u3*x3*(v2*v4*x1*(x2 - x4) +
v1*v2*(x1 - x2)*x4 + v1*v4*x2*(-x1 + x4)) + u2*x2*(v1*v4*x3*(x1 - x4)
+ v1*v3*(-x1 + x3)*x4 + v3*v4*x1*(-x3 + x4)))/(u3*v1*v2*x1*x3 -
u3*v1*v4*x1*x3 - u3*v1*v2*x2*x3 + u3*v2*v4*x2*x3 - u4*v1*v2*x1*x4 +
u4*v1*v3*x1*x4 + u4*v1*v2*x2*x4 - u4*v2*v3*x2*x4 - u4*v1*v3*x3*x4 +
u4*v2*v3*x3*x4 + u3*v1*v4*x3*x4 - u3*v2*v4*x3*x4 + u1*x1*(v2*v3*(x2 -
x3) + v3*v4*(x3 - x4) + v2*v4*(-x2 + x4)) + u2*x2*(v1*v3*(-x1 + x3) +
v1*v4*(x1 - x4) + v3*v4*(-x3 + x4))) + ((v2*(-(u1*u4*v3*(x2 - x3)*(x1
- x4)) + u1*u3*v4*(x1 - x3)*(x2 - x4) - u3*u4*v1*(x1 - x2)*(x3 - x4))
+ u2*(-(u3*v1*v4*(x2 - x3)*(x1 - x4)) + u4*v1*v3*(x1 - x3)*(x2 - x4)
- u1*v3*v4*(x1 - x2)*(x3 - x4)))*(-(v1*(v1 - v2)*(u3*v1 -
u1*v3)*(u3*(v1 - v2) + u1*(v2 - v3) + u2*(-v1 +
v3))*(x1*x1)*x3*(-(u3*v1*v2*x1*x3) + u3*v1*v4*x1*x3 + u3*v1*v2*x2*x3 -
u3*v2*v4*x2*x3 + u4*v1*v2*x1*x4 - u4*v1*v3*x1*x4 - u4*v1*v2*x2*x4 +
u4*v2*v3*x2*x4 + u4*v1*v3*x3*x4 - u4*v2*v3*x3*x4 - u3*v1*v4*x3*x4 +
u3*v2*v4*x3*x4 + u2*x2*(v1*v3*(x1 - x3) + v3*v4*(x3 - x4) +
v1*v4*(-x1 + x4)) + u1*x1*(v2*v3*(-x2 + x3) + v2*v4*(x2 - x4) +
v3*v4*(-x3 + x4)))*(u2*v3*x2*x3*y1 - u2*v4*x2*x3*y1 - u1*v3*x1*x3*y2
+ u1*v4*x1*x3*y2 - u2*v1*x1*x2*y3 + u1*v2*x1*x2*y3 - u1*v4*x1*x2*y3 +
u2*v4*x1*x2*y3 + u2*v1*x1*x2*y4 - u1*v2*x1*x2*y4 + u1*v4*x1*x2*y4 -
u2*v4*x1*x2*y4 + u1*v3*x1*x3*y4 - u1*v4*x1*x3*y4 - u2*v3*x2*x3*y4 +
u2*v4*x2*x3*y4 + u3*x3*(v1*x1*(y2 - y4) + v2*x2*(-y1 + y4) +
v4*(x2*y1 - x1*y2 + x1*y4 - x2*y4)) + u4*(v3*x3*(-(x2*y1) + x1*y2 -
x1*y4 + x2*y4) + v1*x1*(-(x3*y2) + x2*y3 - x2*y4 + x3*y4) +
v2*x2*(x3*(y1 - y4) + x1*(-y3 + y4))))) - (u1*v2*x1*x2*x3 -
u1*v3*x1*x2*x3 - u4*v1*x1*x2*x4 - u1*v2*x1*x2*x4 + u4*v2*x1*x2*x4 +
u1*v4*x1*x2*x4 + u4*v1*x1*x3*x4 + u1*v3*x1*x3*x4 - u4*v3*x1*x3*x4 -
u1*v4*x1*x3*x4 - u4*v2*x2*x3*x4 + u4*v3*x2*x3*x4 + u3*x3*(v1*x1*(x2 -
x4) + v4*(x1 - x2)*x4 + v2*x2*(-x1 + x4)) + u2*x2*(v3*x3*(x1 - x4) +
v4*(-x1 + x3)*x4 + v1*x1*(-x3 + x4)))*(v1*x1*(-(u1*v2*x1*x2) -
u3*v1*x1*x3 + u1*v3*x1*x3 + u3*v2*x2*x3 + u2*x2*(v1*x1 -
v3*x3))*(-(v3*(-x1 + x3)*(v1*(u4*(-v1 + v2) + u2*(v1 - v4) + u1*(-v2
+ v4))*(u1*(-v2 + v3)*y1 + u2*(v1 - v3)*y2 + u3*(-v1 + v2)*y3) -
u1*(u4*(v1 - v2) + u1*(v2 - v4) + u2*(-v1 + v4))*(v1*v2*(y1 - y2) +
v2*v3*(y2 - y3) + v1*v3*(-y1 + y3)) - v1*(u3*(-v1 + v2) + u2*(v1 -
v3) + u1*(-v2 + v3))*(u1*(-v2 + v4)*y1 + u2*(v1 - v4)*y2 + u4*(-v1 +
v2)*y4) + u1*(u3*(v1 - v2) + u1*(v2 - v3) + u2*(-v1 + v3))*(v1*v2*(y1
- y2) + v2*v4*(y2 - y4) + v1*v4*(-y1 + y4)))) + (u3*v1 -
u1*v3)*x3*((u4*(v1 - v2) + u1*(v2 - v4) + u2*(-v1 + v4))*(v1*v2*(y1 -
y2) + v2*v3*(y2 - y3) + v1*v3*(-y1 + y3)) + (u3*(-v1 + v2) + u2*(v1 -
v3) + u1*(-v2 + v3))*(v1*v2*(y1 - y2) + v2*v4*(y2 - y4) + v1*v4*(-y1
+ y4)))) - (u2*v1*v3*x2*(x1 - x3) + u3*v1*v2*(-x1 + x2)*x3 +
u1*v2*v3*x1*(-x2 + x3))*(-(x1*(-(v1*x1) + v3*x3)*(v1*(u4*(-v1 + v2) +
u2*(v1 - v4) + u1*(-v2 + v4))*(u1*(-v2 + v3)*y1 + u2*(v1 - v3)*y2 +
u3*(-v1 + v2)*y3) - u1*(u4*(v1 - v2) + u1*(v2 - v4) + u2*(-v1 +
v4))*(v1*v2*(y1 - y2) + v2*v3*(y2 - y3) + v1*v3*(-y1 + y3)) -
v1*(u3*(-v1 + v2) + u2*(v1 - v3) + u1*(-v2 + v3))*(u1*(-v2 + v4)*y1 +
u2*(v1 - v4)*y2 + u4*(-v1 + v2)*y4) + u1*(u3*(v1 - v2) + u1*(v2 - v3)
+ u2*(-v1 + v3))*(v1*v2*(y1 - y2) + v2*v4*(y2 - y4) + v1*v4*(-y1 +
y4)))) + (u3*v1 - u1*v3)*x1*x3*((u4*(v1 - v2) + u1*(v2 - v4) +
u2*(-v1 + v4))*(v1*v2*(y1 - y2) + v2*v3*(y2 - y3) + v1*v3*(-y1 + y3))
+ (u3*(-v1 + v2) + u2*(v1 - v3) + u1*(-v2 + v3))*(v1*v2*(y1 - y2) +
v2*v4*(y2 - y4) + v1*v4*(-y1 + y4)))))))/((-(u3*v1*v2*x1*x3) +
u3*v1*v4*x1*x3 + u3*v1*v2*x2*x3 - u3*v2*v4*x2*x3 + u4*v1*v2*x1*x4 -
u4*v1*v3*x1*x4 - u4*v1*v2*x2*x4 + u4*v2*v3*x2*x4 + u4*v1*v3*x3*x4 -
u4*v2*v3*x3*x4 - u3*v1*v4*x3*x4 + u3*v2*v4*x3*x4 + u2*x2*(v1*v3*(x1 -
x3) + v3*v4*(x3 - x4) + v1*v4*(-x1 + x4)) + u1*x1*(v2*v3*(-x2 + x3) +
v2*v4*(x2 - x4) + v3*v4*(-x3 + x4)))*(-((u1*u4*(v2*x2 - v3*x3)*(x1 -
x4) + u3*u4*(v1*x1 - v2*x2)*(x3 - x4) - u1*u3*(x1 - x3)*(v2*x2 -
v4*x4) + u2*(-(u4*(v1*x1 - v3*x3)*(x2 - x4)) + u3*(x2 - x3)*(v1*x1 -
v4*x4) + u1*(x1 - x2)*(v3*x3 - v4*x4)))*(v1*x1*(-(u1*v2*x1*x2) -
u3*v1*x1*x3 + u1*v3*x1*x3 + u3*v2*x2*x3 + u2*x2*(v1*x1 -
v3*x3))*(-(v3*(-x1 + x3)*(v1*(u4*(-v1 + v2) + u2*(v1 - v4) + u1*(-v2
+ v4))*(u1*(-v2 + v3)*y1 + u2*(v1 - v3)*y2 + u3*(-v1 + v2)*y3) -
u1*(u4*(v1 - v2) + u1*(v2 - v4) + u2*(-v1 + v4))*(v1*v2*(y1 - y2) +
v2*v3*(y2 - y3) + v1*v3*(-y1 + y3)) - v1*(u3*(-v1 + v2) + u2*(v1 -
v3) + u1*(-v2 + v3))*(u1*(-v2 + v4)*y1 + u2*(v1 - v4)*y2 + u4*(-v1 +
v2)*y4) + u1*(u3*(v1 - v2) + u1*(v2 - v3) + u2*(-v1 + v3))*(v1*v2*(y1
- y2) + v2*v4*(y2 - y4) + v1*v4*(-y1 + y4)))) + (u3*v1 -
u1*v3)*x3*((u4*(v1 - v2) + u1*(v2 - v4) + u2*(-v1 + v4))*(v1*v2*(y1 -
y2) + v2*v3*(y2 - y3) + v1*v3*(-y1 + y3)) + (u3*(-v1 + v2) + u2*(v1 -
v3) + u1*(-v2 + v3))*(v1*v2*(y1 - y2) + v2*v4*(y2 - y4) + v1*v4*(-y1
+ y4)))) - (u2*v1*v3*x2*(x1 - x3) + u3*v1*v2*(-x1 + x2)*x3 +
u1*v2*v3*x1*(-x2 + x3))*(-(x1*(-(v1*x1) + v3*x3)*(v1*(u4*(-v1 + v2) +
u2*(v1 - v4) + u1*(-v2 + v4))*(u1*(-v2 + v3)*y1 + u2*(v1 - v3)*y2 +
u3*(-v1 + v2)*y3) - u1*(u4*(v1 - v2) + u1*(v2 - v4) + u2*(-v1 +
v4))*(v1*v2*(y1 - y2) + v2*v3*(y2 - y3) + v1*v3*(-y1 + y3)) -
v1*(u3*(-v1 + v2) + u2*(v1 - v3) + u1*(-v2 + v3))*(u1*(-v2 + v4)*y1 +
u2*(v1 - v4)*y2 + u4*(-v1 + v2)*y4) + u1*(u3*(v1 - v2) + u1*(v2 - v3)
+ u2*(-v1 + v3))*(v1*v2*(y1 - y2) + v2*v4*(y2 - y4) + v1*v4*(-y1 +
y4)))) + (u3*v1 - u1*v3)*x1*x3*((u4*(v1 - v2) + u1*(v2 - v4) +
u2*(-v1 + v4))*(v1*v2*(y1 - y2) + v2*v3*(y2 - y3) + v1*v3*(-y1 + y3))
+ (u3*(-v1 + v2) + u2*(v1 - v3) + u1*(-v2 + v3))*(v1*v2*(y1 - y2) +
v2*v4*(y2 - y4) + v1*v4*(-y1 + y4)))))) + (-(u3*v1*v2*x1*x3) +
u3*v1*v4*x1*x3 + u3*v1*v2*x2*x3 - u3*v2*v4*x2*x3 + u4*v1*v2*x1*x4 -
u4*v1*v3*x1*x4 - u4*v1*v2*x2*x4 + u4*v2*v3*x2*x4 + u4*v1*v3*x3*x4 -
u4*v2*v3*x3*x4 - u3*v1*v4*x3*x4 + u3*v2*v4*x3*x4 + u2*x2*(v1*v3*(x1 -
x3) + v3*v4*(x3 - x4) + v1*v4*(-x1 + x4)) + u1*x1*(v2*v3*(-x2 + x3) +
v2*v4*(x2 - x4) + v3*v4*(-x3 + x4)))*(-((u2*u3*v1*x1*(x2 - x3) +
u1*u2*v3*(x1 - x2)*x3 + u1*u3*v2*x2*(-x1 + x3))*(-(x1*(-(v1*x1) +
v3*x3)*(v1*(u4*(-v1 + v2) + u2*(v1 - v4) + u1*(-v2 + v4))*(u1*(-v2 +
v3)*y1 + u2*(v1 - v3)*y2 + u3*(-v1 + v2)*y3) - u1*(u4*(v1 - v2) +
u1*(v2 - v4) + u2*(-v1 + v4))*(v1*v2*(y1 - y2) + v2*v3*(y2 - y3) +
v1*v3*(-y1 + y3)) - v1*(u3*(-v1 + v2) + u2*(v1 - v3) + u1*(-v2 +
v3))*(u1*(-v2 + v4)*y1 + u2*(v1 - v4)*y2 + u4*(-v1 + v2)*y4) +
u1*(u3*(v1 - v2) + u1*(v2 - v3) + u2*(-v1 + v3))*(v1*v2*(y1 - y2) +
v2*v4*(y2 - y4) + v1*v4*(-y1 + y4)))) + (u3*v1 -
u1*v3)*x1*x3*((u4*(v1 - v2) + u1*(v2 - v4) + u2*(-v1 +
v4))*(v1*v2*(y1 - y2) + v2*v3*(y2 - y3) + v1*v3*(-y1 + y3)) +
(u3*(-v1 + v2) + u2*(v1 - v3) + u1*(-v2 + v3))*(v1*v2*(y1 - y2) +
v2*v4*(y2 - y4) + v1*v4*(-y1 + y4))))) + (-(u1*v2*x1*x2) -
u3*v1*x1*x3 + u1*v3*x1*x3 + u3*v2*x2*x3 + u2*x2*(v1*x1 -
v3*x3))*(-(x1*(-(u3*v1*x1) + u1*v3*x3)*(v1*(u4*(-v1 + v2) + u2*(v1 -
v4) + u1*(-v2 + v4))*(u1*(-v2 + v3)*y1 + u2*(v1 - v3)*y2 + u3*(-v1 +
v2)*y3) - u1*(u4*(v1 - v2) + u1*(v2 - v4) + u2*(-v1 + v4))*(v1*v2*(y1
- y2) + v2*v3*(y2 - y3) + v1*v3*(-y1 + y3)) - v1*(u3*(-v1 + v2) +
u2*(v1 - v3) + u1*(-v2 + v3))*(u1*(-v2 + v4)*y1 + u2*(v1 - v4)*y2 +
u4*(-v1 + v2)*y4) + u1*(u3*(v1 - v2) + u1*(v2 - v3) + u2*(-v1 +
v3))*(v1*v2*(y1 - y2) + v2*v4*(y2 - y4) + v1*v4*(-y1 + y4)))) +
u1*(u3*v1 - u1*v3)*x1*x3*((u4*(v1 - v2) + u1*(v2 - v4) + u2*(-v1 +
v4))*(v1*v2*(y1 - y2) + v2*v3*(y2 - y3) + v1*v3*(-y1 + y3)) +
(u3*(-v1 + v2) + u2*(v1 - v3) + u1*(-v2 + v3))*(v1*v2*(y1 - y2) +
v2*v4*(y2 - y4) + v1*v4*(-y1 + y4)))))));
double d = (-(v3*x2*x3*y1) -
v1*x1*x3*y2 + v3*x1*x3*y2 + v1*x1*x2*y3 + v2*x2*(x3*y1 -
x1*y3))/(-(u2*v1*x1*x2) + u1*v2*x1*x2 + u3*v1*x1*x3 - u1*v3*x1*x3 -
u3*v2*x2*x3 + u2*v3*x2*x3) + ((-(u1*v2*x1*x2*x3) + u1*v3*x1*x2*x3 +
u4*v1*x1*x2*x4 + u1*v2*x1*x2*x4 - u4*v2*x1*x2*x4 - u1*v4*x1*x2*x4 -
u4*v1*x1*x3*x4 - u1*v3*x1*x3*x4 + u4*v3*x1*x3*x4 + u1*v4*x1*x3*x4 +
u4*v2*x2*x3*x4 - u4*v3*x2*x3*x4 + u2*x2*(v1*x1*(x3 - x4) + v4*(x1 -
x3)*x4 + v3*x3*(-x1 + x4)) + u3*x3*(v2*x2*(x1 - x4) + v4*(-x1 +
x2)*x4 + v1*x1*(-x2 + x4)))*(u1*(v2 - v3)*(v2*v3*(-(x2*y1) + x3*y1 +
x1*y2 - x1*y3) + v1*(v2*x2*y1 - v3*x3*y1 - v2*x1*y2 + v3*x1*y3)) +
u2*(v1 - v3)*(v1*(v3*(-x1 + x3)*y2 + v2*(-(x2*y1) + x1*y2) +
v3*x2*(y1 - y3)) + v2*v3*(-(x3*y2) + x2*y3)) + u3*(v1 -
v2)*(v2*v3*(x3*y2 - x2*y3) + v1*(-(v3*x3*y1) + v2*x3*(y1 - y2) +
v3*x1*y3 + v2*(-x1 + x2)*y3))))/((u3*(-v1 + v2) + u2*(v1 - v3) +
u1*(-v2 + v3))*(-(u1*v2*x1*x2) - u3*v1*x1*x3 + u1*v3*x1*x3 +
u3*v2*x2*x3 + u2*x2*(v1*x1 - v3*x3))*(-(u3*v1*v2*x1*x3) +
u3*v1*v4*x1*x3 + u3*v1*v2*x2*x3 - u3*v2*v4*x2*x3 + u4*v1*v2*x1*x4 -
u4*v1*v3*x1*x4 - u4*v1*v2*x2*x4 + u4*v2*v3*x2*x4 + u4*v1*v3*x3*x4 -
u4*v2*v3*x3*x4 - u3*v1*v4*x3*x4 + u3*v2*v4*x3*x4 + u2*x2*(v1*v3*(x1 -
x3) + v3*v4*(x3 - x4) + v1*v4*(-x1 + x4)) + u1*x1*(v2*v3*(-x2 + x3) +
v2*v4*(x2 - x4) + v3*v4*(-x3 + x4)))) + (((u1*u1)*(v2 - v3)*(v2*v3*(-x2
+ x3) + v2*v4*(x2 - x4) + v3*v4*(-x3 + x4))*y1 + (u2*u2)*(v1 -
v3)*(v1*v3*(-x1 + x3) + v1*v4*(x1 - x4) + v3*v4*(-x3 + x4))*y2 -
u3*(v1 - v2)*(u3*(v1*v2*(x1 - x2) + v2*v4*(x2 - x4) + v1*v4*(-x1 +
x4))*y3 + u4*(v1*v3*(-(x3*y1) + x4*(y1 - y3) + x1*y3) + v1*v2*(x3*(y1
- y2) + x4*(-y1 + y2) + (-x1 + x2)*y3) + v2*v3*(x3*y2 - x2*y3 +
x4*(-y2 + y3)))) + u1*(u4*(v2 - v3)*(v1*v2*(-(x2*y1) + x4*(y1 - y2) +
x1*y2) + v2*v3*(x2*y1 - x3*y1 - (x1 - x4)*(y2 - y3)) + v1*v3*(x3*y1 -
x1*y3 + x4*(-y1 + y3))) + u3*(v2*(-(v2*v4*(x2 - x4)*(y1 + y3)) +
v2*v3*(-(x3*y2) + x1*(y2 - y3) + x2*y3) + v3*v4*(x2*y1 - x1*y2 +
x3*y2 + x1*y3 - x4*(y1 + y3))) + v1*((v2*v2)*(x2*y1 - x1*y2 + x3*(-y1 +
y2)) + v2*v3*(x3*y1 + x1*y3 - x2*(y1 + y3)) + v2*v4*(x3*(y1 - y2) +
x1*y2 + x2*y3 - x4*(y1 + y3)) + v3*v4*(-(x3*y1) - x1*y3 + x4*(y1 +
y3))))) + u2*(u4*(v1 - v3)*(v1*v2*(x2*y1 - x1*y2 + x4*(-y1 + y2)) +
v1*v3*((x1 - x3)*y2 + x4*(y1 - y3) + x2*(-y1 + y3)) + v2*v3*(x3*y2 -
x2*y3 + x4*(-y2 + y3))) + u1*(v1*(v2*v3*(x2*y1 + x1*y2 - x3*(y1 +
y2)) + v2*v4*(-(x2*y1) - x1*y2 + x4*(y1 + y2)) + v3*v4*(x3*y2 -
x4*(y1 + y2) + x2*(y1 - y3) + x1*y3) + (v3*v3)*(x3*y1 - x1*y3 + x2*(-y1
+ y3))) + v3*(-(v3*v4*(x3 - x4)*(y1 + y2)) + v2*v4*(x3*y1 + x1*y2 -
x4*(y1 + y2) - x1*y3 + x2*y3) + v2*v3*(x3*y2 - x2*y3 + x1*(-y2 +
y3)))) + u3*(v2*v3*v4*(-(x3*y2) - x2*y3 + x4*(y2 + y3)) +
(v1*v1)*(v2*(-(x2*y1) + x3*y1 + x1*y2 - x3*y2) - v4*(x1 - x4)*(y2 + y3)
+ v3*(x2*y1 - x3*y1 + x1*y3 - x2*y3)) + v1*(v3*v4*(x3*y1 + x1*y2 -
x4*y2 - x4*y3 + x2*(-y1 + y3)) + v2*(v4*(x2*y1 - x3*y1 + x3*y2 -
x4*y2 + x1*y3 - x4*y3) + v3*(x3*y2 + x2*y3 - x1*(y2 +
y3)))))))*(-(v1*(v1 - v2)*(u3*v1 - u1*v3)*(u3*(v1 - v2) + u1*(v2 -
v3) + u2*(-v1 + v3))*(x1*x1)*x3*(-(u3*v1*v2*x1*x3) + u3*v1*v4*x1*x3 +
u3*v1*v2*x2*x3 - u3*v2*v4*x2*x3 + u4*v1*v2*x1*x4 - u4*v1*v3*x1*x4 -
u4*v1*v2*x2*x4 + u4*v2*v3*x2*x4 + u4*v1*v3*x3*x4 - u4*v2*v3*x3*x4 -
u3*v1*v4*x3*x4 + u3*v2*v4*x3*x4 + u2*x2*(v1*v3*(x1 - x3) + v3*v4*(x3
- x4) + v1*v4*(-x1 + x4)) + u1*x1*(v2*v3*(-x2 + x3) + v2*v4*(x2 - x4)
+ v3*v4*(-x3 + x4)))*(u2*v3*x2*x3*y1 - u2*v4*x2*x3*y1 -
u1*v3*x1*x3*y2 + u1*v4*x1*x3*y2 - u2*v1*x1*x2*y3 + u1*v2*x1*x2*y3 -
u1*v4*x1*x2*y3 + u2*v4*x1*x2*y3 + u2*v1*x1*x2*y4 - u1*v2*x1*x2*y4 +
u1*v4*x1*x2*y4 - u2*v4*x1*x2*y4 + u1*v3*x1*x3*y4 - u1*v4*x1*x3*y4 -
u2*v3*x2*x3*y4 + u2*v4*x2*x3*y4 + u3*x3*(v1*x1*(y2 - y4) + v2*x2*(-y1
+ y4) + v4*(x2*y1 - x1*y2 + x1*y4 - x2*y4)) + u4*(v3*x3*(-(x2*y1) +
x1*y2 - x1*y4 + x2*y4) + v1*x1*(-(x3*y2) + x2*y3 - x2*y4 + x3*y4) +
v2*x2*(x3*(y1 - y4) + x1*(-y3 + y4))))) - (u1*v2*x1*x2*x3 -
u1*v3*x1*x2*x3 - u4*v1*x1*x2*x4 - u1*v2*x1*x2*x4 + u4*v2*x1*x2*x4 +
u1*v4*x1*x2*x4 + u4*v1*x1*x3*x4 + u1*v3*x1*x3*x4 - u4*v3*x1*x3*x4 -
u1*v4*x1*x3*x4 - u4*v2*x2*x3*x4 + u4*v3*x2*x3*x4 + u3*x3*(v1*x1*(x2 -
x4) + v4*(x1 - x2)*x4 + v2*x2*(-x1 + x4)) + u2*x2*(v3*x3*(x1 - x4) +
v4*(-x1 + x3)*x4 + v1*x1*(-x3 + x4)))*(v1*x1*(-(u1*v2*x1*x2) -
u3*v1*x1*x3 + u1*v3*x1*x3 + u3*v2*x2*x3 + u2*x2*(v1*x1 -
v3*x3))*(-(v3*(-x1 + x3)*(v1*(u4*(-v1 + v2) + u2*(v1 - v4) + u1*(-v2
+ v4))*(u1*(-v2 + v3)*y1 + u2*(v1 - v3)*y2 + u3*(-v1 + v2)*y3) -
u1*(u4*(v1 - v2) + u1*(v2 - v4) + u2*(-v1 + v4))*(v1*v2*(y1 - y2) +
v2*v3*(y2 - y3) + v1*v3*(-y1 + y3)) - v1*(u3*(-v1 + v2) + u2*(v1 -
v3) + u1*(-v2 + v3))*(u1*(-v2 + v4)*y1 + u2*(v1 - v4)*y2 + u4*(-v1 +
v2)*y4) + u1*(u3*(v1 - v2) + u1*(v2 - v3) + u2*(-v1 + v3))*(v1*v2*(y1
- y2) + v2*v4*(y2 - y4) + v1*v4*(-y1 + y4)))) + (u3*v1 -
u1*v3)*x3*((u4*(v1 - v2) + u1*(v2 - v4) + u2*(-v1 + v4))*(v1*v2*(y1 -
y2) + v2*v3*(y2 - y3) + v1*v3*(-y1 + y3)) + (u3*(-v1 + v2) + u2*(v1 -
v3) + u1*(-v2 + v3))*(v1*v2*(y1 - y2) + v2*v4*(y2 - y4) + v1*v4*(-y1
+ y4)))) - (u2*v1*v3*x2*(x1 - x3) + u3*v1*v2*(-x1 + x2)*x3 +
u1*v2*v3*x1*(-x2 + x3))*(-(x1*(-(v1*x1) + v3*x3)*(v1*(u4*(-v1 + v2) +
u2*(v1 - v4) + u1*(-v2 + v4))*(u1*(-v2 + v3)*y1 + u2*(v1 - v3)*y2 +
u3*(-v1 + v2)*y3) - u1*(u4*(v1 - v2) + u1*(v2 - v4) + u2*(-v1 +
v4))*(v1*v2*(y1 - y2) + v2*v3*(y2 - y3) + v1*v3*(-y1 + y3)) -
v1*(u3*(-v1 + v2) + u2*(v1 - v3) + u1*(-v2 + v3))*(u1*(-v2 + v4)*y1 +
u2*(v1 - v4)*y2 + u4*(-v1 + v2)*y4) + u1*(u3*(v1 - v2) + u1*(v2 - v3)
+ u2*(-v1 + v3))*(v1*v2*(y1 - y2) + v2*v4*(y2 - y4) + v1*v4*(-y1 +
y4)))) + (u3*v1 - u1*v3)*x1*x3*((u4*(v1 - v2) + u1*(v2 - v4) +
u2*(-v1 + v4))*(v1*v2*(y1 - y2) + v2*v3*(y2 - y3) + v1*v3*(-y1 + y3))
+ (u3*(-v1 + v2) + u2*(v1 - v3) + u1*(-v2 + v3))*(v1*v2*(y1 - y2) +
v2*v4*(y2 - y4) + v1*v4*(-y1 + y4)))))))/((u3*(-v1 + v2) + u2*(v1 -
v3) + u1*(-v2 + v3))*(-(u3*v1*v2*x1*x3) + u3*v1*v4*x1*x3 +
u3*v1*v2*x2*x3 - u3*v2*v4*x2*x3 + u4*v1*v2*x1*x4 - u4*v1*v3*x1*x4 -
u4*v1*v2*x2*x4 + u4*v2*v3*x2*x4 + u4*v1*v3*x3*x4 - u4*v2*v3*x3*x4 -
u3*v1*v4*x3*x4 + u3*v2*v4*x3*x4 + u2*x2*(v1*v3*(x1 - x3) + v3*v4*(x3
- x4) + v1*v4*(-x1 + x4)) + u1*x1*(v2*v3*(-x2 + x3) + v2*v4*(x2 - x4)
+ v3*v4*(-x3 + x4)))*(-((u1*u4*(v2*x2 - v3*x3)*(x1 - x4) +
u3*u4*(v1*x1 - v2*x2)*(x3 - x4) - u1*u3*(x1 - x3)*(v2*x2 - v4*x4) +
u2*(-(u4*(v1*x1 - v3*x3)*(x2 - x4)) + u3*(x2 - x3)*(v1*x1 - v4*x4) +
u1*(x1 - x2)*(v3*x3 - v4*x4)))*(v1*x1*(-(u1*v2*x1*x2) - u3*v1*x1*x3 +
u1*v3*x1*x3 + u3*v2*x2*x3 + u2*x2*(v1*x1 - v3*x3))*(-(v3*(-x1 +
x3)*(v1*(u4*(-v1 + v2) + u2*(v1 - v4) + u1*(-v2 + v4))*(u1*(-v2 +
v3)*y1 + u2*(v1 - v3)*y2 + u3*(-v1 + v2)*y3) - u1*(u4*(v1 - v2) +
u1*(v2 - v4) + u2*(-v1 + v4))*(v1*v2*(y1 - y2) + v2*v3*(y2 - y3) +
v1*v3*(-y1 + y3)) - v1*(u3*(-v1 + v2) + u2*(v1 - v3) + u1*(-v2 +
v3))*(u1*(-v2 + v4)*y1 + u2*(v1 - v4)*y2 + u4*(-v1 + v2)*y4) +
u1*(u3*(v1 - v2) + u1*(v2 - v3) + u2*(-v1 + v3))*(v1*v2*(y1 - y2) +
v2*v4*(y2 - y4) + v1*v4*(-y1 + y4)))) + (u3*v1 - u1*v3)*x3*((u4*(v1 -
v2) + u1*(v2 - v4) + u2*(-v1 + v4))*(v1*v2*(y1 - y2) + v2*v3*(y2 -
y3) + v1*v3*(-y1 + y3)) + (u3*(-v1 + v2) + u2*(v1 - v3) + u1*(-v2 +
v3))*(v1*v2*(y1 - y2) + v2*v4*(y2 - y4) + v1*v4*(-y1 + y4)))) -
(u2*v1*v3*x2*(x1 - x3) + u3*v1*v2*(-x1 + x2)*x3 + u1*v2*v3*x1*(-x2 +
x3))*(-(x1*(-(v1*x1) + v3*x3)*(v1*(u4*(-v1 + v2) + u2*(v1 - v4) +
u1*(-v2 + v4))*(u1*(-v2 + v3)*y1 + u2*(v1 - v3)*y2 + u3*(-v1 +
v2)*y3) - u1*(u4*(v1 - v2) + u1*(v2 - v4) + u2*(-v1 + v4))*(v1*v2*(y1
- y2) + v2*v3*(y2 - y3) + v1*v3*(-y1 + y3)) - v1*(u3*(-v1 + v2) +
u2*(v1 - v3) + u1*(-v2 + v3))*(u1*(-v2 + v4)*y1 + u2*(v1 - v4)*y2 +
u4*(-v1 + v2)*y4) + u1*(u3*(v1 - v2) + u1*(v2 - v3) + u2*(-v1 +
v3))*(v1*v2*(y1 - y2) + v2*v4*(y2 - y4) + v1*v4*(-y1 + y4)))) +
(u3*v1 - u1*v3)*x1*x3*((u4*(v1 - v2) + u1*(v2 - v4) + u2*(-v1 +
v4))*(v1*v2*(y1 - y2) + v2*v3*(y2 - y3) + v1*v3*(-y1 + y3)) +
(u3*(-v1 + v2) + u2*(v1 - v3) + u1*(-v2 + v3))*(v1*v2*(y1 - y2) +
v2*v4*(y2 - y4) + v1*v4*(-y1 + y4)))))) + (-(u3*v1*v2*x1*x3) +
u3*v1*v4*x1*x3 + u3*v1*v2*x2*x3 - u3*v2*v4*x2*x3 + u4*v1*v2*x1*x4 -
u4*v1*v3*x1*x4 - u4*v1*v2*x2*x4 + u4*v2*v3*x2*x4 + u4*v1*v3*x3*x4 -
u4*v2*v3*x3*x4 - u3*v1*v4*x3*x4 + u3*v2*v4*x3*x4 + u2*x2*(v1*v3*(x1 -
x3) + v3*v4*(x3 - x4) + v1*v4*(-x1 + x4)) + u1*x1*(v2*v3*(-x2 + x3) +
v2*v4*(x2 - x4) + v3*v4*(-x3 + x4)))*(-((u2*u3*v1*x1*(x2 - x3) +
u1*u2*v3*(x1 - x2)*x3 + u1*u3*v2*x2*(-x1 + x3))*(-(x1*(-(v1*x1) +
v3*x3)*(v1*(u4*(-v1 + v2) + u2*(v1 - v4) + u1*(-v2 + v4))*(u1*(-v2 +
v3)*y1 + u2*(v1 - v3)*y2 + u3*(-v1 + v2)*y3) - u1*(u4*(v1 - v2) +
u1*(v2 - v4) + u2*(-v1 + v4))*(v1*v2*(y1 - y2) + v2*v3*(y2 - y3) +
v1*v3*(-y1 + y3)) - v1*(u3*(-v1 + v2) + u2*(v1 - v3) + u1*(-v2 +
v3))*(u1*(-v2 + v4)*y1 + u2*(v1 - v4)*y2 + u4*(-v1 + v2)*y4) +
u1*(u3*(v1 - v2) + u1*(v2 - v3) + u2*(-v1 + v3))*(v1*v2*(y1 - y2) +
v2*v4*(y2 - y4) + v1*v4*(-y1 + y4)))) + (u3*v1 -
u1*v3)*x1*x3*((u4*(v1 - v2) + u1*(v2 - v4) + u2*(-v1 +
v4))*(v1*v2*(y1 - y2) + v2*v3*(y2 - y3) + v1*v3*(-y1 + y3)) +
(u3*(-v1 + v2) + u2*(v1 - v3) + u1*(-v2 + v3))*(v1*v2*(y1 - y2) +
v2*v4*(y2 - y4) + v1*v4*(-y1 + y4))))) + (-(u1*v2*x1*x2) -
u3*v1*x1*x3 + u1*v3*x1*x3 + u3*v2*x2*x3 + u2*x2*(v1*x1 -
v3*x3))*(-(x1*(-(u3*v1*x1) + u1*v3*x3)*(v1*(u4*(-v1 + v2) + u2*(v1 -
v4) + u1*(-v2 + v4))*(u1*(-v2 + v3)*y1 + u2*(v1 - v3)*y2 + u3*(-v1 +
v2)*y3) - u1*(u4*(v1 - v2) + u1*(v2 - v4) + u2*(-v1 + v4))*(v1*v2*(y1
- y2) + v2*v3*(y2 - y3) + v1*v3*(-y1 + y3)) - v1*(u3*(-v1 + v2) +
u2*(v1 - v3) + u1*(-v2 + v3))*(u1*(-v2 + v4)*y1 + u2*(v1 - v4)*y2 +
u4*(-v1 + v2)*y4) + u1*(u3*(v1 - v2) + u1*(v2 - v3) + u2*(-v1 +
v3))*(v1*v2*(y1 - y2) + v2*v4*(y2 - y4) + v1*v4*(-y1 + y4)))) +
u1*(u3*v1 - u1*v3)*x1*x3*((u4*(v1 - v2) + u1*(v2 - v4) + u2*(-v1 +
v4))*(v1*v2*(y1 - y2) + v2*v3*(y2 - y3) + v1*v3*(-y1 + y3)) +
(u3*(-v1 + v2) + u2*(v1 - v3) + u1*(-v2 + v3))*(v1*v2*(y1 - y2) +
v2*v4*(y2 - y4) + v1*v4*(-y1 + y4)))))));
double e = (u2*x2*x3*y1 -
u3*x2*x3*y1 - u1*x1*x3*y2 + u3*x1*x3*y2 + u1*x1*x2*y3 -
u2*x1*x2*y3)/(u2*v1*x1*x2 - u1*v2*x1*x2 - u3*v1*x1*x3 + u1*v3*x1*x3 +
u3*v2*x2*x3 - u2*v3*x2*x3) + ((-(u1*v2*x1*x2*x3) + u1*v3*x1*x2*x3 +
u4*v1*x1*x2*x4 + u1*v2*x1*x2*x4 - u4*v2*x1*x2*x4 - u1*v4*x1*x2*x4 -
u4*v1*x1*x3*x4 - u1*v3*x1*x3*x4 + u4*v3*x1*x3*x4 + u1*v4*x1*x3*x4 +
u4*v2*x2*x3*x4 - u4*v3*x2*x3*x4 + u2*x2*(v1*x1*(x3 - x4) + v4*(x1 -
x3)*x4 + v3*x3*(-x1 + x4)) + u3*x3*(v2*x2*(x1 - x4) + v4*(-x1 +
x2)*x4 + v1*x1*(-x2 + x4)))*((u3*u3)*(v1 - v2)*x3*(v1*y1 - v2*y2) +
(u2*u2)*(v1 - v3)*x2*(v1*y1 - v3*y3) + (u1*u1)*(v2 - v3)*x1*(v2*y2 - v3*y3)
+ u1*u3*(-((v2*v2)*(x1 + x3)*y2) - v1*v3*(x3*y1 + x1*y3) + v1*v2*(x3*y2
+ x2*(y1 - y3) + x1*y3) + v2*v3*(x3*y1 + x1*y2 + x2*(-y1 + y3))) +
u2*(u1*(-(v1*v2*(x2*y1 + x1*y2)) - (v3*v3)*(x1 + x2)*y3 + v2*v3*(x2*y1 -
x3*y1 + x3*y2 + x1*y3) + v1*v3*(x3*(y1 - y2) + x1*y2 + x2*y3)) +
u3*(-((v1*v1)*(x2 + x3)*y1) + v1*v3*(x2*y1 - x1*y2 + x3*y2 + x1*y3) -
v2*v3*(x3*y2 + x2*y3) + v1*v2*(x3*y1 + x1*y2 - x1*y3 +
x2*y3)))))/((u3*(-v1 + v2) + u2*(v1 - v3) + u1*(-v2 +
v3))*(-(u1*v2*x1*x2) - u3*v1*x1*x3 + u1*v3*x1*x3 + u3*v2*x2*x3 +
u2*x2*(v1*x1 - v3*x3))*(-(u3*v1*v2*x1*x3) + u3*v1*v4*x1*x3 +
u3*v1*v2*x2*x3 - u3*v2*v4*x2*x3 + u4*v1*v2*x1*x4 - u4*v1*v3*x1*x4 -
u4*v1*v2*x2*x4 + u4*v2*v3*x2*x4 + u4*v1*v3*x3*x4 - u4*v2*v3*x3*x4 -
u3*v1*v4*x3*x4 + u3*v2*v4*x3*x4 + u2*x2*(v1*v3*(x1 - x3) + v3*v4*(x3
- x4) + v1*v4*(-x1 + x4)) + u1*x1*(v2*v3*(-x2 + x3) + v2*v4*(x2 - x4)
+ v3*v4*(-x3 + x4)))) + ((-((u3*u3)*u4*(v1 - v2)*(x3 - x4)*(v1*y1 -
v2*y2)) + (u1*u1)*(-(u4*(v2 - v3)*(x1 - x4)*(v2*y2 - v3*y3)) +
u3*((v2*v2)*(x1 - x3)*y2 + v3*v4*(-(x3*y1) + x4*y1 + x1*y3 - x4*y3) +
v2*v4*(-(x4*y1) - x1*y2 + x3*y2 + x2*(y1 - y3) + x4*y3) +
v2*v3*(x3*y1 - x1*y3 + x2*(-y1 + y3)))) + u1*u3*(u3*((v2*v2)*(-x1 +
x3)*y2 + v1*v2*(-(x3*y1) + x2*(y1 - y3) + x1*y3) + v2*v4*((x1 -
x3)*y2 + x4*(y1 - y3) + x2*(-y1 + y3)) + v1*v4*(x3*y1 - x1*y3 +
x4*(-y1 + y3))) + u4*((v2*v2)*(x1 + x3 - 2*x4)*y2 + v2*v3*(-(x3*y1) -
x1*y2 + x4*y2 + x2*(y1 - y3) + x4*y3) + v1*v2*(-(x3*y2) + x4*(y1 +
y2) - x1*y3 + x2*(-y1 + y3)) + v1*v3*(x3*y1 + x1*y3 - x4*(y1 + y3))))
+ (u2*u2)*(-(u4*(v1 - v3)*(x2 - x4)*(v1*y1 - v3*y3)) +
u1*(v1*v3*(-(x2*y1) + x3*(y1 - y2) + x1*y2) + v1*v4*(x2*y1 - x1*y2 +
x4*(-y1 + y2)) + (v3*v3)*(-x1 + x2)*y3 + v3*v4*(x4*(y1 - y2) + x3*(-y1 +
y2) + (x1 - x2)*y3)) + u3*((v1*v1)*(x2 - x3)*y1 + v1*v4*(-(x2*y1) +
x3*y1 + (x1 - x4)*(y2 - y3)) + v3*v4*(-(x3*y2) + x4*(y2 - y3) +
x2*y3) + v1*v3*(x3*y2 - x2*y3 + x1*(-y2 + y3)))) - u2*((u3*u3)*((v1*v1)*(x2
- x3)*y1 + v1*v4*(-(x2*y1) + x3*y1 + (x1 - x4)*(y2 - y3)) +
v2*v4*(-(x3*y2) + x4*(y2 - y3) + x2*y3) + v1*v2*(x3*y2 - x2*y3 +
x1*(-y2 + y3))) - u1*(u1*(v2*v4*(-(x2*y1) + x4*(y1 - y2) + x1*y2) +
v2*v3*(x2*y1 - x1*y2 + x3*(-y1 + y2)) + (v3*v3)*(x1 - x2)*y3 +
v3*v4*(x3*(y1 - y2) + x4*(-y1 + y2) + (-x1 + x2)*y3)) +
u4*(v1*v2*(x2*y1 + x1*y2 - x4*(y1 + y2)) + (v3*v3)*(x1 + x2 - 2*x4)*y3 +
v2*v3*(-(x2*y1) + x3*(y1 - y2) + x4*y2 - x1*y3 + x4*y3) +
v1*v3*(-(x1*y2) + x3*(-y1 + y2) - x2*y3 + x4*(y1 + y3)))) +
u3*(-(u4*((v1*v1)*(x2 + x3 - 2*x4)*y1 + v1*v2*(-(x3*y1) - x1*y2 + x4*(y1
+ y2) + x1*y3 - x2*y3) + v1*v3*(-(x2*y1) + x1*y2 - x3*y2 - x1*y3 +
x4*(y1 + y3)) + v2*v3*(x3*y2 + x2*y3 - x4*(y2 + y3)))) +
u1*(v3*v4*(-(x3*(y1 + y2)) + x4*(y1 + y2 - 2*y3) + (x1 + x2)*y3) +
v1*(v2*(x2*y1 + x1*y2 - x3*(y1 + y2)) + v4*(x2*y1 + x3*y1 - 2*x4*y1 -
x1*y2 + x4*y2 - x1*y3 + x4*y3) + v3*(x3*y1 + x1*y3 - x2*(y1 + y3))) +
v2*(v4*((x1 + x3)*y2 - x2*(y1 + y3) + x4*(y1 - 2*y2 + y3)) +
v3*(x3*y2 + x2*y3 - x1*(y2 + y3)))))))*(-(v1*(v1 - v2)*(u3*v1 -
u1*v3)*(u3*(v1 - v2) + u1*(v2 - v3) + u2*(-v1 +
v3))*(x1*x1)*x3*(-(u3*v1*v2*x1*x3) + u3*v1*v4*x1*x3 + u3*v1*v2*x2*x3 -
u3*v2*v4*x2*x3 + u4*v1*v2*x1*x4 - u4*v1*v3*x1*x4 - u4*v1*v2*x2*x4 +
u4*v2*v3*x2*x4 + u4*v1*v3*x3*x4 - u4*v2*v3*x3*x4 - u3*v1*v4*x3*x4 +
u3*v2*v4*x3*x4 + u2*x2*(v1*v3*(x1 - x3) + v3*v4*(x3 - x4) +
v1*v4*(-x1 + x4)) + u1*x1*(v2*v3*(-x2 + x3) + v2*v4*(x2 - x4) +
v3*v4*(-x3 + x4)))*(u2*v3*x2*x3*y1 - u2*v4*x2*x3*y1 - u1*v3*x1*x3*y2
+ u1*v4*x1*x3*y2 - u2*v1*x1*x2*y3 + u1*v2*x1*x2*y3 - u1*v4*x1*x2*y3 +
u2*v4*x1*x2*y3 + u2*v1*x1*x2*y4 - u1*v2*x1*x2*y4 + u1*v4*x1*x2*y4 -
u2*v4*x1*x2*y4 + u1*v3*x1*x3*y4 - u1*v4*x1*x3*y4 - u2*v3*x2*x3*y4 +
u2*v4*x2*x3*y4 + u3*x3*(v1*x1*(y2 - y4) + v2*x2*(-y1 + y4) +
v4*(x2*y1 - x1*y2 + x1*y4 - x2*y4)) + u4*(v3*x3*(-(x2*y1) + x1*y2 -
x1*y4 + x2*y4) + v1*x1*(-(x3*y2) + x2*y3 - x2*y4 + x3*y4) +
v2*x2*(x3*(y1 - y4) + x1*(-y3 + y4))))) - (u1*v2*x1*x2*x3 -
u1*v3*x1*x2*x3 - u4*v1*x1*x2*x4 - u1*v2*x1*x2*x4 + u4*v2*x1*x2*x4 +
u1*v4*x1*x2*x4 + u4*v1*x1*x3*x4 + u1*v3*x1*x3*x4 - u4*v3*x1*x3*x4 -
u1*v4*x1*x3*x4 - u4*v2*x2*x3*x4 + u4*v3*x2*x3*x4 + u3*x3*(v1*x1*(x2 -
x4) + v4*(x1 - x2)*x4 + v2*x2*(-x1 + x4)) + u2*x2*(v3*x3*(x1 - x4) +
v4*(-x1 + x3)*x4 + v1*x1*(-x3 + x4)))*(v1*x1*(-(u1*v2*x1*x2) -
u3*v1*x1*x3 + u1*v3*x1*x3 + u3*v2*x2*x3 + u2*x2*(v1*x1 -
v3*x3))*(-(v3*(-x1 + x3)*(v1*(u4*(-v1 + v2) + u2*(v1 - v4) + u1*(-v2
+ v4))*(u1*(-v2 + v3)*y1 + u2*(v1 - v3)*y2 + u3*(-v1 + v2)*y3) -
u1*(u4*(v1 - v2) + u1*(v2 - v4) + u2*(-v1 + v4))*(v1*v2*(y1 - y2) +
v2*v3*(y2 - y3) + v1*v3*(-y1 + y3)) - v1*(u3*(-v1 + v2) + u2*(v1 -
v3) + u1*(-v2 + v3))*(u1*(-v2 + v4)*y1 + u2*(v1 - v4)*y2 + u4*(-v1 +
v2)*y4) + u1*(u3*(v1 - v2) + u1*(v2 - v3) + u2*(-v1 + v3))*(v1*v2*(y1
- y2) + v2*v4*(y2 - y4) + v1*v4*(-y1 + y4)))) + (u3*v1 -
u1*v3)*x3*((u4*(v1 - v2) + u1*(v2 - v4) + u2*(-v1 + v4))*(v1*v2*(y1 -
y2) + v2*v3*(y2 - y3) + v1*v3*(-y1 + y3)) + (u3*(-v1 + v2) + u2*(v1 -
v3) + u1*(-v2 + v3))*(v1*v2*(y1 - y2) + v2*v4*(y2 - y4) + v1*v4*(-y1
+ y4)))) - (u2*v1*v3*x2*(x1 - x3) + u3*v1*v2*(-x1 + x2)*x3 +
u1*v2*v3*x1*(-x2 + x3))*(-(x1*(-(v1*x1) + v3*x3)*(v1*(u4*(-v1 + v2) +
u2*(v1 - v4) + u1*(-v2 + v4))*(u1*(-v2 + v3)*y1 + u2*(v1 - v3)*y2 +
u3*(-v1 + v2)*y3) - u1*(u4*(v1 - v2) + u1*(v2 - v4) + u2*(-v1 +
v4))*(v1*v2*(y1 - y2) + v2*v3*(y2 - y3) + v1*v3*(-y1 + y3)) -
v1*(u3*(-v1 + v2) + u2*(v1 - v3) + u1*(-v2 + v3))*(u1*(-v2 + v4)*y1 +
u2*(v1 - v4)*y2 + u4*(-v1 + v2)*y4) + u1*(u3*(v1 - v2) + u1*(v2 - v3)
+ u2*(-v1 + v3))*(v1*v2*(y1 - y2) + v2*v4*(y2 - y4) + v1*v4*(-y1 +
y4)))) + (u3*v1 - u1*v3)*x1*x3*((u4*(v1 - v2) + u1*(v2 - v4) +
u2*(-v1 + v4))*(v1*v2*(y1 - y2) + v2*v3*(y2 - y3) + v1*v3*(-y1 + y3))
+ (u3*(-v1 + v2) + u2*(v1 - v3) + u1*(-v2 + v3))*(v1*v2*(y1 - y2) +
v2*v4*(y2 - y4) + v1*v4*(-y1 + y4)))))))/((u3*(-v1 + v2) + u2*(v1 -
v3) + u1*(-v2 + v3))*(-(u3*v1*v2*x1*x3) + u3*v1*v4*x1*x3 +
u3*v1*v2*x2*x3 - u3*v2*v4*x2*x3 + u4*v1*v2*x1*x4 - u4*v1*v3*x1*x4 -
u4*v1*v2*x2*x4 + u4*v2*v3*x2*x4 + u4*v1*v3*x3*x4 - u4*v2*v3*x3*x4 -
u3*v1*v4*x3*x4 + u3*v2*v4*x3*x4 + u2*x2*(v1*v3*(x1 - x3) + v3*v4*(x3
- x4) + v1*v4*(-x1 + x4)) + u1*x1*(v2*v3*(-x2 + x3) + v2*v4*(x2 - x4)
+ v3*v4*(-x3 + x4)))*(-((u1*u4*(v2*x2 - v3*x3)*(x1 - x4) +
u3*u4*(v1*x1 - v2*x2)*(x3 - x4) - u1*u3*(x1 - x3)*(v2*x2 - v4*x4) +
u2*(-(u4*(v1*x1 - v3*x3)*(x2 - x4)) + u3*(x2 - x3)*(v1*x1 - v4*x4) +
u1*(x1 - x2)*(v3*x3 - v4*x4)))*(v1*x1*(-(u1*v2*x1*x2) - u3*v1*x1*x3 +
u1*v3*x1*x3 + u3*v2*x2*x3 + u2*x2*(v1*x1 - v3*x3))*(-(v3*(-x1 +
x3)*(v1*(u4*(-v1 + v2) + u2*(v1 - v4) + u1*(-v2 + v4))*(u1*(-v2 +
v3)*y1 + u2*(v1 - v3)*y2 + u3*(-v1 + v2)*y3) - u1*(u4*(v1 - v2) +
u1*(v2 - v4) + u2*(-v1 + v4))*(v1*v2*(y1 - y2) + v2*v3*(y2 - y3) +
v1*v3*(-y1 + y3)) - v1*(u3*(-v1 + v2) + u2*(v1 - v3) + u1*(-v2 +
v3))*(u1*(-v2 + v4)*y1 + u2*(v1 - v4)*y2 + u4*(-v1 + v2)*y4) +
u1*(u3*(v1 - v2) + u1*(v2 - v3) + u2*(-v1 + v3))*(v1*v2*(y1 - y2) +
v2*v4*(y2 - y4) + v1*v4*(-y1 + y4)))) + (u3*v1 - u1*v3)*x3*((u4*(v1 -
v2) + u1*(v2 - v4) + u2*(-v1 + v4))*(v1*v2*(y1 - y2) + v2*v3*(y2 -
y3) + v1*v3*(-y1 + y3)) + (u3*(-v1 + v2) + u2*(v1 - v3) + u1*(-v2 +
v3))*(v1*v2*(y1 - y2) + v2*v4*(y2 - y4) + v1*v4*(-y1 + y4)))) -
(u2*v1*v3*x2*(x1 - x3) + u3*v1*v2*(-x1 + x2)*x3 + u1*v2*v3*x1*(-x2 +
x3))*(-(x1*(-(v1*x1) + v3*x3)*(v1*(u4*(-v1 + v2) + u2*(v1 - v4) +
u1*(-v2 + v4))*(u1*(-v2 + v3)*y1 + u2*(v1 - v3)*y2 + u3*(-v1 +
v2)*y3) - u1*(u4*(v1 - v2) + u1*(v2 - v4) + u2*(-v1 + v4))*(v1*v2*(y1
- y2) + v2*v3*(y2 - y3) + v1*v3*(-y1 + y3)) - v1*(u3*(-v1 + v2) +
u2*(v1 - v3) + u1*(-v2 + v3))*(u1*(-v2 + v4)*y1 + u2*(v1 - v4)*y2 +
u4*(-v1 + v2)*y4) + u1*(u3*(v1 - v2) + u1*(v2 - v3) + u2*(-v1 +
v3))*(v1*v2*(y1 - y2) + v2*v4*(y2 - y4) + v1*v4*(-y1 + y4)))) +
(u3*v1 - u1*v3)*x1*x3*((u4*(v1 - v2) + u1*(v2 - v4) + u2*(-v1 +
v4))*(v1*v2*(y1 - y2) + v2*v3*(y2 - y3) + v1*v3*(-y1 + y3)) +
(u3*(-v1 + v2) + u2*(v1 - v3) + u1*(-v2 + v3))*(v1*v2*(y1 - y2) +
v2*v4*(y2 - y4) + v1*v4*(-y1 + y4)))))) + (-(u3*v1*v2*x1*x3) +
u3*v1*v4*x1*x3 + u3*v1*v2*x2*x3 - u3*v2*v4*x2*x3 + u4*v1*v2*x1*x4 -
u4*v1*v3*x1*x4 - u4*v1*v2*x2*x4 + u4*v2*v3*x2*x4 + u4*v1*v3*x3*x4 -
u4*v2*v3*x3*x4 - u3*v1*v4*x3*x4 + u3*v2*v4*x3*x4 + u2*x2*(v1*v3*(x1 -
x3) + v3*v4*(x3 - x4) + v1*v4*(-x1 + x4)) + u1*x1*(v2*v3*(-x2 + x3) +
v2*v4*(x2 - x4) + v3*v4*(-x3 + x4)))*(-((u2*u3*v1*x1*(x2 - x3) +
u1*u2*v3*(x1 - x2)*x3 + u1*u3*v2*x2*(-x1 + x3))*(-(x1*(-(v1*x1) +
v3*x3)*(v1*(u4*(-v1 + v2) + u2*(v1 - v4) + u1*(-v2 + v4))*(u1*(-v2 +
v3)*y1 + u2*(v1 - v3)*y2 + u3*(-v1 + v2)*y3) - u1*(u4*(v1 - v2) +
u1*(v2 - v4) + u2*(-v1 + v4))*(v1*v2*(y1 - y2) + v2*v3*(y2 - y3) +
v1*v3*(-y1 + y3)) - v1*(u3*(-v1 + v2) + u2*(v1 - v3) + u1*(-v2 +
v3))*(u1*(-v2 + v4)*y1 + u2*(v1 - v4)*y2 + u4*(-v1 + v2)*y4) +
u1*(u3*(v1 - v2) + u1*(v2 - v3) + u2*(-v1 + v3))*(v1*v2*(y1 - y2) +
v2*v4*(y2 - y4) + v1*v4*(-y1 + y4)))) + (u3*v1 -
u1*v3)*x1*x3*((u4*(v1 - v2) + u1*(v2 - v4) + u2*(-v1 +
v4))*(v1*v2*(y1 - y2) + v2*v3*(y2 - y3) + v1*v3*(-y1 + y3)) +
(u3*(-v1 + v2) + u2*(v1 - v3) + u1*(-v2 + v3))*(v1*v2*(y1 - y2) +
v2*v4*(y2 - y4) + v1*v4*(-y1 + y4))))) + (-(u1*v2*x1*x2) -
u3*v1*x1*x3 + u1*v3*x1*x3 + u3*v2*x2*x3 + u2*x2*(v1*x1 -
v3*x3))*(-(x1*(-(u3*v1*x1) + u1*v3*x3)*(v1*(u4*(-v1 + v2) + u2*(v1 -
v4) + u1*(-v2 + v4))*(u1*(-v2 + v3)*y1 + u2*(v1 - v3)*y2 + u3*(-v1 +
v2)*y3) - u1*(u4*(v1 - v2) + u1*(v2 - v4) + u2*(-v1 + v4))*(v1*v2*(y1
- y2) + v2*v3*(y2 - y3) + v1*v3*(-y1 + y3)) - v1*(u3*(-v1 + v2) +
u2*(v1 - v3) + u1*(-v2 + v3))*(u1*(-v2 + v4)*y1 + u2*(v1 - v4)*y2 +
u4*(-v1 + v2)*y4) + u1*(u3*(v1 - v2) + u1*(v2 - v3) + u2*(-v1 +
v3))*(v1*v2*(y1 - y2) + v2*v4*(y2 - y4) + v1*v4*(-y1 + y4)))) +
u1*(u3*v1 - u1*v3)*x1*x3*((u4*(v1 - v2) + u1*(v2 - v4) + u2*(-v1 +
v4))*(v1*v2*(y1 - y2) + v2*v3*(y2 - y3) + v1*v3*(-y1 + y3)) +
(u3*(-v1 + v2) + u2*(v1 - v3) + u1*(-v2 + v3))*(v1*v2*(y1 - y2) +
v2*v4*(y2 - y4) + v1*v4*(-y1 + y4)))))));
double f = (u3*v2*x2*x3*y1 -
u2*v3*x2*x3*y1 - u3*v1*x1*x3*y2 + u1*v3*x1*x3*y2 + u2*v1*x1*x2*y3 -
u1*v2*x1*x2*y3)/(u2*v1*x1*x2 - u1*v2*x1*x2 - u3*v1*x1*x3 +
u1*v3*x1*x3 + u3*v2*x2*x3 - u2*v3*x2*x3) + ((u1*v2*x1*x2*x3 -
u1*v3*x1*x2*x3 - u4*v1*x1*x2*x4 - u1*v2*x1*x2*x4 + u4*v2*x1*x2*x4 +
u1*v4*x1*x2*x4 + u4*v1*x1*x3*x4 + u1*v3*x1*x3*x4 - u4*v3*x1*x3*x4 -
u1*v4*x1*x3*x4 - u4*v2*x2*x3*x4 + u4*v3*x2*x3*x4 + u3*x3*(v1*x1*(x2 -
x4) + v4*(x1 - x2)*x4 + v2*x2*(-x1 + x4)) + u2*x2*(v3*x3*(x1 - x4) +
v4*(-x1 + x3)*x4 + v1*x1*(-x3 + x4)))*(-(u3*v1*v2*x3*y1) +
u2*v1*v3*x3*y1 + u2*v1*v3*x1*y2 - u1*v2*v3*x1*y2 + u3*v1*v2*x3*y2 -
u2*v1*v3*x3*y2 - u2*v1*v3*x1*y3 + u1*v2*v3*x1*y3 - ((u2*v1*v3*x2*(x1
- x3) + u3*v1*v2*(-x1 + x2)*x3 + u1*v2*v3*x1*(-x2 +
x3))*(u2*v3*x3*(y1 - y2) + u3*v2*x3*(-y1 + y2) + u2*v1*x1*(y2 - y3) +
u1*v2*x1*(-y2 + y3)))/(-(u1*v2*x1*x2) - u3*v1*x1*x3 + u1*v3*x1*x3 +
u3*v2*x2*x3 + u2*x2*(v1*x1 - v3*x3))))/((u3*(-v1 + v2) + u2*(v1 - v3)
+ u1*(-v2 + v3))*x1*x3*(-(u3*v1*v2*x1*x3) + u3*v1*v4*x1*x3 +
u3*v1*v2*x2*x3 - u3*v2*v4*x2*x3 + u4*v1*v2*x1*x4 - u4*v1*v3*x1*x4 -
u4*v1*v2*x2*x4 + u4*v2*v3*x2*x4 + u4*v1*v3*x3*x4 - u4*v2*v3*x3*x4 -
u3*v1*v4*x3*x4 + u3*v2*v4*x3*x4 + u2*x2*(v1*v3*(x1 - x3) + v3*v4*(x3
- x4) + v1*v4*(-x1 + x4)) + u1*x1*(v2*v3*(-x2 + x3) + v2*v4*(x2 - x4)
+ v3*v4*(-x3 + x4)))) + ((((u1*u3*v2*x2*(x1 - x3) + u1*u2*v3*(-x1 +
x2)*x3 + u2*u3*v1*x1*(-x2 + x3))*(u2*v3*x3*(y1 - y2) + u3*v2*x3*(-y1
+ y2) + u2*v1*x1*(y2 - y3) + u1*v2*x1*(-y2 + y3)))/((u3*(v1 - v2) +
u1*(v2 - v3) + u2*(-v1 + v3))*x1*x3*(-(u2*v1*x1*x2) + u1*v2*x1*x2 +
u3*v1*x1*x3 - u1*v3*x1*x3 - u3*v2*x2*x3 + u2*v3*x2*x3)) +
(u1*u2*v3*x3*(y1 - y2) + u2*u3*v1*x1*(y2 - y3) + u1*u3*v2*(x3*(-y1 +
y2) + x1*(-y2 + y3)))/((u3*(-v1 + v2) + u2*(v1 - v3) + u1*(-v2 +
v3))*x1*x3) - ((u1*u4*(v2*x2 - v3*x3)*(x1 - x4) + u3*u4*(v1*x1 -
v2*x2)*(x3 - x4) - u1*u3*(x1 - x3)*(v2*x2 - v4*x4) + u2*(-(u4*(v1*x1
- v3*x3)*(x2 - x4)) + u3*(x2 - x3)*(v1*x1 - v4*x4) + u1*(x1 -
x2)*(v3*x3 - v4*x4)))*((u3*u3)*v1*(v1 - v2)*v2*x3*(y1 - y2) +
(u2*u2)*v1*(v1 - v3)*v3*x2*(y1 - y3) + (u1*u1)*v2*(v2 - v3)*v3*x1*(y2 - y3)
+ u2*u3*v1*(v2*v3*x3*(y1 - y2) + v2*v3*x2*(y1 - y3) + v1*v2*(x1*(y2 -
y3) + x2*(-y1 + y3)) + v1*v3*(x3*(-y1 + y2) + x1*(-y2 + y3))) +
u1*u3*v2*(v2*v3*x3*(y1 - y2) + v1*v3*(x3*(-y1 + y2) + x1*(y2 - y3)) +
v2*v3*x2*(-y1 + y3) + v1*v2*(x2*(y1 - y3) + x1*(-y2 + y3))) +
u1*u2*v3*(v2*v3*x3*(-y1 + y2) + v1*v3*(x3*(y1 - y2) + x1*(y2 - y3)) +
v2*v3*x2*(y1 - y3) + v1*v2*(x2*(-y1 + y3) + x1*(-y2 +
y3)))))/((u3*(-v1 + v2) + u2*(v1 - v3) + u1*(-v2 +
v3))*(-(u1*v2*x1*x2) - u3*v1*x1*x3 + u1*v3*x1*x3 + u3*v2*x2*x3 +
u2*x2*(v1*x1 - v3*x3))*(-(u3*v1*v2*x1*x3) + u3*v1*v4*x1*x3 +
u3*v1*v2*x2*x3 - u3*v2*v4*x2*x3 + u4*v1*v2*x1*x4 - u4*v1*v3*x1*x4 -
u4*v1*v2*x2*x4 + u4*v2*v3*x2*x4 + u4*v1*v3*x3*x4 - u4*v2*v3*x3*x4 -
u3*v1*v4*x3*x4 + u3*v2*v4*x3*x4 + u2*x2*(v1*v3*(x1 - x3) + v3*v4*(x3
- x4) + v1*v4*(-x1 + x4)) + u1*x1*(v2*v3*(-x2 + x3) + v2*v4*(x2 - x4)
+ v3*v4*(-x3 + x4)))))*(-(v1*(v1 - v2)*(u3*v1 - u1*v3)*(u3*(v1 - v2)
+ u1*(v2 - v3) + u2*(-v1 + v3))*(x1*x1)*x3*(-(u3*v1*v2*x1*x3) +
u3*v1*v4*x1*x3 + u3*v1*v2*x2*x3 - u3*v2*v4*x2*x3 + u4*v1*v2*x1*x4 -
u4*v1*v3*x1*x4 - u4*v1*v2*x2*x4 + u4*v2*v3*x2*x4 + u4*v1*v3*x3*x4 -
u4*v2*v3*x3*x4 - u3*v1*v4*x3*x4 + u3*v2*v4*x3*x4 + u2*x2*(v1*v3*(x1 -
x3) + v3*v4*(x3 - x4) + v1*v4*(-x1 + x4)) + u1*x1*(v2*v3*(-x2 + x3) +
v2*v4*(x2 - x4) + v3*v4*(-x3 + x4)))*(u2*v3*x2*x3*y1 - u2*v4*x2*x3*y1
- u1*v3*x1*x3*y2 + u1*v4*x1*x3*y2 - u2*v1*x1*x2*y3 + u1*v2*x1*x2*y3 -
u1*v4*x1*x2*y3 + u2*v4*x1*x2*y3 + u2*v1*x1*x2*y4 - u1*v2*x1*x2*y4 +
u1*v4*x1*x2*y4 - u2*v4*x1*x2*y4 + u1*v3*x1*x3*y4 - u1*v4*x1*x3*y4 -
u2*v3*x2*x3*y4 + u2*v4*x2*x3*y4 + u3*x3*(v1*x1*(y2 - y4) + v2*x2*(-y1
+ y4) + v4*(x2*y1 - x1*y2 + x1*y4 - x2*y4)) + u4*(v3*x3*(-(x2*y1) +
x1*y2 - x1*y4 + x2*y4) + v1*x1*(-(x3*y2) + x2*y3 - x2*y4 + x3*y4) +
v2*x2*(x3*(y1 - y4) + x1*(-y3 + y4))))) - (u1*v2*x1*x2*x3 -
u1*v3*x1*x2*x3 - u4*v1*x1*x2*x4 - u1*v2*x1*x2*x4 + u4*v2*x1*x2*x4 +
u1*v4*x1*x2*x4 + u4*v1*x1*x3*x4 + u1*v3*x1*x3*x4 - u4*v3*x1*x3*x4 -
u1*v4*x1*x3*x4 - u4*v2*x2*x3*x4 + u4*v3*x2*x3*x4 + u3*x3*(v1*x1*(x2 -
x4) + v4*(x1 - x2)*x4 + v2*x2*(-x1 + x4)) + u2*x2*(v3*x3*(x1 - x4) +
v4*(-x1 + x3)*x4 + v1*x1*(-x3 + x4)))*(v1*x1*(-(u1*v2*x1*x2) -
u3*v1*x1*x3 + u1*v3*x1*x3 + u3*v2*x2*x3 + u2*x2*(v1*x1 -
v3*x3))*(-(v3*(-x1 + x3)*(v1*(u4*(-v1 + v2) + u2*(v1 - v4) + u1*(-v2
+ v4))*(u1*(-v2 + v3)*y1 + u2*(v1 - v3)*y2 + u3*(-v1 + v2)*y3) -
u1*(u4*(v1 - v2) + u1*(v2 - v4) + u2*(-v1 + v4))*(v1*v2*(y1 - y2) +
v2*v3*(y2 - y3) + v1*v3*(-y1 + y3)) - v1*(u3*(-v1 + v2) + u2*(v1 -
v3) + u1*(-v2 + v3))*(u1*(-v2 + v4)*y1 + u2*(v1 - v4)*y2 + u4*(-v1 +
v2)*y4) + u1*(u3*(v1 - v2) + u1*(v2 - v3) + u2*(-v1 + v3))*(v1*v2*(y1
- y2) + v2*v4*(y2 - y4) + v1*v4*(-y1 + y4)))) + (u3*v1 -
u1*v3)*x3*((u4*(v1 - v2) + u1*(v2 - v4) + u2*(-v1 + v4))*(v1*v2*(y1 -
y2) + v2*v3*(y2 - y3) + v1*v3*(-y1 + y3)) + (u3*(-v1 + v2) + u2*(v1 -
v3) + u1*(-v2 + v3))*(v1*v2*(y1 - y2) + v2*v4*(y2 - y4) + v1*v4*(-y1
+ y4)))) - (u2*v1*v3*x2*(x1 - x3) + u3*v1*v2*(-x1 + x2)*x3 +
u1*v2*v3*x1*(-x2 + x3))*(-(x1*(-(v1*x1) + v3*x3)*(v1*(u4*(-v1 + v2) +
u2*(v1 - v4) + u1*(-v2 + v4))*(u1*(-v2 + v3)*y1 + u2*(v1 - v3)*y2 +
u3*(-v1 + v2)*y3) - u1*(u4*(v1 - v2) + u1*(v2 - v4) + u2*(-v1 +
v4))*(v1*v2*(y1 - y2) + v2*v3*(y2 - y3) + v1*v3*(-y1 + y3)) -
v1*(u3*(-v1 + v2) + u2*(v1 - v3) + u1*(-v2 + v3))*(u1*(-v2 + v4)*y1 +
u2*(v1 - v4)*y2 + u4*(-v1 + v2)*y4) + u1*(u3*(v1 - v2) + u1*(v2 - v3)
+ u2*(-v1 + v3))*(v1*v2*(y1 - y2) + v2*v4*(y2 - y4) + v1*v4*(-y1 +
y4)))) + (u3*v1 - u1*v3)*x1*x3*((u4*(v1 - v2) + u1*(v2 - v4) +
u2*(-v1 + v4))*(v1*v2*(y1 - y2) + v2*v3*(y2 - y3) + v1*v3*(-y1 + y3))
+ (u3*(-v1 + v2) + u2*(v1 - v3) + u1*(-v2 + v3))*(v1*v2*(y1 - y2) +
v2*v4*(y2 - y4) + v1*v4*(-y1 + y4)))))))/(-((u1*u4*(v2*x2 -
v3*x3)*(x1 - x4) + u3*u4*(v1*x1 - v2*x2)*(x3 - x4) - u1*u3*(x1 -
x3)*(v2*x2 - v4*x4) + u2*(-(u4*(v1*x1 - v3*x3)*(x2 - x4)) + u3*(x2 -
x3)*(v1*x1 - v4*x4) + u1*(x1 - x2)*(v3*x3 -
v4*x4)))*(v1*x1*(-(u1*v2*x1*x2) - u3*v1*x1*x3 + u1*v3*x1*x3 +
u3*v2*x2*x3 + u2*x2*(v1*x1 - v3*x3))*(-(v3*(-x1 + x3)*(v1*(u4*(-v1 +
v2) + u2*(v1 - v4) + u1*(-v2 + v4))*(u1*(-v2 + v3)*y1 + u2*(v1 -
v3)*y2 + u3*(-v1 + v2)*y3) - u1*(u4*(v1 - v2) + u1*(v2 - v4) +
u2*(-v1 + v4))*(v1*v2*(y1 - y2) + v2*v3*(y2 - y3) + v1*v3*(-y1 + y3))
- v1*(u3*(-v1 + v2) + u2*(v1 - v3) + u1*(-v2 + v3))*(u1*(-v2 + v4)*y1
+ u2*(v1 - v4)*y2 + u4*(-v1 + v2)*y4) + u1*(u3*(v1 - v2) + u1*(v2 -
v3) + u2*(-v1 + v3))*(v1*v2*(y1 - y2) + v2*v4*(y2 - y4) + v1*v4*(-y1
+ y4)))) + (u3*v1 - u1*v3)*x3*((u4*(v1 - v2) + u1*(v2 - v4) + u2*(-v1
+ v4))*(v1*v2*(y1 - y2) + v2*v3*(y2 - y3) + v1*v3*(-y1 + y3)) +
(u3*(-v1 + v2) + u2*(v1 - v3) + u1*(-v2 + v3))*(v1*v2*(y1 - y2) +
v2*v4*(y2 - y4) + v1*v4*(-y1 + y4)))) - (u2*v1*v3*x2*(x1 - x3) +
u3*v1*v2*(-x1 + x2)*x3 + u1*v2*v3*x1*(-x2 + x3))*(-(x1*(-(v1*x1) +
v3*x3)*(v1*(u4*(-v1 + v2) + u2*(v1 - v4) + u1*(-v2 + v4))*(u1*(-v2 +
v3)*y1 + u2*(v1 - v3)*y2 + u3*(-v1 + v2)*y3) - u1*(u4*(v1 - v2) +
u1*(v2 - v4) + u2*(-v1 + v4))*(v1*v2*(y1 - y2) + v2*v3*(y2 - y3) +
v1*v3*(-y1 + y3)) - v1*(u3*(-v1 + v2) + u2*(v1 - v3) + u1*(-v2 +
v3))*(u1*(-v2 + v4)*y1 + u2*(v1 - v4)*y2 + u4*(-v1 + v2)*y4) +
u1*(u3*(v1 - v2) + u1*(v2 - v3) + u2*(-v1 + v3))*(v1*v2*(y1 - y2) +
v2*v4*(y2 - y4) + v1*v4*(-y1 + y4)))) + (u3*v1 -
u1*v3)*x1*x3*((u4*(v1 - v2) + u1*(v2 - v4) + u2*(-v1 +
v4))*(v1*v2*(y1 - y2) + v2*v3*(y2 - y3) + v1*v3*(-y1 + y3)) +
(u3*(-v1 + v2) + u2*(v1 - v3) + u1*(-v2 + v3))*(v1*v2*(y1 - y2) +
v2*v4*(y2 - y4) + v1*v4*(-y1 + y4)))))) + (-(u3*v1*v2*x1*x3) +
u3*v1*v4*x1*x3 + u3*v1*v2*x2*x3 - u3*v2*v4*x2*x3 + u4*v1*v2*x1*x4 -
u4*v1*v3*x1*x4 - u4*v1*v2*x2*x4 + u4*v2*v3*x2*x4 + u4*v1*v3*x3*x4 -
u4*v2*v3*x3*x4 - u3*v1*v4*x3*x4 + u3*v2*v4*x3*x4 + u2*x2*(v1*v3*(x1 -
x3) + v3*v4*(x3 - x4) + v1*v4*(-x1 + x4)) + u1*x1*(v2*v3*(-x2 + x3) +
v2*v4*(x2 - x4) + v3*v4*(-x3 + x4)))*(-((u2*u3*v1*x1*(x2 - x3) +
u1*u2*v3*(x1 - x2)*x3 + u1*u3*v2*x2*(-x1 + x3))*(-(x1*(-(v1*x1) +
v3*x3)*(v1*(u4*(-v1 + v2) + u2*(v1 - v4) + u1*(-v2 + v4))*(u1*(-v2 +
v3)*y1 + u2*(v1 - v3)*y2 + u3*(-v1 + v2)*y3) - u1*(u4*(v1 - v2) +
u1*(v2 - v4) + u2*(-v1 + v4))*(v1*v2*(y1 - y2) + v2*v3*(y2 - y3) +
v1*v3*(-y1 + y3)) - v1*(u3*(-v1 + v2) + u2*(v1 - v3) + u1*(-v2 +
v3))*(u1*(-v2 + v4)*y1 + u2*(v1 - v4)*y2 + u4*(-v1 + v2)*y4) +
u1*(u3*(v1 - v2) + u1*(v2 - v3) + u2*(-v1 + v3))*(v1*v2*(y1 - y2) +
v2*v4*(y2 - y4) + v1*v4*(-y1 + y4)))) + (u3*v1 -
u1*v3)*x1*x3*((u4*(v1 - v2) + u1*(v2 - v4) + u2*(-v1 +
v4))*(v1*v2*(y1 - y2) + v2*v3*(y2 - y3) + v1*v3*(-y1 + y3)) +
(u3*(-v1 + v2) + u2*(v1 - v3) + u1*(-v2 + v3))*(v1*v2*(y1 - y2) +
v2*v4*(y2 - y4) + v1*v4*(-y1 + y4))))) + (-(u1*v2*x1*x2) -
u3*v1*x1*x3 + u1*v3*x1*x3 + u3*v2*x2*x3 + u2*x2*(v1*x1 -
v3*x3))*(-(x1*(-(u3*v1*x1) + u1*v3*x3)*(v1*(u4*(-v1 + v2) + u2*(v1 -
v4) + u1*(-v2 + v4))*(u1*(-v2 + v3)*y1 + u2*(v1 - v3)*y2 + u3*(-v1 +
v2)*y3) - u1*(u4*(v1 - v2) + u1*(v2 - v4) + u2*(-v1 + v4))*(v1*v2*(y1
- y2) + v2*v3*(y2 - y3) + v1*v3*(-y1 + y3)) - v1*(u3*(-v1 + v2) +
u2*(v1 - v3) + u1*(-v2 + v3))*(u1*(-v2 + v4)*y1 + u2*(v1 - v4)*y2 +
u4*(-v1 + v2)*y4) + u1*(u3*(v1 - v2) + u1*(v2 - v3) + u2*(-v1 +
v3))*(v1*v2*(y1 - y2) + v2*v4*(y2 - y4) + v1*v4*(-y1 + y4)))) +
u1*(u3*v1 - u1*v3)*x1*x3*((u4*(v1 - v2) + u1*(v2 - v4) + u2*(-v1 +
v4))*(v1*v2*(y1 - y2) + v2*v3*(y2 - y3) + v1*v3*(-y1 + y3)) +
(u3*(-v1 + v2) + u2*(v1 - v3) + u1*(-v2 + v3))*(v1*v2*(y1 - y2) +
v2*v4*(y2 - y4) + v1*v4*(-y1 + y4))))));
double g = (-(v1*v3*x1*x2) +
v2*v3*x1*x2 + v1*v4*x1*x2 - v2*v4*x1*x2 + v1*v2*x1*x3 - v2*v3*x1*x3 -
v1*v4*x1*x3 + v3*v4*x1*x3 - v1*v2*x2*x3 + v1*v3*x2*x3 + v2*v4*x2*x3 -
v3*v4*x2*x3 - v1*v2*x1*x4 + v1*v3*x1*x4 + v2*v4*x1*x4 - v3*v4*x1*x4 +
v1*v2*x2*x4 - v2*v3*x2*x4 - v1*v4*x2*x4 + v3*v4*x2*x4 - v1*v3*x3*x4 +
v2*v3*x3*x4 + v1*v4*x3*x4 - v2*v4*x3*x4 + ((-(u2*v1*v3*x1) +
u2*v1*v4*x1 + u1*v2*v3*x2 - u1*v2*v4*x2 + u4*v1*v2*(-x1 + x2) +
u4*v1*v3*(x1 - x3) + u2*v1*v3*x3 - u1*v2*v3*x3 + u1*v3*v4*x3 -
u2*v3*v4*x3 + u4*v2*v3*(-x2 + x3) + u3*v2*v4*(x2 - x4) - u2*v1*v4*x4
+ u1*v2*v4*x4 - u1*v3*v4*x4 + u2*v3*v4*x4 + u3*v1*(v2*(x1 - x2) +
v4*(-x1 + x4)))*(-(v1*(v1 - v2)*(u3*v1 - u1*v3)*(u3*(v1 - v2) +
u1*(v2 - v3) + u2*(-v1 + v3))*(x1*x1)*x3*(-(u3*v1*v2*x1*x3) +
u3*v1*v4*x1*x3 + u3*v1*v2*x2*x3 - u3*v2*v4*x2*x3 + u4*v1*v2*x1*x4 -
u4*v1*v3*x1*x4 - u4*v1*v2*x2*x4 + u4*v2*v3*x2*x4 + u4*v1*v3*x3*x4 -
u4*v2*v3*x3*x4 - u3*v1*v4*x3*x4 + u3*v2*v4*x3*x4 + u2*x2*(v1*v3*(x1 -
x3) + v3*v4*(x3 - x4) + v1*v4*(-x1 + x4)) + u1*x1*(v2*v3*(-x2 + x3) +
v2*v4*(x2 - x4) + v3*v4*(-x3 + x4)))*(u2*v3*x2*x3*y1 - u2*v4*x2*x3*y1
- u1*v3*x1*x3*y2 + u1*v4*x1*x3*y2 - u2*v1*x1*x2*y3 + u1*v2*x1*x2*y3 -
u1*v4*x1*x2*y3 + u2*v4*x1*x2*y3 + u2*v1*x1*x2*y4 - u1*v2*x1*x2*y4 +
u1*v4*x1*x2*y4 - u2*v4*x1*x2*y4 + u1*v3*x1*x3*y4 - u1*v4*x1*x3*y4 -
u2*v3*x2*x3*y4 + u2*v4*x2*x3*y4 + u3*x3*(v1*x1*(y2 - y4) + v2*x2*(-y1
+ y4) + v4*(x2*y1 - x1*y2 + x1*y4 - x2*y4)) + u4*(v3*x3*(-(x2*y1) +
x1*y2 - x1*y4 + x2*y4) + v1*x1*(-(x3*y2) + x2*y3 - x2*y4 + x3*y4) +
v2*x2*(x3*(y1 - y4) + x1*(-y3 + y4))))) - (u1*v2*x1*x2*x3 -
u1*v3*x1*x2*x3 - u4*v1*x1*x2*x4 - u1*v2*x1*x2*x4 + u4*v2*x1*x2*x4 +
u1*v4*x1*x2*x4 + u4*v1*x1*x3*x4 + u1*v3*x1*x3*x4 - u4*v3*x1*x3*x4 -
u1*v4*x1*x3*x4 - u4*v2*x2*x3*x4 + u4*v3*x2*x3*x4 + u3*x3*(v1*x1*(x2 -
x4) + v4*(x1 - x2)*x4 + v2*x2*(-x1 + x4)) + u2*x2*(v3*x3*(x1 - x4) +
v4*(-x1 + x3)*x4 + v1*x1*(-x3 + x4)))*(v1*x1*(-(u1*v2*x1*x2) -
u3*v1*x1*x3 + u1*v3*x1*x3 + u3*v2*x2*x3 + u2*x2*(v1*x1 -
v3*x3))*(-(v3*(-x1 + x3)*(v1*(u4*(-v1 + v2) + u2*(v1 - v4) + u1*(-v2
+ v4))*(u1*(-v2 + v3)*y1 + u2*(v1 - v3)*y2 + u3*(-v1 + v2)*y3) -
u1*(u4*(v1 - v2) + u1*(v2 - v4) + u2*(-v1 + v4))*(v1*v2*(y1 - y2) +
v2*v3*(y2 - y3) + v1*v3*(-y1 + y3)) - v1*(u3*(-v1 + v2) + u2*(v1 -
v3) + u1*(-v2 + v3))*(u1*(-v2 + v4)*y1 + u2*(v1 - v4)*y2 + u4*(-v1 +
v2)*y4) + u1*(u3*(v1 - v2) + u1*(v2 - v3) + u2*(-v1 + v3))*(v1*v2*(y1
- y2) + v2*v4*(y2 - y4) + v1*v4*(-y1 + y4)))) + (u3*v1 -
u1*v3)*x3*((u4*(v1 - v2) + u1*(v2 - v4) + u2*(-v1 + v4))*(v1*v2*(y1 -
y2) + v2*v3*(y2 - y3) + v1*v3*(-y1 + y3)) + (u3*(-v1 + v2) + u2*(v1 -
v3) + u1*(-v2 + v3))*(v1*v2*(y1 - y2) + v2*v4*(y2 - y4) + v1*v4*(-y1
+ y4)))) - (u2*v1*v3*x2*(x1 - x3) + u3*v1*v2*(-x1 + x2)*x3 +
u1*v2*v3*x1*(-x2 + x3))*(-(x1*(-(v1*x1) + v3*x3)*(v1*(u4*(-v1 + v2) +
u2*(v1 - v4) + u1*(-v2 + v4))*(u1*(-v2 + v3)*y1 + u2*(v1 - v3)*y2 +
u3*(-v1 + v2)*y3) - u1*(u4*(v1 - v2) + u1*(v2 - v4) + u2*(-v1 +
v4))*(v1*v2*(y1 - y2) + v2*v3*(y2 - y3) + v1*v3*(-y1 + y3)) -
v1*(u3*(-v1 + v2) + u2*(v1 - v3) + u1*(-v2 + v3))*(u1*(-v2 + v4)*y1 +
u2*(v1 - v4)*y2 + u4*(-v1 + v2)*y4) + u1*(u3*(v1 - v2) + u1*(v2 - v3)
+ u2*(-v1 + v3))*(v1*v2*(y1 - y2) + v2*v4*(y2 - y4) + v1*v4*(-y1 +
y4)))) + (u3*v1 - u1*v3)*x1*x3*((u4*(v1 - v2) + u1*(v2 - v4) +
u2*(-v1 + v4))*(v1*v2*(y1 - y2) + v2*v3*(y2 - y3) + v1*v3*(-y1 + y3))
+ (u3*(-v1 + v2) + u2*(v1 - v3) + u1*(-v2 + v3))*(v1*v2*(y1 - y2) +
v2*v4*(y2 - y4) + v1*v4*(-y1 + y4)))))))/(-((u1*u4*(v2*x2 -
v3*x3)*(x1 - x4) + u3*u4*(v1*x1 - v2*x2)*(x3 - x4) - u1*u3*(x1 -
x3)*(v2*x2 - v4*x4) + u2*(-(u4*(v1*x1 - v3*x3)*(x2 - x4)) + u3*(x2 -
x3)*(v1*x1 - v4*x4) + u1*(x1 - x2)*(v3*x3 -
v4*x4)))*(v1*x1*(-(u1*v2*x1*x2) - u3*v1*x1*x3 + u1*v3*x1*x3 +
u3*v2*x2*x3 + u2*x2*(v1*x1 - v3*x3))*(-(v3*(-x1 + x3)*(v1*(u4*(-v1 +
v2) + u2*(v1 - v4) + u1*(-v2 + v4))*(u1*(-v2 + v3)*y1 + u2*(v1 -
v3)*y2 + u3*(-v1 + v2)*y3) - u1*(u4*(v1 - v2) + u1*(v2 - v4) +
u2*(-v1 + v4))*(v1*v2*(y1 - y2) + v2*v3*(y2 - y3) + v1*v3*(-y1 + y3))
- v1*(u3*(-v1 + v2) + u2*(v1 - v3) + u1*(-v2 + v3))*(u1*(-v2 + v4)*y1
+ u2*(v1 - v4)*y2 + u4*(-v1 + v2)*y4) + u1*(u3*(v1 - v2) + u1*(v2 -
v3) + u2*(-v1 + v3))*(v1*v2*(y1 - y2) + v2*v4*(y2 - y4) + v1*v4*(-y1
+ y4)))) + (u3*v1 - u1*v3)*x3*((u4*(v1 - v2) + u1*(v2 - v4) + u2*(-v1
+ v4))*(v1*v2*(y1 - y2) + v2*v3*(y2 - y3) + v1*v3*(-y1 + y3)) +
(u3*(-v1 + v2) + u2*(v1 - v3) + u1*(-v2 + v3))*(v1*v2*(y1 - y2) +
v2*v4*(y2 - y4) + v1*v4*(-y1 + y4)))) - (u2*v1*v3*x2*(x1 - x3) +
u3*v1*v2*(-x1 + x2)*x3 + u1*v2*v3*x1*(-x2 + x3))*(-(x1*(-(v1*x1) +
v3*x3)*(v1*(u4*(-v1 + v2) + u2*(v1 - v4) + u1*(-v2 + v4))*(u1*(-v2 +
v3)*y1 + u2*(v1 - v3)*y2 + u3*(-v1 + v2)*y3) - u1*(u4*(v1 - v2) +
u1*(v2 - v4) + u2*(-v1 + v4))*(v1*v2*(y1 - y2) + v2*v3*(y2 - y3) +
v1*v3*(-y1 + y3)) - v1*(u3*(-v1 + v2) + u2*(v1 - v3) + u1*(-v2 +
v3))*(u1*(-v2 + v4)*y1 + u2*(v1 - v4)*y2 + u4*(-v1 + v2)*y4) +
u1*(u3*(v1 - v2) + u1*(v2 - v3) + u2*(-v1 + v3))*(v1*v2*(y1 - y2) +
v2*v4*(y2 - y4) + v1*v4*(-y1 + y4)))) + (u3*v1 -
u1*v3)*x1*x3*((u4*(v1 - v2) + u1*(v2 - v4) + u2*(-v1 +
v4))*(v1*v2*(y1 - y2) + v2*v3*(y2 - y3) + v1*v3*(-y1 + y3)) +
(u3*(-v1 + v2) + u2*(v1 - v3) + u1*(-v2 + v3))*(v1*v2*(y1 - y2) +
v2*v4*(y2 - y4) + v1*v4*(-y1 + y4)))))) + (-(u3*v1*v2*x1*x3) +
u3*v1*v4*x1*x3 + u3*v1*v2*x2*x3 - u3*v2*v4*x2*x3 + u4*v1*v2*x1*x4 -
u4*v1*v3*x1*x4 - u4*v1*v2*x2*x4 + u4*v2*v3*x2*x4 + u4*v1*v3*x3*x4 -
u4*v2*v3*x3*x4 - u3*v1*v4*x3*x4 + u3*v2*v4*x3*x4 + u2*x2*(v1*v3*(x1 -
x3) + v3*v4*(x3 - x4) + v1*v4*(-x1 + x4)) + u1*x1*(v2*v3*(-x2 + x3) +
v2*v4*(x2 - x4) + v3*v4*(-x3 + x4)))*(-((u2*u3*v1*x1*(x2 - x3) +
u1*u2*v3*(x1 - x2)*x3 + u1*u3*v2*x2*(-x1 + x3))*(-(x1*(-(v1*x1) +
v3*x3)*(v1*(u4*(-v1 + v2) + u2*(v1 - v4) + u1*(-v2 + v4))*(u1*(-v2 +
v3)*y1 + u2*(v1 - v3)*y2 + u3*(-v1 + v2)*y3) - u1*(u4*(v1 - v2) +
u1*(v2 - v4) + u2*(-v1 + v4))*(v1*v2*(y1 - y2) + v2*v3*(y2 - y3) +
v1*v3*(-y1 + y3)) - v1*(u3*(-v1 + v2) + u2*(v1 - v3) + u1*(-v2 +
v3))*(u1*(-v2 + v4)*y1 + u2*(v1 - v4)*y2 + u4*(-v1 + v2)*y4) +
u1*(u3*(v1 - v2) + u1*(v2 - v3) + u2*(-v1 + v3))*(v1*v2*(y1 - y2) +
v2*v4*(y2 - y4) + v1*v4*(-y1 + y4)))) + (u3*v1 -
u1*v3)*x1*x3*((u4*(v1 - v2) + u1*(v2 - v4) + u2*(-v1 +
v4))*(v1*v2*(y1 - y2) + v2*v3*(y2 - y3) + v1*v3*(-y1 + y3)) +
(u3*(-v1 + v2) + u2*(v1 - v3) + u1*(-v2 + v3))*(v1*v2*(y1 - y2) +
v2*v4*(y2 - y4) + v1*v4*(-y1 + y4))))) + (-(u1*v2*x1*x2) -
u3*v1*x1*x3 + u1*v3*x1*x3 + u3*v2*x2*x3 + u2*x2*(v1*x1 -
v3*x3))*(-(x1*(-(u3*v1*x1) + u1*v3*x3)*(v1*(u4*(-v1 + v2) + u2*(v1 -
v4) + u1*(-v2 + v4))*(u1*(-v2 + v3)*y1 + u2*(v1 - v3)*y2 + u3*(-v1 +
v2)*y3) - u1*(u4*(v1 - v2) + u1*(v2 - v4) + u2*(-v1 + v4))*(v1*v2*(y1
- y2) + v2*v3*(y2 - y3) + v1*v3*(-y1 + y3)) - v1*(u3*(-v1 + v2) +
u2*(v1 - v3) + u1*(-v2 + v3))*(u1*(-v2 + v4)*y1 + u2*(v1 - v4)*y2 +
u4*(-v1 + v2)*y4) + u1*(u3*(v1 - v2) + u1*(v2 - v3) + u2*(-v1 +
v3))*(v1*v2*(y1 - y2) + v2*v4*(y2 - y4) + v1*v4*(-y1 + y4)))) +
u1*(u3*v1 - u1*v3)*x1*x3*((u4*(v1 - v2) + u1*(v2 - v4) + u2*(-v1 +
v4))*(v1*v2*(y1 - y2) + v2*v3*(y2 - y3) + v1*v3*(-y1 + y3)) +
(u3*(-v1 + v2) + u2*(v1 - v3) + u1*(-v2 + v3))*(v1*v2*(y1 - y2) +
v2*v4*(y2 - y4) + v1*v4*(-y1 + y4)))))))/(-(u3*v1*v2*x1*x3) +
u3*v1*v4*x1*x3 + u3*v1*v2*x2*x3 - u3*v2*v4*x2*x3 + u4*v1*v2*x1*x4 -
u4*v1*v3*x1*x4 - u4*v1*v2*x2*x4 + u4*v2*v3*x2*x4 + u4*v1*v3*x3*x4 -
u4*v2*v3*x3*x4 - u3*v1*v4*x3*x4 + u3*v2*v4*x3*x4 + u2*x2*(v1*v3*(x1 -
x3) + v3*v4*(x3 - x4) + v1*v4*(-x1 + x4)) + u1*x1*(v2*v3*(-x2 + x3) +
v2*v4*(x2 - x4) + v3*v4*(-x3 + x4)));
double h = (-(u1*v3*x1*x2) +
u2*v3*x1*x2 + u1*v4*x1*x2 - u2*v4*x1*x2 + u1*v2*x1*x3 - u3*v2*x1*x3 -
u1*v4*x1*x3 + u3*v4*x1*x3 - u2*v1*x2*x3 + u3*v1*x2*x3 + u2*v4*x2*x3 -
u3*v4*x2*x3 - u1*v2*x1*x4 + u4*v2*x1*x4 + u1*v3*x1*x4 - u4*v3*x1*x4 +
u2*v1*x2*x4 - u4*v1*x2*x4 - u2*v3*x2*x4 + u4*v3*x2*x4 - u3*v1*x3*x4 +
u4*v1*x3*x4 + u3*v2*x3*x4 - u4*v2*x3*x4 + ((-(u2*u3*(v1 - v4)*(x2 -
x3)) + u1*(-(u2*(v3 - v4)*(x1 - x2)) + u3*(v2 - v4)*(x1 - x3) -
u4*(v2 - v3)*(x1 - x4)) + u2*u4*(v1 - v3)*(x2 - x4) - u3*u4*(v1 -
v2)*(x3 - x4))*(-(v1*(v1 - v2)*(u3*v1 - u1*v3)*(u3*(v1 - v2) + u1*(v2
- v3) + u2*(-v1 + v3))*(x1*x1)*x3*(-(u3*v1*v2*x1*x3) + u3*v1*v4*x1*x3 +
u3*v1*v2*x2*x3 - u3*v2*v4*x2*x3 + u4*v1*v2*x1*x4 - u4*v1*v3*x1*x4 -
u4*v1*v2*x2*x4 + u4*v2*v3*x2*x4 + u4*v1*v3*x3*x4 - u4*v2*v3*x3*x4 -
u3*v1*v4*x3*x4 + u3*v2*v4*x3*x4 + u2*x2*(v1*v3*(x1 - x3) + v3*v4*(x3
- x4) + v1*v4*(-x1 + x4)) + u1*x1*(v2*v3*(-x2 + x3) + v2*v4*(x2 - x4)
+ v3*v4*(-x3 + x4)))*(u2*v3*x2*x3*y1 - u2*v4*x2*x3*y1 -
u1*v3*x1*x3*y2 + u1*v4*x1*x3*y2 - u2*v1*x1*x2*y3 + u1*v2*x1*x2*y3 -
u1*v4*x1*x2*y3 + u2*v4*x1*x2*y3 + u2*v1*x1*x2*y4 - u1*v2*x1*x2*y4 +
u1*v4*x1*x2*y4 - u2*v4*x1*x2*y4 + u1*v3*x1*x3*y4 - u1*v4*x1*x3*y4 -
u2*v3*x2*x3*y4 + u2*v4*x2*x3*y4 + u3*x3*(v1*x1*(y2 - y4) + v2*x2*(-y1
+ y4) + v4*(x2*y1 - x1*y2 + x1*y4 - x2*y4)) + u4*(v3*x3*(-(x2*y1) +
x1*y2 - x1*y4 + x2*y4) + v1*x1*(-(x3*y2) + x2*y3 - x2*y4 + x3*y4) +
v2*x2*(x3*(y1 - y4) + x1*(-y3 + y4))))) - (u1*v2*x1*x2*x3 -
u1*v3*x1*x2*x3 - u4*v1*x1*x2*x4 - u1*v2*x1*x2*x4 + u4*v2*x1*x2*x4 +
u1*v4*x1*x2*x4 + u4*v1*x1*x3*x4 + u1*v3*x1*x3*x4 - u4*v3*x1*x3*x4 -
u1*v4*x1*x3*x4 - u4*v2*x2*x3*x4 + u4*v3*x2*x3*x4 + u3*x3*(v1*x1*(x2 -
x4) + v4*(x1 - x2)*x4 + v2*x2*(-x1 + x4)) + u2*x2*(v3*x3*(x1 - x4) +
v4*(-x1 + x3)*x4 + v1*x1*(-x3 + x4)))*(v1*x1*(-(u1*v2*x1*x2) -
u3*v1*x1*x3 + u1*v3*x1*x3 + u3*v2*x2*x3 + u2*x2*(v1*x1 -
v3*x3))*(-(v3*(-x1 + x3)*(v1*(u4*(-v1 + v2) + u2*(v1 - v4) + u1*(-v2
+ v4))*(u1*(-v2 + v3)*y1 + u2*(v1 - v3)*y2 + u3*(-v1 + v2)*y3) -
u1*(u4*(v1 - v2) + u1*(v2 - v4) + u2*(-v1 + v4))*(v1*v2*(y1 - y2) +
v2*v3*(y2 - y3) + v1*v3*(-y1 + y3)) - v1*(u3*(-v1 + v2) + u2*(v1 -
v3) + u1*(-v2 + v3))*(u1*(-v2 + v4)*y1 + u2*(v1 - v4)*y2 + u4*(-v1 +
v2)*y4) + u1*(u3*(v1 - v2) + u1*(v2 - v3) + u2*(-v1 + v3))*(v1*v2*(y1
- y2) + v2*v4*(y2 - y4) + v1*v4*(-y1 + y4)))) + (u3*v1 -
u1*v3)*x3*((u4*(v1 - v2) + u1*(v2 - v4) + u2*(-v1 + v4))*(v1*v2*(y1 -
y2) + v2*v3*(y2 - y3) + v1*v3*(-y1 + y3)) + (u3*(-v1 + v2) + u2*(v1 -
v3) + u1*(-v2 + v3))*(v1*v2*(y1 - y2) + v2*v4*(y2 - y4) + v1*v4*(-y1
+ y4)))) - (u2*v1*v3*x2*(x1 - x3) + u3*v1*v2*(-x1 + x2)*x3 +
u1*v2*v3*x1*(-x2 + x3))*(-(x1*(-(v1*x1) + v3*x3)*(v1*(u4*(-v1 + v2) +
u2*(v1 - v4) + u1*(-v2 + v4))*(u1*(-v2 + v3)*y1 + u2*(v1 - v3)*y2 +
u3*(-v1 + v2)*y3) - u1*(u4*(v1 - v2) + u1*(v2 - v4) + u2*(-v1 +
v4))*(v1*v2*(y1 - y2) + v2*v3*(y2 - y3) + v1*v3*(-y1 + y3)) -
v1*(u3*(-v1 + v2) + u2*(v1 - v3) + u1*(-v2 + v3))*(u1*(-v2 + v4)*y1 +
u2*(v1 - v4)*y2 + u4*(-v1 + v2)*y4) + u1*(u3*(v1 - v2) + u1*(v2 - v3)
+ u2*(-v1 + v3))*(v1*v2*(y1 - y2) + v2*v4*(y2 - y4) + v1*v4*(-y1 +
y4)))) + (u3*v1 - u1*v3)*x1*x3*((u4*(v1 - v2) + u1*(v2 - v4) +
u2*(-v1 + v4))*(v1*v2*(y1 - y2) + v2*v3*(y2 - y3) + v1*v3*(-y1 + y3))
+ (u3*(-v1 + v2) + u2*(v1 - v3) + u1*(-v2 + v3))*(v1*v2*(y1 - y2) +
v2*v4*(y2 - y4) + v1*v4*(-y1 + y4)))))))/(-((u1*u4*(v2*x2 -
v3*x3)*(x1 - x4) + u3*u4*(v1*x1 - v2*x2)*(x3 - x4) - u1*u3*(x1 -
x3)*(v2*x2 - v4*x4) + u2*(-(u4*(v1*x1 - v3*x3)*(x2 - x4)) + u3*(x2 -
x3)*(v1*x1 - v4*x4) + u1*(x1 - x2)*(v3*x3 -
v4*x4)))*(v1*x1*(-(u1*v2*x1*x2) - u3*v1*x1*x3 + u1*v3*x1*x3 +
u3*v2*x2*x3 + u2*x2*(v1*x1 - v3*x3))*(-(v3*(-x1 + x3)*(v1*(u4*(-v1 +
v2) + u2*(v1 - v4) + u1*(-v2 + v4))*(u1*(-v2 + v3)*y1 + u2*(v1 -
v3)*y2 + u3*(-v1 + v2)*y3) - u1*(u4*(v1 - v2) + u1*(v2 - v4) +
u2*(-v1 + v4))*(v1*v2*(y1 - y2) + v2*v3*(y2 - y3) + v1*v3*(-y1 + y3))
- v1*(u3*(-v1 + v2) + u2*(v1 - v3) + u1*(-v2 + v3))*(u1*(-v2 + v4)*y1
+ u2*(v1 - v4)*y2 + u4*(-v1 + v2)*y4) + u1*(u3*(v1 - v2) + u1*(v2 -
v3) + u2*(-v1 + v3))*(v1*v2*(y1 - y2) + v2*v4*(y2 - y4) + v1*v4*(-y1
+ y4)))) + (u3*v1 - u1*v3)*x3*((u4*(v1 - v2) + u1*(v2 - v4) + u2*(-v1
+ v4))*(v1*v2*(y1 - y2) + v2*v3*(y2 - y3) + v1*v3*(-y1 + y3)) +
(u3*(-v1 + v2) + u2*(v1 - v3) + u1*(-v2 + v3))*(v1*v2*(y1 - y2) +
v2*v4*(y2 - y4) + v1*v4*(-y1 + y4)))) - (u2*v1*v3*x2*(x1 - x3) +
u3*v1*v2*(-x1 + x2)*x3 + u1*v2*v3*x1*(-x2 + x3))*(-(x1*(-(v1*x1) +
v3*x3)*(v1*(u4*(-v1 + v2) + u2*(v1 - v4) + u1*(-v2 + v4))*(u1*(-v2 +
v3)*y1 + u2*(v1 - v3)*y2 + u3*(-v1 + v2)*y3) - u1*(u4*(v1 - v2) +
u1*(v2 - v4) + u2*(-v1 + v4))*(v1*v2*(y1 - y2) + v2*v3*(y2 - y3) +
v1*v3*(-y1 + y3)) - v1*(u3*(-v1 + v2) + u2*(v1 - v3) + u1*(-v2 +
v3))*(u1*(-v2 + v4)*y1 + u2*(v1 - v4)*y2 + u4*(-v1 + v2)*y4) +
u1*(u3*(v1 - v2) + u1*(v2 - v3) + u2*(-v1 + v3))*(v1*v2*(y1 - y2) +
v2*v4*(y2 - y4) + v1*v4*(-y1 + y4)))) + (u3*v1 -
u1*v3)*x1*x3*((u4*(v1 - v2) + u1*(v2 - v4) + u2*(-v1 +
v4))*(v1*v2*(y1 - y2) + v2*v3*(y2 - y3) + v1*v3*(-y1 + y3)) +
(u3*(-v1 + v2) + u2*(v1 - v3) + u1*(-v2 + v3))*(v1*v2*(y1 - y2) +
v2*v4*(y2 - y4) + v1*v4*(-y1 + y4)))))) + (-(u3*v1*v2*x1*x3) +
u3*v1*v4*x1*x3 + u3*v1*v2*x2*x3 - u3*v2*v4*x2*x3 + u4*v1*v2*x1*x4 -
u4*v1*v3*x1*x4 - u4*v1*v2*x2*x4 + u4*v2*v3*x2*x4 + u4*v1*v3*x3*x4 -
u4*v2*v3*x3*x4 - u3*v1*v4*x3*x4 + u3*v2*v4*x3*x4 + u2*x2*(v1*v3*(x1 -
x3) + v3*v4*(x3 - x4) + v1*v4*(-x1 + x4)) + u1*x1*(v2*v3*(-x2 + x3) +
v2*v4*(x2 - x4) + v3*v4*(-x3 + x4)))*(-((u2*u3*v1*x1*(x2 - x3) +
u1*u2*v3*(x1 - x2)*x3 + u1*u3*v2*x2*(-x1 + x3))*(-(x1*(-(v1*x1) +
v3*x3)*(v1*(u4*(-v1 + v2) + u2*(v1 - v4) + u1*(-v2 + v4))*(u1*(-v2 +
v3)*y1 + u2*(v1 - v3)*y2 + u3*(-v1 + v2)*y3) - u1*(u4*(v1 - v2) +
u1*(v2 - v4) + u2*(-v1 + v4))*(v1*v2*(y1 - y2) + v2*v3*(y2 - y3) +
v1*v3*(-y1 + y3)) - v1*(u3*(-v1 + v2) + u2*(v1 - v3) + u1*(-v2 +
v3))*(u1*(-v2 + v4)*y1 + u2*(v1 - v4)*y2 + u4*(-v1 + v2)*y4) +
u1*(u3*(v1 - v2) + u1*(v2 - v3) + u2*(-v1 + v3))*(v1*v2*(y1 - y2) +
v2*v4*(y2 - y4) + v1*v4*(-y1 + y4)))) + (u3*v1 -
u1*v3)*x1*x3*((u4*(v1 - v2) + u1*(v2 - v4) + u2*(-v1 +
v4))*(v1*v2*(y1 - y2) + v2*v3*(y2 - y3) + v1*v3*(-y1 + y3)) +
(u3*(-v1 + v2) + u2*(v1 - v3) + u1*(-v2 + v3))*(v1*v2*(y1 - y2) +
v2*v4*(y2 - y4) + v1*v4*(-y1 + y4))))) + (-(u1*v2*x1*x2) -
u3*v1*x1*x3 + u1*v3*x1*x3 + u3*v2*x2*x3 + u2*x2*(v1*x1 -
v3*x3))*(-(x1*(-(u3*v1*x1) + u1*v3*x3)*(v1*(u4*(-v1 + v2) + u2*(v1 -
v4) + u1*(-v2 + v4))*(u1*(-v2 + v3)*y1 + u2*(v1 - v3)*y2 + u3*(-v1 +
v2)*y3) - u1*(u4*(v1 - v2) + u1*(v2 - v4) + u2*(-v1 + v4))*(v1*v2*(y1
- y2) + v2*v3*(y2 - y3) + v1*v3*(-y1 + y3)) - v1*(u3*(-v1 + v2) +
u2*(v1 - v3) + u1*(-v2 + v3))*(u1*(-v2 + v4)*y1 + u2*(v1 - v4)*y2 +
u4*(-v1 + v2)*y4) + u1*(u3*(v1 - v2) + u1*(v2 - v3) + u2*(-v1 +
v3))*(v1*v2*(y1 - y2) + v2*v4*(y2 - y4) + v1*v4*(-y1 + y4)))) +
u1*(u3*v1 - u1*v3)*x1*x3*((u4*(v1 - v2) + u1*(v2 - v4) + u2*(-v1 +
v4))*(v1*v2*(y1 - y2) + v2*v3*(y2 - y3) + v1*v3*(-y1 + y3)) +
(u3*(-v1 + v2) + u2*(v1 - v3) + u1*(-v2 + v3))*(v1*v2*(y1 - y2) +
v2*v4*(y2 - y4) + v1*v4*(-y1 + y4)))))))/(u3*v1*v2*x1*x3 -
u3*v1*v4*x1*x3 - u3*v1*v2*x2*x3 + u3*v2*v4*x2*x3 - u4*v1*v2*x1*x4 +
u4*v1*v3*x1*x4 + u4*v1*v2*x2*x4 - u4*v2*v3*x2*x4 - u4*v1*v3*x3*x4 +
u4*v2*v3*x3*x4 + u3*v1*v4*x3*x4 - u3*v2*v4*x3*x4 + u1*x1*(v2*v3*(x2 -
x3) + v3*v4*(x3 - x4) + v2*v4*(-x2 + x4)) + u2*x2*(v1*v3*(-x1 + x3) +
v1*v4*(x1 - x4) + v3*v4*(-x3 + x4)));
return new float[]{(float)a,(float)b,(float)c,(float)d,(float)e,(float)f,(float)g,(float)h};
}
float[] applyHMatrix(float[] H, float u, float v){
float x = H[0] * u + H[1] * v + H[2];
float y = H[3] * u + H[4] * v + H[5];
float z = H[6] * u + H[7] * v + 1;
return new float[]{x/z,y/z};
}
boolean pointInQuad(float x,float y,float ax,float ay,float bx,float by,float cx,float cy,float dx,float dy){
float[] uv = cart2bary(x,y,ax,ay,bx,by,cx,cy);
if (uv[0] < 0 || uv[1] < 0 || (1-uv[0]-uv[1]) < 0){
uv = cart2bary(x,y,ax,ay,dx,dy,cx,cy);
if (uv[0] < 0 || uv[1] < 0 || (1-uv[0]-uv[1]) < 0){
return false;
}
}
return true;
}
void warpHomographic(PImage src, PImage dst,
float ax0, float ay0, float bx0, float by0, float cx0, float cy0, float dx0, float dy0,
float ax1, float ay1, float bx1, float by1, float cx1, float cy1, float dx1, float dy1
){
src.loadPixels();
dst.loadPixels();
float[] H = computeHMatrix(
ax0,ay0,bx0,by0,cx0,cy0,dx0,dy0,
ax1,ay1,bx1,by1,cx1,cy1,dx1,dy1
);
int[] roi = quadRoi(ax1,ay1,bx1,by1,cx1,cy1,dx1,dy1);
for (int i = roi[1]; i <= roi[3]; i++){
if (i < 0 || i > dst.height) continue;
for (int j = roi[0]; j <= roi[2]; j++){
if (j < 0 || j > dst.width) continue;
if (!pointInQuad(j,i,ax1,ay1,bx1,by1,cx1,cy1,dx1,dy1)) continue;
float[] xy = applyHMatrix(H, j, i);
int val = sampler(src,xy[0],xy[1]);
dst.pixels[i*dst.width+j] = val;
}
}
dst.updatePixels();
}
//Sweep (Biangular) method -----------------------------------------------
float[] lineIntersect(float p0x, float p0y, float p1x, float p1y, float q0x, float q0y, float q1x, float q1y){
float d0x = ((p1x) - (p0x));
float d0y = ((p1y) - (p0y));
float d1x = ((q1x) - (q0x));
float d1y = ((q1y) - (q0y));
float vc = ((((d0x) * (d1y))) - (((d0y) * (d1x))));
if ((vc) == (0)) {
return null;
}
float vcn = ((vc) * (vc));
float t = ((((((((((q0x) - (p0x))) * (d1y))) * (vc))) - (((((((q0y) - (p0y))) * (d1x))) * (vc))))) / (vcn));
return new float[]{p0x + t * d0x, p0y + t * d0y};
}
float pointDistanceToLine(float x, float y, float x1, float y1, float x2, float y2) {
float A = x - x1;
float B = y - y1;
float C = x2 - x1;
float D = y2 - y1;
float dot = A*C+B*D;
float len_sq = C*C+D*D;
float param = -1;
if (len_sq != 0) {
param = dot / len_sq;
}
float xx, yy;
xx = x1 + param*C;
yy = y1 + param*D;
float dx = x - xx;
float dy = y - yy;
return sqrt(dx*dx+dy*dy);
}
float vecAngle(float ux, float uy, float vx, float vy){
float dot = ux * vx + uy * vy;
float nu = sqrt(ux*ux+uy*uy);
float nv = sqrt(vx*vx+vy*vy);
float cs = dot/(nu*nv);
return acos(cs);
}
float[] vecRot(float x, float y,float th){
return new float[]{x*cos(th)-y*sin(th),x*sin(th)+y*cos(th)};
}
float cart2sweep(
float x,float y,
float ax,float ay,
float dx,float dy,
float ang,
float D,
float[]isect){
if (isect == null){
return pointDistanceToLine(x,y,ax,ay,dx,dy)/D;
}
float vx = x-isect[0];
float vy = y-isect[1];
float A = vecAngle(dx-isect[0],dy-isect[1],vx,vy);
return A/ang;
}
float[] sweep2cart(
float u, float v,
float ax, float ay, float bx, float by,
float cx, float cy, float dx, float dy,
float angV,float angH,
float[] isectV, float[] isectH
){
float l0x, l0y, l1x, l1y;
float m0x, m0y, m1x, m1y;
if (isectV != null){
float dax = dx-ax;
float day = dy-ay;
float au = u*angV;
float[] urxy = vecRot(dax,day,au);
l0x = isectV[0];
l0y = isectV[1];
l1x = l0x+urxy[0];
l1y = l0y+urxy[1];
}else{
l0x = ax * (1-u) + bx * u;
l0y = ay * (1-u) + by * u;
l1x = dx * (1-u) + cx * u;
l1y = dy * (1-u) + cy * u;
}
if (isectH != null){
float bax = bx-ax;
float bay = by-ay;
float av = v*angH;
float[] vrxy = vecRot(bax,bay,av);
m0x = isectH[0];
m0y = isectH[1];
m1x = m0x+vrxy[0];
m1y = m0y+vrxy[1];
}else{
m0x = ax * (1-v) + dx * v;
m0y = ay * (1-v) + dy * v;
m1x = bx * (1-v) + cx * v;
m1y = by * (1-v) + cy * v;
}
return lineIntersect(l0x,l0y,l1x,l1y,m0x,m0y,m1x,m1y);
}
void warpSweep(PImage src, PImage dst,
float ax0, float ay0, float bx0, float by0, float cx0, float cy0, float dx0, float dy0,
float ax1, float ay1, float bx1, float by1, float cx1, float cy1, float dx1, float dy1
){
src.loadPixels();
dst.loadPixels();
float[] isectV0 = lineIntersect(ax0,ay0,dx0,dy0, bx0,by0,cx0,cy0);
float[] isectH0 = lineIntersect(ax0,ay0,bx0,by0, dx0,dy0,cx0,cy0);
float[] isectV1 = lineIntersect(ax1,ay1,dx1,dy1, bx1,by1,cx1,cy1);
float[] isectH1 = lineIntersect(ax1,ay1,bx1,by1, dx1,dy1,cx1,cy1);
float d1_tb=0, d1_lr=0;
if (isectV1 == null) d1_lr = pointDistanceToLine(ax1,ay1,bx1,by1,cx1,cy1);
if (isectH1 == null) d1_tb = pointDistanceToLine(ax1,ay1,dx1,dy1,cx1,cy1);
float angV0=0, angH0=0, angV1=0, angH1=0;
if (isectV0 != null) angV0 = vecAngle(dx0-isectV0[0],dy0-isectV0[1], cx0-isectV0[0],cy0-isectV0[1]);
if (isectH0 != null) angH0 = vecAngle(ax0-isectH0[0],ay0-isectH0[1], dx0-isectH0[0],dy0-isectH0[1]);
if (isectV1 != null) angV1 = vecAngle(dx1-isectV1[0],dy1-isectV1[1], cx1-isectV1[0],cy1-isectV1[1]);
if (isectH1 != null) angH1 = vecAngle(ax1-isectH1[0],ay1-isectH1[1], dx1-isectH1[0],dy1-isectH1[1]);
int[] roi = quadRoi(ax1,ay1,bx1,by1,cx1,cy1,dx1,dy1);
for (int i = roi[1]; i <= roi[3]; i++){
if (i < 0 || i > dst.height) continue;
for (int j = roi[0]; j <= roi[2]; j++){
if (j < 0 || j > dst.width) continue;
if (!pointInQuad(j,i,ax1,ay1,bx1,by1,cx1,cy1,dx1,dy1)) continue;
float u = cart2sweep(j,i,ax1,ay1,dx1,dy1,angV1,d1_lr,isectV1);
float v = cart2sweep(j,i,bx1,by1,ax1,ay1,angH1,d1_tb,isectH1);
float[] xy = sweep2cart(u,v,ax0,ay0,bx0,by0,cx0,cy0,dx0,dy0,angV0,angH0,isectV0,isectH0);
int val = sampler(src,xy[0],xy[1]);
dst.pixels[i*dst.width+j] = val;
}
}
dst.updatePixels();
}
//Runner -----------------------------------------------
PImage src;
PImage dst;
void setup(){
size(1024,512);
src = loadImage("boat.png"); // https://homepages.cae.wisc.edu/~ece533/images/boat.png
dst = createImage(src.width,src.height,RGB);
}
void draw(){
dst.loadPixels();for(int i=0;i<dst.pixels.length;i++)dst.pixels[i]=0;dst.updatePixels();
float ax0 = 50;
float ay0 = 50;
float bx0 = 300;
float by0 = 50;
float cx0 = 300;
float cy0 = 300;
float dx0 = 80;
float dy0 = 300;
float ax1 = 20;
float ay1 = 100;
float bx1 = 400;
float by1 = 100;
float cx1 = mouseX-512;
float cy1 = mouseY;
float dx1 = 100;
float dy1 = 400;
switch (method){
case HOMOGRAPHIC:
warpHomographic(src,dst,
ax0,ay0,bx0,by0,cx0,cy0,dx0,dy0,
ax1,ay1,bx1,by1,cx1,cy1,dx1,dy1
);break;
case BILINEAR:
warpQuadcentric(src,dst,
ax0,ay0,bx0,by0,cx0,cy0,dx0,dy0,
ax1,ay1,bx1,by1,cx1,cy1,dx1,dy1
);break;
case BIANGULAR:
warpSweep(src,dst,
ax0,ay0,bx0,by0,cx0,cy0,dx0,dy0,
ax1,ay1,bx1,by1,cx1,cy1,dx1,dy1
);break;
case BARYCENTRIC:
warpBarycentric(src,dst,
ax0,ay0,bx0,by0,cx0,cy0,dx0,dy0,
ax1,ay1,bx1,by1,cx1,cy1,dx1,dy1
);break;
}
noFill();
stroke(255,255,0);
strokeWeight(2);
image(src,0,0);
quad(ax0,ay0,bx0,by0,cx0,cy0,dx0,dy0);
circle(ax0,ay0,6);
circle(bx0,by0,6);
circle(cx0,cy0,6);
circle(dx0,dy0,6);
text("Move mouse to distort, Press a key to change method (currently "+method+")", 0,10);
translate(512,0);
image(dst,0,0);
quad(ax1,ay1,bx1,by1,cx1,cy1,dx1,dy1);
circle(ax1,ay1,6);
circle(bx1,by1,6);
circle(cx1,cy1,6);
circle(dx1,dy1,6);
}
void keyPressed(){
method = (method + 1) % 4;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment