import java.applet.Applet; import java.awt.event.*; import java.awt.*; /**This class does some basic spherical geometry. It isn't used directly in the proofs, but is used in some of the sanity checks for the proofs.**/ public class XtraVector { /**norm**/ public static double norm(Vector V) { return(Math.sqrt(Vector.dot(V,V))); } /**cross product **/ public static Vector cross(Vector v,Vector w) { Vector X=new Vector(); X.x[0]=v.x[1]*w.x[2]-w.x[1]*v.x[2]; X.x[1]=v.x[2]*w.x[0]-w.x[2]*v.x[0]; X.x[2]=v.x[0]*w.x[1]-w.x[0]*v.x[1]; return(X); } /**In these routines we find the intersection between the lines X1+s U1 and X2 + s U2. The routine only works when the lines actually intersect. The first routine is the final one.**/ public static Vector findIntersection(Vector X1,Vector U1,Vector X2,Vector U2) { int q=bestDeterminant(U1,U2); return(findIntersection(q,X1,U1,X2,U2)); } public static int bestDeterminant(Vector U1,Vector U2) { Vector X=cross(U1,U2); int index=-1; double max=0; for(int i=0;i<3;++i) { double test=Math.abs(X.x[i]); if(maxd[2]) { double temp=d[2]; d[2]=d[1]; d[1]=temp; } d[1]=d[1]/d[0]; d[2]=d[2]/d[0]; d[3]=Vector.dist(V1,V2)/d[0]; d[1]=Math.sqrt(d[1]*d[1]-1); d[2]=Math.sqrt(d[2]*d[2]-1); return(d); } public static double[] positionData2(Vector W,Vector V1,Vector V2) { Vector V=average(V1,V2); double r=Vector.dist(V,W); double s=Vector.dist(V1,V2); double[] d={r,s}; return(d); } public static Vector scale(double d,Vector v) { Vector x=new Vector(); for(int i=0;i<3;++i) x.x[i]=d*v.x[i]; return(x); } public static Vector average(Vector v,Vector w) { Vector x=new Vector(); for(int i=0;i<3;++i) x.x[i]=.5*(v.x[i]+w.x[i]); return(x); } /**project to unit sphere**/ public static Vector unitSphere(Vector W) { Vector V=new Vector(W.x[0],W.x[1],W.x[2]); double d=Math.sqrt(Vector.dot(V,V)); V.x[0]=V.x[0]/d; V.x[1]=V.x[1]/d; V.x[2]=V.x[2]/d; return(V); } /**Apply to W the isometric reflection that swaps V1 and V2**/ public static Vector swap(Vector V1,Vector V2,Vector W) { Vector[] X=new Vector[10]; X[0]=Vector.plus(V1,V2); X[0]=unitSphere(X[0]); X[1]=cross(V1,V2); X[1]=unitSphere(X[1]); X[2]=cross(X[0],X[1]); double d=2*Vector.dot(W,X[2]); X[3]=scale(d,X[2]); X[4]=Vector.minus(W,X[3]); return(X[4]); } }