


    /**This draws pictures associated to sect 21.1 in the monograph.
       This has to do with Part II of the Hexagrid Theorem.*/

    public void drawHexImage(Graphics2D g,Output OUT) {
      GeneralPath gp=new GeneralPath();
      int val=M.C.CON_P.PEC.IS[0].val;

      /*This is a little complication in the drawing.  Whether we
        use the polyhedron R1 or R2 depends on which of the
        fibers we are considering.*/
        if((val==1)&&(offset>2*A)) val=2;
        if((val==2)&&(offset<2*A)) val=1;

      /*Here is another little complication.  We only use the
        piece R4 for half the fibers.*/
        if((val==4)&&(offset>2*A)) val=-1;

      if(val>=0) {

	  gp=slice1(P);

      }

      if(M.C.EXPORT.mode==1) OUT.polyWrite(gp,Color.white,Color.white);

      gp=transform(gp);
      g.setColor(new Color(0,0,255,50));
      g.fill(gp);
      g.setColor(Color.white);    
      g.draw(gp);
      }





    public void drawFloorImage(Graphics2D g,Output OUT) {
      GeneralPath gp=new GeneralPath();
      AffineTransform AA=new AffineTransform();
      Polytope P0=new Polytope();
      Polytope P=new Polytope();

          int choice=M.C.CON_P.PEC.IS[0].val;
	  int shift=M.C.CON_P.PEC.SHIFT.mode;
	  if(shift==3) AA=AffineTransform.getTranslateInstance(2+A,1);
	  if(shift==1) AA=AffineTransform.getTranslateInstance(1,1);
	  if(shift==2) AA=AffineTransform.getTranslateInstance(-1,-1);
	  if(shift==0) AA=AffineTransform.getTranslateInstance(0,0);

	  //the positive case
	  if(choice>3)  AA=AffineTransform.getTranslateInstance(0,0);

	  if(M.C.CON_P.PEC.FLOOR.mode==1) {
	     P0=PL.Q[choice];
	     for(int i=-3;i<=3;++i) {
	       for(int j=-3;j<=3;++j) {
	          for(int k=-3;k<=3;++k) {
		      P=Polytope.gamma(i,j,k,P0);

	          gp=slice1(P);
	          gp.transform(AA);
                  if(M.C.EXPORT.mode==1) OUT.polyWrite(gp,Color.white,Color.white);
	          gp=transform(gp);
                  g.setColor(Color.white);
                  g.fill(gp);  
	          g.draw(gp);
		  }
	       }
	     }
	  }
    }




    //taking a 3 dimensional slice

    public double[] sliceProject0(double A,int i,int j) {
	double t0=this.V[i].x[3];
	double t1=this.V[j].x[3];
	double det=t0-t1;
	if(Math.abs(det)<.000001) return(null);
	double r=(A-t1)/(t0-t1);
	if(r<0.000001) return(null);
	if(r>0.999999) return(null);
	double[] p=new double[3];
	for(int q=0;q<3;++q) {
	   p[q]=r*this.V[i].x[q]+(1-r)*this.V[j].x[q];
	}
	return(p);
    }


    public static Complex project(double[] p,int p1,int p2) {
	double d1=p[0]*p2-p[1]*p1;
	Complex z=new Complex(d1,p[2]);
	return(z);
    }





    public Complex[] sliceProject1(double A,int p1,int p2) {
	GeneralPath gp=new GeneralPath();
	int fred=0;
	double[] p=new double[2];
	Complex[] zz=new Complex[100];
	int number=0;

	for(int i=0;i<count;++i) {
	    for(int j=i+1;j<count;++j) {
		    p=sliceProject0(A,i,j);
		    if(p!=null) {
			++number;
			zz[number]=project(p,p1,p2);
		    }
	    }
	}
	zz[0]=new Complex(number,0);
	return(zz);
    }



    public GeneralPath sliceProject(double A,int p1,int p2) {
	GeneralPath gp=new GeneralPath();
	Complex[] zz=sliceProject1(A,p1,p2);
	if(zz[0].x>0) {
	   PolyWedgeLong P=new PolyWedgeLong((int)(zz[0].x),zz);
	   P=PolyWedgeLong.cheapHull(P);
	   gp=P.toGeneralPath();
	}
	return(gp);
    }




