import java.awt.*; import java.awt.event.*; import java.applet.*; import java.awt.geom.*; import java.math.*; /**This is the interval arithmetic version of the class Separation.java. That class defines the separation functions from the paper. These are lower and upper bounds on the distance between pairs of points in two spherical patches. We have to be careful that our boxes do not cross the coordinate axes. So, we eliminate the initial boxes.**/ public class IntervalSeparation { /**The lower bound on distance**/ public static Interval psiMin(IntervalBox B1,IntervalBox B2) { Interval bound=new Interval(0.0); if(B1.type==2) bound=perfectLowerBound(B2,B1); if(B2.type==2) bound=perfectLowerBound(B1,B2); if(bound.l>0) return(bound); return(lowerBound(B1,B2)); } /**The upper bound on distance**/ public static Interval psiMax(IntervalBox B1,IntervalBox B2) { Interval bound=new Interval(2.0); if((B1.k==-2)||(B2.k==-2)) return(bound); if(B1.type==2) bound=perfectUpperBound(B2,B1); if(B2.type==2) bound=perfectUpperBound(B1,B2); if(bound.r<2) return(bound); return(upperBound(B1,B2)); } /**The general purpose upper bound from the paper**/ public static Interval upperBound(IntervalBox B1,IntervalBox B2) { Interval D=DVAL(B1,B2); Interval d=delta(B1,B2); Interval ONE=new Interval(1.0); Interval d1=Interval.minus(ONE,Interval.times(Interval.times(d,d),new Interval(0.5))); Interval D1=new Interval(); if(D.r>=2) D1=new Interval(0.0); if(D.r<2) D1=Interval.sqrtUpperBound(Interval.minus(new Interval(4.0),Interval.times(D,D))); Interval s=Interval.plus(D,Interval.times(D1,d)); if(s.l>2) return(new Interval(2.0)); return(s); } /**The general purpose lower bound from the paper.**/ public static Interval lowerBound(IntervalBox B1,IntervalBox B2) { Interval D=DVAL(B1,B2); Interval d=delta(B1,B2); Interval ONE=new Interval(1.0); Interval d1=Interval.minus(ONE,Interval.times(Interval.times(d,d),new Interval(0.5))); Interval D1=new Interval(); if(D.r>=2) D1=new Interval(0.0); if(D.r<2) D1=Interval.sqrtUpperBound(Interval.minus(new Interval(4.0),Interval.times(D,D))); Interval s=Interval.minus(Interval.times(D,d1),Interval.times(D1,d)); if(s.r<0) return(new Interval(0.0)); return(s); } /**Estimate on the average radius of the caps containing the spherical patches**/ public static Interval delta(IntervalBox B1,IntervalBox B2) { Interval x1=Interval.times(B1.delta(),B1.tau()); Interval x2=Interval.times(B2.delta(),B2.tau()); Interval x=Interval.plus(x1,x2); x=Interval.times(x,new Interval(.25,.25)); return(x); } /**Distance between the inverse stereo images of the box centers.**/ public static Interval DVAL(IntervalBox B1,IntervalBox B2) { IntervalVector V1=B1.getCenter(); IntervalVector V2=B2.getCenter(); return(IntervalVector.dist(V1,V2)); } /**The sharp upper bound, used only in case the second box is the point at infinity.*/ public static Interval perfectLowerBound(IntervalBox B1,IntervalBox B2) { if(B1.k<-1) return(new Interval(0.0)); if(B2.k<-1) return(new Interval(0.0)); IntervalVector[] V1=B1.toVectors(); IntervalVector[] V2=B2.toVectors(); double min=2; Interval test=new Interval(0.0); for(int i=0;itest.l) min=test.l; } } return(new Interval(min)); } public static Interval perfectUpperBound(IntervalBox B1,IntervalBox B2) { if(B1.k<-1) return(new Interval(0.0)); if(B2.k<-1) return(new Interval(0.0)); IntervalVector[] V1=B1.toVectors(); IntervalVector[] V2=B2.toVectors(); double max=0; Interval test=new Interval(0.0); for(int i=0;i