import java.applet.Applet; import java.awt.event.*; import java.awt.*; import java.awt.geom.*; public class PolyWedgeLong { Complex[] z=new Complex[100]; int count; public PolyWedgeLong() {} public PolyWedgeLong(int cc,Complex[] zz) { this.count=cc; for(int i=1;i<=cc;++i) z[i]=new Complex(zz[i]); } public GeneralPath toGeneralPath() { GeneralPath gp=new GeneralPath(); gp.moveTo((float)(z[1].x),(float)(z[1].y)); for(int i=1;i<=count;++i) { gp.lineTo((float)(z[i].x),(float)(z[i].y)); } gp.closePath(); return(gp); } /*this routine finds the lowest point of a polygon. if there are more than one of these points, the routine picks the last one.*/ public static int extreme(Complex u,PolyWedgeLong P) { double test,min; int X; min=10000.0; X=0; Complex v; for(int i=1;i<=P.count;++i) { v=Complex.times(u,P.z[i]); test=v.y; if(testtest) { min=test; X=i; } } } return(X); } /*this routine rotates a polygon so that the edge determined by the indices a and b is horizontal*/ public static PolyWedgeLong roll(PolyWedgeLong P,int a,int b) { int i; Complex w=new Complex(); PolyWedgeLong Q=new PolyWedgeLong(); w=Complex.minus(P.z[b],P.z[a]); w=Complex.unit(w); for(i=1;i<=P.count;++i) { Q.z[i]=Complex.divide(P.z[i],w); } Q.count=P.count; return(Q); } public static PolyWedgeLong convexHull(PolyWedgeLong P) { PolyWedgeLong Q=new PolyWedgeLong(); int[] n=new int[100]; int match; int ct; for(int i=1;i<=P.count;++i) Q.z[i]=new Complex(P.z[i]); Q.count=P.count; n[1]=bottom(Q); match=0; ct=1; while(match==0) { n[ct+1]=nextPoint(Q,n[ct]); if(n[ct+1]==n[1]) match=1; if(ct>P.count) match=1; if(n[ct+1]==0) match=1; Q=roll(Q,n[ct],n[ct+1]); ++ct; } for(int i=1;i<=ct;++i) Q.z[i]=P.z[n[i]]; Q.count=ct; return(Q); } }