import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.awt.geom.*;
import java.math.*;
public class Polytope {
int count;
Vector4[] V=new Vector4[20];
int[] type=new int[4];
public Polytope() {}
public Polytope(Polytope P) {
count=P.count;
for(int i=0;i
0.9999999) return(null);
if(s<0.0000001) return(null);
if(s>0.9999999) return(null);
if(r+s>.9999999) return(null);
Complex p=new Complex();
x0=V[2].dot(V[2],P.V[i]);
y0=V[3].dot(V[3],P.V[i]);
x1=V[2].dot(V[2],P.V[j]);
y1=V[3].dot(V[3],P.V[j]);
x2=V[2].dot(V[2],P.V[k]);
y2=V[3].dot(V[3],P.V[k]);
p.x=r*x0+s*x1+(1-r-s)*x2;
p.y=r*y0+s*y1+(1-r-s)*y2;
return(p);
}
public static Complex[] planarSlice1(Vector4[] V,double x,double y,Polytope P) {
GeneralPath gp=new GeneralPath();
int fred=0;
Complex p;
Complex[] zz=new Complex[100];
int number=0;
for(int i=0;i0) {
PolyWedgeLong LP=new PolyWedgeLong(n,zz);
LP=PolyWedgeLong.cheapHull(LP);
gp=LP.toGeneralPath();
}
return(gp);
}
public GeneralPath slice0(double x,double y) {
Vector4[] V=new Vector4[4];
V[0]=new Vector4(0,0,1,0);
V[1]=new Vector4(0,0,0,1);
V[2]=new Vector4(1,0,0,0);
V[3]=new Vector4(0,1,0,0);
return(planarSlice(V,x,y,this));
}
//for hexagrid theorem 1
public GeneralPath slice1(double y,double A) {
Vector4[] V=new Vector4[4];
V[0]=new Vector4(0,1,-1,0);
V[1]=new Vector4(0,0,0,1);
V[2]=new Vector4(1,0,0,0);
V[3]=new Vector4(0,0,1,0);
return(planarSlice(V,y+.00001,A+.00001,this));
}
//for hexagrid theorem 2
public GeneralPath slice2(double x,double y) {
Vector4[] V=new Vector4[4];
V[0]=new Vector4(1,1,0,0);
V[1]=new Vector4(0,0,0,1);
V[2]=new Vector4(1,0,0,0);
V[3]=new Vector4(0,0,1,0);
return(planarSlice(V,x+.00001,y,this));
}
public void print(Output OUT) {
OUT.write("SLASHlefteqn{"); //start equation
for(int i=0;i0) {
V=new Vector4(i1,i2,i3,i4);
test=testDisjoint0(V,P1,P2);
if(test==1) return(1);
}
}
}
}
}
return(0);
}
//return of 1 means disjoint
public static int testDisjoint0(Vector4 V,Polytope P1,Polytope P2) {
double min1,max1,min2,max2;
min1=10000;
min2=10000;
max1=-10000;
max2=-10000;
double test=0;
for(int i=0;itest) min1=test;
if(max1test) min2=test;
if(max2=max2) good=1;
if(min2>=max1) good=1;
if(good==1) {
return(1);
}
return(0);
}
/**This routine counts the number of vertices in the hyperplane normal to the vector
(1,1,0,-1). This is the hyperplane Pi in part III of the book. if the polytope
actually intersects the hyperplane, the return is -1. Also, if the polytope
lies on the negative side of Pi then the return is -1. By this we mean that
v0+v1-v3<=0 for all vertices*/
public static int countHyperplaneIntersect(Polytope P) {
Polytope Q=hyperplaneIntersect(P);
if(Q!=null) return(Q.count);
return(0);
}
public static Polytope hyperplaneIntersect(Polytope P) {
int count=0;
double test=0;
int neg=0;
int pos=0;
Vector4[] TEMP=new Vector4[10];
for(int i=0;i.00001) pos=1;
if(test<-.00001) neg=1;
}
if(neg==1) return(null);
if(count==0) return(null);
Polytope Q=new Polytope();
Q.count=count;
for(int i=0;i