import java.awt.Graphics;
import java.applet.Applet;
import java.awt.Color;

//Takashi OHYAMA
//Make 2009/6/8
//Update 2010/6/27 Add comments.
//^       2011/3/14 Add comments. 
public class segvoro extends java.applet.Applet{
    double gpi;
    Color gcol1,gcol2,gcol3,gcol4,gcol5,gcol6,gcol7;
    int N,gtaka,ghaba;
    int i,j,k;
    String NS,ghabaS,gtakaS;
    double Nd,gtakad,ghabad;
    double tmpw;
    int br;

    double gxs[]=new double[100];
    double gys[]=new double[100];
    double gxe[]=new double[100];
    double gye[]=new double[100];

    double gslope[]=new double[100];
    double gintercept[]=new double[100];

    double gx,gy;

    double grx1;
    double gry1;
    double grx2;
    double gry2;

    double gux1;
    double guy1;
    double gux2;
    double guy2;
    double gux3;
    double guy3;
    double gux4;
    double guy4;

    double gpboriginx;
    double gpboriginy;
    double gpbijsp;
    double gpbijstheta;
    double gpbijep;
    double gpbijetheta;

    public double dou(String dous){
        double dou1;
        dou1 = (Double.valueOf(dous)).doubleValue();
        return dou1;
    }//dou

    public double rand(){
        double rand1;
        rand1=Math.random();
        return rand1;
    }//rand

    public void init(){
        gcol1=Color.black;
        gcol2=Color.yellow;
        gcol3=Color.white;
        gcol4=Color.green;
        gcol5=Color.pink;
        gcol6=Color.magenta;
        gcol7=Color.cyan;

        //^html file input. gtakaS, ghabaS is set from html file
        //^haba is the width of Screen(Applet)
        //^taka is the height of Screen(Applet)
        gtakaS=getParameter("takap");
        ghabaS=getParameter("habap");
        NS=getParameter("Np");
        ghabad=dou(ghabaS);
        gtakad=dou(gtakaS);
        Nd=dou(NS);
        ghaba=(int)ghabad;
        gtaka=(int)gtakad;
        N=(int)Nd;
        if(N==20){
            N=2+(int)(14*rand());
        }
    }//init

    public double jou(double a,double b){
        double jou1;
        jou1=Math.pow(a,b);
        return jou1;
    }//jou

    public double dis(double x1,double y1,double x2,double y2){
        return jou(jou(x2-x1,2.0)+jou(y2-y1,2.0),0.5);
    }//dis

    //main function
    //main関数
    public void paint(java.awt.Graphics g){
        gpi=3.14159265358979323846263;//pi

        //s is start
        //e is end
        //l is left
        //r is right
        //s sometime is l
        //e sometime is r

        double slx;
        double sly;
        double srx;
        double sry;

        double elx;
        double ely;
        double erx;
        double ery;

        double selx;
        double sely;
        double serx;
        double sery;

        double eslx;
        double esly;
        double esrx;
        double esry;




        double dxs;
        double dxe;
        double dys;
        double dye;
        double dslope;
        double dintercept;
        double intersectionx;
        double minx;
        double maxx;
        double minx2;
        double maxx2;

        int xsI[]=new int[100];
        int ysI[]=new int[100];
        int xeI[]=new int[100];
        int yeI[]=new int[100];
        double s[]=new double[100];
        String sss[]=new String[100];


        //^Setting generators(Line segments)
        //^In this version, these line segments are set such that they don't cross each other.
        g.setColor(gcol1);
        g.fillRect(1,1,ghaba,gtaka);
        g.setColor(gcol3);
        g.drawString("N="+N,15,15);
        k=0;
        while(k<N){
            dxs=rand()*(ghaba-30)+15;
            dys=rand()*(gtaka-30)+15;
            dxe=rand()*(ghaba-30)+15;
            dye=rand()*(gtaka-30)+15;
            dslope=(dye-dys)/(dxe-dxs);
            dintercept=dys-dslope*dxs;
            minx=dxs;
            maxx=dxe;
            if(dxs>dxe){
                minx=dxe;
                maxx=dxs;
            }
            br=0;//^br is crossing flag. 0:Not Cross, so this segment can be generator segment.
                 //^                     1:Cross with other generators, so can not be generator.
            for(i=0;i<k;i++){
                minx2=gxs[i];
                maxx2=gxe[i];
                if(gxs[i]>gxe[i]){
                    minx2=gxe[i];
                    maxx2=gxs[i];
                }
                intersectionx=(dintercept-gintercept[i])/(gslope[i]-dslope);
                if(intersectionx>minx && intersectionx<maxx){
                    if(intersectionx>minx2 && intersectionx<maxx2){
                       br=1;
                    }
                }

            }

            if(br==0){
                gxs[k]=dxs;//^k's generator is defined (gxs[k],gys[k])-(gxe[k],gye[k])
                           //^g is global variables
                           //^x is x-coordinate, y is y-coordinate
                           //^s is start point, e is end point.
                gys[k]=dys;
                gxe[k]=dxe;
                gye[k]=dye;
                if(gxs[k]>gxe[k]){
                    tmpw=gxs[k];
                    gxs[k]=gxe[k];
                    gxe[k]=tmpw;
                    tmpw=gys[k];
                    gys[k]=gye[k];
                    gye[k]=tmpw;
                }
                xsI[k]=(int)(gxs[k]);
                ysI[k]=(int)(gys[k]);
                xeI[k]=(int)(gxe[k]);
                yeI[k]=(int)(gye[k]);
                g.setColor(gcol3);
                g.drawLine(xsI[k],ysI[k],xeI[k],yeI[k]);
                g.setColor(gcol2);
                g.drawString(""+k,(xsI[k]+xeI[k])/2,(ysI[k]+yeI[k])/2);
                gslope[k]=dslope;
                gintercept[k]=dintercept;
                k++;
            }//br==0
        }//while k<n

//^Main Logic
//^Consider N line segments.
//^i=1,...,N-1
//^    j=i+1,...,N
//^        Consider bisector of i and j
//^        i and j are line segments. So the bisector has three type below.
//^           1) the bisector of two edge points; perpendicular bisector of two edge points, y=ax+b 
//^           2) the bisector of two line segments; the bisector of an angles.
//^           3 the bisector of one edge point and one line segment; parabola line
//^        In this program, we compute these 3 bisectors, such that 1) y=slope*x+intercept for all x
//^                                                                 2) y=slope*x+intercept for all x
//^                                                                 3) y^2=4p*x for all x
//^                            check i and j is the nearest or not for (x,y)
//^                                   if yes, plot(x,y)
//^                                      no,  next x
//^        details;
//^        1) bisector of two edge points of line segments
//^        1-1) bisector of i's left vertex and j's left vertex
//^        1-2) bisector of i's right vertex and j's right vertex
//^        1-3) bisector of i's left vertex and j's right vertex
//^        1-4) bisector of i's right vertex and j's left vertex
//^        In these 4 cases, compute slope a and intercept b of perpendicular bisector of two edge points, y=ax+b 
//^        for x=left point of the screen to right point of screen
//^            compute y=ax+b
//^            compute d=distance between (x,y) and edge points(distance to i and distance to j are same)
//^            compute d_epsi=distance between (x,y) and edge point of i*0.999+j*0.001 (this means inner point of line segment) 
//^            compute d_epsj=distance between (x,y) and edge point of j*0.999+i*0.001 (this means inner point of line segment) 
//^            if d_epsj<d or d_epsi<d then next x
//^            for k=1,...,N but not i,j
//^                compute d_k=distance from (x,y) to k (that is edge points or intersection of perpendicular line from k)
//^                if d_k<d then next x
//^            next k
//^            plot (x,y)
//^        next x
//^
//^        2) Next, consider the bisector of two line segments, that is, the image is the bisector of an angles.
//^        There are two bisectors of an angles for line segments i and j.Compute these bisectors of an angles as (gux1,guy1)-(gux2,guy2) and (gux3,guy3)-(gux4,guy4)
//^        2-1) For (gux1,guy1)-(gux2,guy2)
//^        Compute a, b of y=ax+b for (gux1,guy1)-(gux2,guy2)
//^        for x=gux1 to gux2
//^            Compute y=ax+b
//^            Compute intersection of line segment i and perpendicular line from (x,y) to i.
//^            If the intersection is outside of line segment i, then next x
//^            Compute intersection of line segment j and perpendicular line from (x,y) to j.
//^            If the intersection is outside of line segment j, then next x
//^            Compute d, distance from (x,y) to i or j(to i and to j are same).
//^            For k=1,...,N but not i,j
//^                Compute d_k, distance from (x,y) to k.
//^                If d_k is less than d then next x
//^            next k
//^            plot (x,y)
//^        next x
//^        2-2) For (gux3,guy3)-(gux4,guy4). This is another bisector of an angle. 
//^        Use same logic of 2-1)
//^
//^        3) Finally, consider the bisector of one line segment and one edge point of another line segment
//^        3-1) line segment i and left point of segment j
//^        3-2) line segment i and right point of segment j
//^        3-3) line segment j and left point of segment i
//^        3-4) line segment j and right point of segment i
//^        For these 4 cases, apply following method.
//^        When the line (directrix) is x=-lp and the point (focus) is (lp,0) then the parabola line is y^2=4lpx.
//^        At first, lp is set to the half of distance between segment i and edge point of j.
//^        Rotate segment i and edge point of j by the angle of segment i, that is, make line segment i x=lp. Next, move segment i and edge point of j such that the middlepoint of segment i and edge point of j become origin point, (0,0). From these actions, we can draw y^2=4lpx for segment i and edge point of j.
//^        Later, rotate back and move back. then you can draw exact parabola.
//^        Compute (gpboriginx,gpboriginy). This is origin point for segment i and edge point of j for y^2=4lpx.
//^        Compute gpbijep. This is lp when bisector is y^2=4lpx for line segment i and edge point of j.
//^        Compute gpbijetheta. This is angle of rotation when bisector is y^2=4lpx for line segment i and edge point of j.
//^        for(y=-height of screen to height of screen
//^            compute x=y^2/(4lp)
//^            Rotate back (x,y) for segment i and edge point of j.
//^            compute d as distance from edge point j to (x,y).
//^            compute da as distance from another edge point j to (x,y).
//^            if da<d then next y
//^            compute deps as distance from edge point*0.999+another edge point*0.001 j to (x,y). This means inner point very small epsilon.
//^            if deps<d then next y
//^            for k=1,...,N but not i,j
//^                compute d_k as distance from k to (x,y).
//^                if d_k<d then next y
//^            next k
//^            Plot (x,y)
//^        next y
//^
//^    next j
//^next i




        for(i=0;i<N-1;i++){
            for(j=i+1;j<N;j++){

                //bisector of i's left vertex and j's left vertex  iの左側の端点とjの左側の端点で端点同士の垂直二等分線を計算します。
                bisec2poi(gxs[i],gys[i],gxs[j],gys[j]);
                slx=grx1;
                sly=gry1;
                srx=grx2;
                sry=gry2;
                g.setColor(Color.yellow);
//                g.drawLine((int)(slx),(int)(sly),(int)(srx),(int)(sry));
                double ldi;
                double lys;
                ldi=(sly-sry)/(slx-srx);
                lys=sly-ldi*slx;
                double lx;
                double ly;
//                for(lx=slx;lx<srx;lx=lx+0.5){
                double z1;
                double z1start;
                double z1end;
                z1start=slx;
                z1end=srx;
                if(Math.abs(ldi)>1.0){
                    if(ldi>1.0){
                        z1start=slx*ldi+lys;
                        z1end=srx*ldi+lys;
                    }else{
                        z1start=srx*ldi+lys;
                        z1end=slx*ldi+lys;
                    }
                }
                ldi=(sly-sry)/(slx-srx);
                for(z1=z1start;z1<z1end;z1=z1+0.5){
                    if(Math.abs(ldi)<1.0){
                        lx=z1;
                        ly=lx*ldi+lys;
                    }else{
                        ly=z1;
                        lx=(ly-lys)/ldi;
                    }
                    int cnt;
                    cnt=0;
                    double disis;
                    double disiseps;
                    double disjseps;
                    disis=dis(lx,ly,gxs[i],gys[i]);
                    disiseps=dis(lx,ly,gxs[i]*0.999+gxe[i]*0.001,gys[i]*0.999+gye[i]*0.001);
                    disjseps=dis(lx,ly,gxs[j]*0.999+gxe[j]*0.001,gys[j]*0.999+gye[j]*0.001);
                    if(disiseps<disis){
                        cnt++;
                    }
                    if(disjseps<disis){
                        cnt++;
                    }
                    if(cnt==0){
                        if(cntorder(i,j,lx,ly,disis)==0){
                            g.drawLine((int)(lx),(int)(ly),(int)(lx),(int)(ly));
                        }
                    }
                }//lx

                //bisector of i's right vertex and j's right vertex  iの右側の端点とjの右側の端点で端点同士の垂直二等分線を計算します。
                bisec2poi(gxe[i],gye[i],gxe[j],gye[j]);
                elx=grx1;
                ely=gry1;
                erx=grx2;
                ery=gry2;
                g.setColor(gcol5);
//                g.drawLine((int)(elx),(int)(ely),(int)(erx),(int)(ery));
                ldi=(ely-ery)/(elx-erx);
                lys=ely-ldi*elx;
//                for(lx=elx;lx<erx;lx=lx+0.5){
                z1start=elx;
                z1end=erx;
                if(Math.abs(ldi)>1.0){
                    if(ldi>1.0){
                        z1start=elx*ldi+lys;
                        z1end=erx*ldi+lys;
                    }else{
                        z1start=erx*ldi+lys;
                        z1end=elx*ldi+lys;
                    }
                }
                elx=grx1;
                ely=gry1;
                erx=grx2;
                ery=gry2;
                ldi=(ely-ery)/(elx-erx);
                for(z1=z1start;z1<z1end;z1=z1+0.5){
                    if(Math.abs(ldi)<1.0){
                        lx=z1;
                        ly=lx*ldi+lys;
                    }else{
                        ly=z1;
                        lx=(ly-lys)/ldi;
                    }
//                    ly=lx*ldi+lys;
                    int cnt;
                    cnt=0;
                    double disie;
                    double disieeps;
                    double disjeeps;
                    disie=dis(lx,ly,gxe[i],gye[i]);
                    disieeps=dis(lx,ly,gxe[i]*0.999+gxs[i]*0.001,gye[i]*0.999+gys[i]*0.001);
                    disjeeps=dis(lx,ly,gxe[j]*0.999+gxs[j]*0.001,gye[j]*0.999+gys[j]*0.001);
                    if(disieeps<disie){
                        cnt++;
                    }
                    if(disjeeps<disie){
                        cnt++;
                    }
                    if(cnt==0){
                        if(cntorder(i,j,lx,ly,disie)==0){
                            g.drawLine((int)(lx),(int)(ly),(int)(lx),(int)(ly));
                        }
                    }
                }//lx

                //bisector of i's left vertex and j's right vertex iの左側の端点とjの右側の端点で端点同士の垂直二等分線を計算します。
                bisec2poi(gxs[i],gys[i],gxe[j],gye[j]);
                selx=grx1;
                sely=gry1;
                serx=grx2;
                sery=gry2;
                g.setColor(Color.yellow);
//                g.drawLine((int)(selx),(int)(sely),(int)(serx),(int)(sery));
                ldi=(sely-sery)/(selx-serx);
                lys=sely-ldi*selx;
//                for(lx=selx;lx<serx;lx=lx+0.5){
                z1start=selx;
                z1end=serx;
                if(Math.abs(ldi)>1.0){
                    if(ldi>1.0){
                        z1start=selx*ldi+lys;
                        z1end=serx*ldi+lys;
                    }else{
                        z1start=serx*ldi+lys;
                        z1end=selx*ldi+lys;
                    }
                }
                selx=grx1;
                sely=gry1;
                serx=grx2;
                sery=gry2;
                ldi=(sely-sery)/(selx-serx);
                for(z1=z1start;z1<z1end;z1=z1+0.5){
                    if(Math.abs(ldi)<1.0){
                        lx=z1;
                        ly=lx*ldi+lys;
                    }else{
                        ly=z1;
                        lx=(ly-lys)/ldi;
                    }
//                    ly=lx*ldi+lys;
                    int cnt;
                    cnt=0;
                    double disis;
                    double disiseps;
                    double disjeeps;
                    disis=dis(lx,ly,gxs[i],gys[i]);
                    disiseps=dis(lx,ly,gxs[i]*0.999+gxe[i]*0.001,gys[i]*0.999+gye[i]*0.001);
                    disjeeps=dis(lx,ly,gxe[j]*0.999+gxs[j]*0.001,gye[j]*0.999+gys[j]*0.001);
                    if(disiseps<disis){
                        cnt++;
                    }
                    if(disjeeps<disis){
                        cnt++;
                    }
                    if(cnt==0){
                        if(cntorder(i,j,lx,ly,disis)==0){
                            g.drawLine((int)(lx),(int)(ly),(int)(lx),(int)(ly));
                        }
                    }
                }//lx

                //bisector of i's right vertex and j's left vertex iの右側の端点とjの左側の端点で端点同士の垂直二等分線を計算します。
                bisec2poi(gxe[i],gye[i],gxs[j],gys[j]);
                eslx=grx1;
                esly=gry1;
                esrx=grx2;
                esry=gry2;
                g.setColor(Color.white);
//                g.drawLine((int)(eslx),(int)(esly),(int)(esrx),(int)(esry));
                ldi=(esly-esry)/(eslx-esrx);
                lys=esly-ldi*eslx;
//                for(lx=eslx;lx<esrx;lx=lx+0.5){
                z1start=eslx;
                z1end=esrx;
                if(Math.abs(ldi)>1.0){
                    if(ldi>1.0){
                        z1start=eslx*ldi+lys;
                        z1end=esrx*ldi+lys;
                    }else{
                        z1start=esrx*ldi+lys;
                        z1end=eslx*ldi+lys;
                    }
                }
                eslx=grx1;
                esly=gry1;
                esrx=grx2;
                esry=gry2;
                ldi=(esly-esry)/(eslx-esrx);
                for(z1=z1start;z1<z1end;z1=z1+0.5){
                    if(Math.abs(ldi)<1.0){
                        lx=z1;
                        ly=lx*ldi+lys;
                    }else{
                        ly=z1;
                        lx=(ly-lys)/ldi;
                    }
//                    ly=lx*ldi+lys;
                    int cnt;
                    cnt=0;
                    double disie;
                    double disieeps;
                    double disjseps;
                    disie=dis(lx,ly,gxe[i],gye[i]);
                    disieeps=dis(lx,ly,gxe[i]*0.999+gxs[i]*0.001,gye[i]*0.999+gys[i]*0.001);
                    disjseps=dis(lx,ly,gxs[j]*0.999+gxe[j]*0.001,gys[j]*0.999+gye[j]*0.001);
                    if(disieeps<disie){
                        cnt++;
                    }
                    if(disjseps<disie){
                        cnt++;
                    }
                    if(cnt==0){
                        if(cntorder(i,j,lx,ly,disie)==0){
                            g.drawLine((int)(lx),(int)(ly),(int)(lx),(int)(ly));
                        }
                    }
                }//lx


                //bisector of two line segments  i,jの線分に囲まれた領域を考える。雰囲気的には角の二等分線
                bisec2seg(i,j);
                double lsegcsx1;
                double lsegcsy1;
                double lsegcex1;
                double lsegcey1;
                double lsegcsx2;
                double lsegcsy2;
                double lsegcex2;
                double lsegcey2;
                lsegcsx1=gux1;
                lsegcsy1=guy1;
                lsegcex1=gux2;
                lsegcey1=guy2;
                g.setColor(gcol3);
//                g.drawOval((int)(gx)-3,(int)(gy)-3,6,6);
//                g.drawLine((int)(lsegcsx1),(int)(lsegcsy1),(int)(lsegcex1),(int)(lsegcey1));
                ldi=(lsegcsy1-lsegcey1)/(lsegcsx1-lsegcex1);//slope of (gux1,guy1)-(gux2,guy2)　(gux1,guy1)-(gux2,guy2)の傾き
                lys=lsegcsy1-ldi*lsegcsx1;//intercept of (gux1,guy1)-(gux2,guy2)　(gux1,guy1)-(gux2,guy2)のy切片
//                for(lx=lsegcsx1;lx<lsegcex1;lx=lx+0.5){
                //if abs(slope)<1 then for x=right of screen to left of screen, abs(slope)>=1 then for y=bottom of screen to top of screen
                //if 傾きが１より小さければ for x=画面の左端 to 画面の右端, 傾きが１より大きければ for y=画面の下端 to 画面の上端
                z1start=lsegcsx1;
                z1end=lsegcex1;
                if(Math.abs(ldi)>1.0){
                    if(ldi>1.0){
                        z1start=lsegcsx1*ldi+lys;
                        z1end=lsegcex1*ldi+lys;
                    }else{
                        z1start=lsegcex1*ldi+lys;
                        z1end=lsegcsx1*ldi+lys;
                    }
                }
                lsegcsx1=gux1;
                lsegcsy1=guy1;
                lsegcex1=gux2;
                lsegcey1=guy2;
                ldi=(lsegcsy1-lsegcey1)/(lsegcsx1-lsegcex1);
                for(z1=z1start;z1<z1end;z1=z1+0.5){
                    if(Math.abs(ldi)<1.0){
                        lx=z1;
                        ly=lx*ldi+lys;
                    }else{
                        ly=z1;
                        lx=(ly-lys)/ldi;
                    }
//                    ly=lx*ldi+lys;
                    int cnt;
                    cnt=0;
                    double dii;
                    double ysi;
                    double intersectionxi;

                    dii=-1.0/gslope[i];//slope, dii of perpendicular line from (lx,ly) to line segment i (lx,ly)から線分iへの垂線の傾き
                    ysi=ly-dii*lx;//intercept, ysi of perpendicular line from (lx,ly) to line segment i (lx,ly)から線分iへの垂線のy切片
                    intersectionxi=(ysi-gintercept[i])/(gslope[i]-dii);//x coordinate of intersection of perpendicular line from (lx,ly) to line segment i and line segment i  線分iと(lx,ly)からiへ下ろした垂線の交点のx座標
                    //if intersection is outside of line segment i then don't draw bisector
                    //交点が線分iの外側ならこの点が境界になることはない(cntを0以外の値にする)
                    if(intersectionxi<gxs[i] || intersectionxi>gxe[i]){
                        cnt++;
                    }//intersectionxi<gxs[i] or intersectionxi>gxe[i]
                        double dij;
                        double ysj;
                        double intersectionxj;
                        dij=-1.0/gslope[j];//slope, dij of perpendicular line from (lx,ly) to line segment j (lx,ly)から線分jへの垂線の傾き
                        ysj=ly-dij*lx;//intercept, ysj of perpendicular line from (lx,ly) to line segment j (lx,ly)から線分jへの垂線のy切片
                        intersectionxj=(ysj-gintercept[j])/(gslope[j]-dij);//x coordinate of intersection of perpendicular line from (lx,ly) to line segment j and line segment j  線分jと(lx,ly)からjへ下ろした垂線の交点のx座標
                        //if intersection is outside of line segment j then don't draw bisector
                        //交点が線分jの外側ならこの点が境界になることはない(cntを0以外の値にする)
                        if(intersectionxj<gxs[j] || intersectionxj>gxe[j]){
                            cnt++;
                        }
                    //cnt==0 means   perpendicular line from (lx,ly) to i crosses inside line segment i and perpendicular line from (lx,ly) to j crosses inside line segment j
                    //cnt==0とは・・・　(lx,ly)からiに下ろした垂線が線分iの内側にあり、(lx,ly)からjに下ろした垂線が線分jの内側にあるので、(lx,ly)は境界の候補です。
                    if(cnt==0){
                        double disijc;
                        disijc=Math.abs(gslope[i]*lx-ly+gintercept[i])/jou(jou(gslope[i],2.0)+1.0,0.5);//distance from (lx,ly) to segment i(same to sengemnt j)  (lx,ly)から線分iへの距離(jへの距離と同じです)
                        //compute distance to k. If distance to i is less than any other distance to k then plot (lx,ly) as bisector of i and j
                        //kへの距離と比較して、i,jより近いkがなければ(lx.ly)を境界線としてプロットする
                        if(cntorder(i,j,lx,ly,disijc)==0){
                            g.drawLine((int)(lx),(int)(ly),(int)(lx),(int)(ly));
                        }
                    }
                }//lx

                //(gux3,guy3)-(gux4,guy4) is another bisector of an angle. Following 60 lines is same (gux1,guy1)-(gux2,guy2)
                //(gux3,guy3)-(gux4,guy4)はiとjの角の二等分線のもう一方。次の60行は(gux1,guy1)-(gux2,guy2)と同じロジックです
                lsegcsx2=gux3;
                lsegcsy2=guy3;
                lsegcex2=gux4;
                lsegcey2=guy4;
//                g.drawLine((int)(lsegcsx2),(int)(lsegcsy2),(int)(lsegcex2),(int)(lsegcey2));
                ldi=(lsegcsy2-lsegcey2)/(lsegcsx2-lsegcex2);
                lys=lsegcsy2-ldi*lsegcsx2;
//                for(lx=lsegcsx2;lx<lsegcex2;lx=lx+0.5){
                z1start=lsegcsx2;
                z1end=lsegcex2;
                if(Math.abs(ldi)>1.0){
                    if(ldi>1.0){
                        z1start=lsegcsx2*ldi+lys;
                        z1end=lsegcex2*ldi+lys;
                    }else{
                        z1start=lsegcex2*ldi+lys;
                        z1end=lsegcsx2*ldi+lys;
                    }
                }
                lsegcsx2=gux3;
                lsegcsy2=guy3;
                lsegcex2=gux4;
                lsegcey2=guy4;
                ldi=(lsegcsy2-lsegcey2)/(lsegcsx2-lsegcex2);
                for(z1=z1start;z1<z1end;z1=z1+0.5){
                    if(Math.abs(ldi)<1.0){
                        lx=z1;
                        ly=lx*ldi+lys;
                    }else{
                        ly=z1;
                        lx=(ly-lys)/ldi;
                    }
//                    ly=lx*ldi+lys;
                    int cnt;
                    cnt=0;
                    double dii;
                    double ysi;
                    double intersectionxi;
                    dii=-1.0/gslope[i];
                    ysi=ly-dii*lx;
                    intersectionxi=(ysi-gintercept[i])/(gslope[i]-dii);
                    if(intersectionxi<gxs[i] || intersectionxi>gxe[i]){
                        cnt++;
                    }//intersectionxi<gxs[i] or intersectionxi>gxe[i]
                        double dij;
                        double ysj;
                        double intersectionxj;
                        dij=-1.0/gslope[j];
                        ysj=ly-dij*lx;
                        intersectionxj=(ysj-gintercept[j])/(gslope[j]-dij);
                        if(intersectionxj<gxs[j] || intersectionxj>gxe[j]){
                            cnt++;
                        }
                    if(cnt==0){
                        double disijc;
                        disijc=Math.abs(gslope[i]*lx-ly+gintercept[i])/jou(jou(gslope[i],2.0)+1.0,0.5);
                        if(cntorder(i,j,lx,ly,disijc)==0){
                            g.drawLine((int)(lx),(int)(ly),(int)(lx),(int)(ly));
                        }
                    }
                }//lx


        //Logically, following 4 lines, next j next i  for(i=) for(j=) can be able to deleted. But loops are very long, so javac command has errors. So I added these 4 lines.
        //理論的には以下の４行 next j next i for(i=) for(j=)は不要です。しかしループが長いので、コンパイルがエラーになってしまうので、この４行を追加しました。
            }//j
        }//i

        for(i=0;i<N-1;i++){
            for(j=i+1;j<N;j++){

                //bisector of segment and a point 線分と線分の端点による境界線すなわち、放物線を考えます
                //bisector is parabola arc.
                double lpboriginx;
                double lpboriginy;
                double x;
                double y;
                double xrmp;
                double yrmp;
                double xrmm;
                double yrmm;
                double ystart;
                double yend;

                double disjs;
                double disje;
                int cnt;

                double lpbijsp;
                double lpbijstheta;
                //parabola bisector of line segment i and left point of segment j 線分iと線分jの左端
                bisecsegpois(i,j);
                lpbijsp=gpbijsp;
                lpbijstheta=gpi-gpbijstheta;
                if(gxs[j]>gpboriginx){
                    lpbijstheta=gpi*2.0-gpbijstheta;
                }
                lpboriginx=gpboriginx;
                lpboriginy=gpboriginy;
                double yisrm;
                double yierm;
                yisrm=Math.sin(lpbijstheta)*(gxs[i]-lpboriginx)+Math.cos(lpbijstheta)*(gys[i]-lpboriginy);
                yierm=Math.sin(lpbijstheta)*(gxe[i]-lpboriginx)+Math.cos(lpbijstheta)*(gye[i]-lpboriginy);
                ystart=yisrm;
                yend=yierm;
                if(yisrm>yierm){
                    ystart=yierm;
                    yend=yisrm;
                }
                lpboriginx=gpboriginx;
                lpboriginy=gpboriginy;
                g.setColor(Color.green);
                for(y=ystart;y<yend;y=y+0.1){
                    x=jou(y,2.0)/(4.0*lpbijsp);
                    xrmp=lpboriginx+Math.cos(-lpbijstheta)*x-Math.sin(-lpbijstheta)*y;
                    yrmp=lpboriginy+Math.sin(-lpbijstheta)*x+Math.cos(-lpbijstheta)*y;
                    cnt=0;
                    disjs=dis(xrmp,yrmp,gxs[j],gys[j]);
                    disje=dis(xrmp,yrmp,gxe[j],gye[j]);
                    if(disje<disjs){
                        cnt++;
                    }else{
                        double disjseps;
                        disjseps=dis(xrmp,yrmp,gxs[j]*0.999+gxe[j]*0.001,gys[j]*0.999+gye[j]*0.001);
                        if(disjseps<disjs){
                            cnt++;
                        }
                    }
                    lpboriginx=gpboriginx;
                    lpboriginy=gpboriginy;
                    if(cnt==0){
                        if(cntorder(i,j,xrmp,yrmp,disjs)==0){
                            g.drawLine((int)(xrmp),(int)(yrmp),(int)(xrmp),(int)(yrmp));
                        }
                    }//cnt==0
                }//y

                double lpbijep;
                double lpbijetheta;
                //parabola bisector of line segment i and right point of segment j 線分iと線分jの右端
                bisecsegpoie(i,j);
                lpbijep=gpbijep;
                lpbijetheta=gpi-gpbijetheta;
                if(gxe[j]>gpboriginx){
                    lpbijetheta=gpi*2.0-gpbijetheta;
                }
                lpboriginx=gpboriginx;
                lpboriginy=gpboriginy;
                yisrm=Math.sin(lpbijetheta)*(gxs[i]-lpboriginx)+Math.cos(lpbijetheta)*(gys[i]-lpboriginy);
                yierm=Math.sin(lpbijetheta)*(gxe[i]-lpboriginx)+Math.cos(lpbijetheta)*(gye[i]-lpboriginy);
                ystart=yisrm;
                yend=yierm;
                if(yisrm>yierm){
                    ystart=yierm;
                    yend=yisrm;
                }
                lpboriginx=gpboriginx;
                lpboriginy=gpboriginy;
                g.setColor(Color.pink);
                for(y=ystart;y<yend;y=y+0.1){
                    x=jou(y,2.0)/(4.0*lpbijep);
                    xrmp=lpboriginx+Math.cos(-lpbijetheta)*x-Math.sin(-lpbijetheta)*y;
                    yrmp=lpboriginy+Math.sin(-lpbijetheta)*x+Math.cos(-lpbijetheta)*y;
                    cnt=0;
                    disjs=dis(xrmp,yrmp,gxe[j],gye[j]);
                    disje=dis(xrmp,yrmp,gxs[j],gys[j]);
                    if(disje<disjs){
                        cnt++;
                    }else{
                        double disjeeps;
                        disjeeps=dis(xrmp,yrmp,gxe[j]*0.999+gxs[j]*0.001,gye[j]*0.999+gys[j]*0.001);
                        if(disjeeps<disjs){
                            cnt++;
                        }
                    }
                    if(cnt==0){
                        if(cntorder(i,j,xrmp,yrmp,disjs)==0){
                            g.drawLine((int)(xrmp),(int)(yrmp),(int)(xrmp),(int)(yrmp));
                        }
                    }//cnt==0
                }//y

                double lpbjisp;
                double lpbjistheta;
                //parabola bisector of line segment j and left point of segment i　線分jと線分iの左端
                bisecsegpois(j,i);
                lpbjisp=gpbijsp;
                lpbjistheta=gpi-gpbijstheta;
                if(gxs[i]>gpboriginx){
                    lpbjistheta=gpi*2.0-gpbijstheta;
                }
                lpboriginx=gpboriginx;
                lpboriginy=gpboriginy;
                double yjsrm;
                double yjerm;
                yjsrm=Math.sin(lpbjistheta)*(gxs[j]-lpboriginx)+Math.cos(lpbjistheta)*(gys[j]-lpboriginy);
                yjerm=Math.sin(lpbjistheta)*(gxe[j]-lpboriginx)+Math.cos(lpbjistheta)*(gye[j]-lpboriginy);
                ystart=yjsrm;
                yend=yjerm;
                if(yjsrm>yjerm){
                    ystart=yjerm;
                    yend=yjsrm;
                }
                lpboriginx=gpboriginx;
                lpboriginy=gpboriginy;
                g.setColor(Color.cyan);
                for(y=ystart;y<yend;y=y+0.1){
                    x=jou(y,2.0)/(4.0*lpbjisp);
                    xrmp=lpboriginx+Math.cos(-lpbjistheta)*x-Math.sin(-lpbjistheta)*y;
                    yrmp=lpboriginy+Math.sin(-lpbjistheta)*x+Math.cos(-lpbjistheta)*y;
                    cnt=0;
                    disjs=dis(xrmp,yrmp,gxs[i],gys[i]);
                    disje=dis(xrmp,yrmp,gxe[i],gye[i]);
                    if(disje<disjs){
                        cnt++;
                    }else{
                        double disiseps;
                        disiseps=dis(xrmp,yrmp,gxs[i]*0.999+gxe[i]*0.001,gys[i]*0.999+gye[i]*0.001);
                        if(disiseps<disjs){
                            cnt++;
                        }
                    }
                    if(cnt==0){
                        if(cntorder(i,j,xrmp,yrmp,disjs)==0){
                            g.drawLine((int)(xrmp),(int)(yrmp),(int)(xrmp),(int)(yrmp));
                        }
                    }
                }//y

                double lpbjiep;
                double lpbjietheta;
                //parabola bisector of line segment j and right point of segment i　線分jと線分iの右端
                bisecsegpoie(j,i);
                lpbjiep=gpbijep;
                lpbjietheta=gpi-gpbijetheta;
                if(gxe[i]>gpboriginx){
                    lpbjietheta=gpi*2.0-gpbijetheta;
                }
                lpboriginx=gpboriginx;
                lpboriginy=gpboriginy;
                yjsrm=Math.sin(lpbjietheta)*(gxs[j]-lpboriginx)+Math.cos(lpbjietheta)*(gys[j]-lpboriginy);
                yjerm=Math.sin(lpbjietheta)*(gxe[j]-lpboriginx)+Math.cos(lpbjietheta)*(gye[j]-lpboriginy);
                ystart=yjsrm;
                yend=yjerm;
                if(yjsrm>yjerm){
                    ystart=yjerm;
                    yend=yjsrm;
                }
                lpboriginx=gpboriginx;
                lpboriginy=gpboriginy;
                g.setColor(Color.red);
                for(y=ystart;y<yend;y=y+0.1){
                    x=jou(y,2.0)/(4.0*lpbjiep);
                    xrmp=lpboriginx+Math.cos(-lpbjietheta)*x-Math.sin(-lpbjietheta)*y;
                    yrmp=lpboriginy+Math.sin(-lpbjietheta)*x+Math.cos(-lpbjietheta)*y;
                    cnt=0;
                    disjs=dis(xrmp,yrmp,gxe[i],gye[i]);
                    disje=dis(xrmp,yrmp,gxs[i],gys[i]);
                    if(disje<disjs){
                        cnt++;
                    }else{
                        double disieeps;
                        disieeps=dis(xrmp,yrmp,gxe[i]*0.999+gxs[i]*0.001,gye[i]*0.999+gys[i]*0.001);
                        if(disieeps<disjs){
                            cnt++;
                        }
                    }
                    if(cnt==0){
                        if(cntorder(i,j,xrmp,yrmp,disjs)==0){
                            g.drawLine((int)(xrmp),(int)(yrmp),(int)(xrmp),(int)(yrmp));
                        }
                    }//cnt==0
                }//y

            }//j
        }//i
    }//paint main

    //bisectors of two points ２つの端点に対する境界線を求めます
    void bisec2poi( double tx1, double ty1, double tx2,  double ty2){
        double ssdi;
        double ssdi2;
        double ssys;
        double sscx;
        double sscy;

        ssdi=(ty1-ty2)/(tx1-tx2);
        ssdi2=-1.0/ssdi;
        sscx=(tx1+tx2)/2.0;
        sscy=(ty1+ty2)/2.0;
        ssys=sscy-ssdi2*sscx;

        grx1=0.0;
        gry1=ssys;
        if(ssys<0.0){
            grx1=-ssys/ssdi2;
            gry1=0.0;
        }
        if(ssys>gtakad){
            grx1=(gtakad-ssys)/ssdi2;
            gry1=gtakad;
        }
        grx2=ghabad;
        gry2=ssdi2*ghabad+ssys;
        if(gry2<0.0){
            grx2=-ssys/ssdi2;
            gry2=0.0;
        }
        if(ssdi2*ghabad+ssys>gtakad){
            grx2=(gtakad-ssys)/ssdi2;
            gry2=gtakad;
        }
    }//bisec2poi

    //2 bisectors of line segment i and line segment j　線分pariと線分parjの境界を求めます。角の二等分線を求めることになります。大きい角と小さい角、両方の二等分線を求めます
    void bisec2seg(int pari,int parj){


        double lcx1;
        double lcy1;
        double lcx2;
        double lcy2;

        double lslope;
        double lintercept;

        double lthetai;
        double lthetaj;
        double lctheta;
        double lcslope;
        double lcys;


        lcx1=100.0;
        lcy1=10.0;

        //(lcx1,lcy1) is intersection of two line segments. は2つの線分の交点
        lcx1=(gintercept[pari]-gintercept[parj])/(gslope[parj]-gslope[pari]);
        lcy1=gslope[pari]*lcx1+gintercept[pari];

        lthetai=Math.atan(gslope[pari]);//angletheta of i  iの角度
        lthetaj=Math.atan(gslope[parj]);//angletheta of j  jの角度
        lctheta=(lthetai+lthetaj)/2.0;//angle of bisector of an angle  角の二等分線の角度
        lcslope=Math.tan(lctheta);//slope of bisector of an angle  角の二等分線の傾き
        lcys=lcy1-lcslope*lcx1;//intercept of bisector of an angle  角の二等分線のｙ切片

        //Consider two bisectors of an angle for line segments i and j.
        //iとjによりできる２つの角の二等分線を考えます。
        //One bisector of an angles is expressed (gux1,guy1)-(gux2,guy2)
        //The other is expressed (gux3,guy3)-(gux4,guy4)
        //一つの角の二等分線は (gux1,guy1)-(gux2,guy2)であらわされ
        //もう一つは(gux3,guy3)-(gux4,guy4)であらわされます。
        gux1=0.0;//(gux1,guy1) is left edge point of the one bisector of an angle  は１つの角の二等分線の左端
        guy1=lcys;
        if(lcys<0.0){
            gux1=-lcys/lcslope;
            guy1=0.0;
        }
        if(lcys>gtakad){
            gux1=(gtakad-lcys)/lcslope;
            guy1=gtakad;
        }
        gux2=ghabad;//(gux2,guy2) is right edge point of the one bisector of an angle  は１つの角の二等分線の右端
        guy2=lcslope*ghabad+lcys;
        if(guy2<0.0){
            gux2=-lcys/lcslope;
            guy2=0.0;
        }
        if(lcslope*ghabad+lcys>gtakad){
            gux2=(gtakad-lcys)/lcslope;
            guy2=gtakad;
        }

        lthetaj=Math.atan(gslope[parj]);
        if(lthetai<lthetaj){
            lthetai=lthetai+gpi;
        }else{
            lthetaj=lthetaj+gpi;
        }
        lctheta=(lthetai+lthetaj)/2.0;
        lcslope=Math.tan(lctheta);
        lcys=lcy1-lcslope*lcx1;

        gux3=0.0;//(gux3,guy3) is left edge point of the other bisector of an angle  はもう一方の角の二等分線の左端
        guy3=lcys;
        if(lcys<0.0){
            gux3=-lcys/lcslope;
            guy3=0.0;
        }
        if(lcys>gtakad){
            gux3=(gtakad-lcys)/lcslope;
            guy3=gtakad;
        }
        gux4=ghabad;//(gux4,guy4) is right edge point of the other bisector of an angle  はもう一方の角の二等分線の右端
        guy4=lcslope*ghabad+lcys;
        if(guy4<0.0){
            gux4=-lcys/lcslope;
            guy4=0.0;
        }
        if(lcslope*ghabad+lcys>gtakad){
            gux4=(gtakad-lcys)/lcslope;
            guy4=gtakad;
        }

    }//bisec2poi

    //parabola bisector of line segment i and left point of segment j
    void bisecsegpois(int pari, int parj){
        double lthetaj;
        double dis;
        double lslopej;
        double linterceptj;
        double lp;
        double lintersectionx;
        double lintersectiony;
        double lcx;
        double lcy;

        //When the line (directrix) is x=-lp and the point (focus) is (lp,0) then the parabola line is y^2=4lpx.
        //もし準線をx=-lp、焦点を(lp,0)とすると、放物線の式はy^2=4lpxとなります。

        //At first, lp is set to the half of distance between segment i and edge point of j.
        //まずlpを線分iとjの端点までの距離の半分とします。
        //Rotate segment i and edge point of j by the angle of segment i, that is, make line segment i x=lp. Next, move segment i and edge point of j such that the middlepoint of segment i and edge point of j become origin point, (0,0). From these actions, we can draw y^2=4lpx for segment i and edge point of j.
        //After exit this subroutine, rotate back and move back. then you can draw exact parabola.
        //線分iとjの端点を線分iの角度だけ回転させます。それから、jの端点と、そこからiにおろした垂線の交わる点の中点が原点になるように平行移動させます。そうすることにより線分iとjの端点を使って、y^2=4lpxの式を作ることができます。
        //このサブルーチンをぬけたあと、y^2=4lpxの各点に対して、逆の回転と逆の平行移動をすれば、もとの線分と点の位置に対して放物線を書くことができます。

        //distance between line i and point(left point of j)
        dis=Math.abs(gslope[pari]*gxs[parj]-gys[parj]+gintercept[pari])/jou(jou(gslope[pari],2.0)+1.0,0.5);
        lp=dis/2.0;
        lslopej=-1.0/gslope[pari];
        linterceptj=gys[parj]-lslopej*gxs[parj];
        lintersectionx=(gintercept[pari]-linterceptj)/(lslopej-gslope[pari]);
        lintersectiony=lintersectionx*lslopej+linterceptj;
        lcx=(gxs[parj]+lintersectionx)/2.0;
        lcy=(gys[parj]+lintersectiony)/2.0;
        lthetaj=Math.atan(lslopej);

        //(gpboriginx,gpboriginy) is origin point for segment i and edge point of j for y^2=4lpx.
        //(gpboriginx,gpboriginy)は線分iとjの端点で放物線を描くときの原点。y^2=4lpxの式で表す際に平行移動させるｘ方向、ｙ方向の座標をあらわします。
        gpboriginx=lcx;
        gpboriginy=lcy;
        //gpbijsp is lp when bisector is y^2=4lpx for line segment i and edge point of j. 線分iとjの端点の境界線放物線をy^2=4lpxであらわすときのlp
        gpbijsp=lp;
        //gpbijstheta is angle of rotation when bisector is y^2=4lpx for line segment i and edge point of j. 線分iとjの端点の境界放物線をy^2=4lpxであらわすときに回転させる角度
        gpbijstheta=lthetaj;

    }//bisecsegpois

    //parabola bisector of line segment pari and right point of segment parj　線分pariと、線分parjの右端の点でできる放物線の情報を求めます
    void bisecsegpoie(int pari, int parj){
        double lthetaj;
        double dis;
        double lslopej;
        double linterceptj;
        double lp;
        double lintersectionx;
        double lintersectiony;
        double lcx;
        double lcy;

        //When the line (directrix) is x=-lp and the point (focus) is (lp,0) then the parabola line is y^2=4lpx.
        //もし準線をx=-lp、焦点を(lp,0)とすると、放物線の式はy^2=4lpxとなります。

        //At first, lp is set to the half of distance between segment i and edge point of j.
        //まずlpを線分iとjの端点までの距離の半分とします。
        //Rotate segment i and edge point of j by the angle of segment i, that is, make line segment i x=lp. Next, move segment i and edge point of j such that the middlepoint of segment i and edge point of j become origin point, (0,0). From these actions, we can draw y^2=4lpx for segment i and edge point of j.
        //After exit this subroutine, rotate back and move back. then you can draw exact parabola.
        //線分iとjの端点を線分iの角度だけ回転させます。それから、jの端点と、そこからiにおろした垂線の交わる点の中点が原点になるように平行移動させます。そうすることにより線分iとjの端点を使って、y^2=4lpxの式を作ることができます。
        //このサブルーチンをぬけたあと、y^2=4lpxの各点に対して、逆の回転と逆の平行移動をすれば、もとの線分と点の位置に対して放物線を書くことができます。


        //distance between line pari and point(right point of parj)　線分pariと線分parjの右端の点の距離
        dis=Math.abs(gslope[pari]*gxe[parj]-gye[parj]+gintercept[pari])/jou(jou(gslope[pari],2.0)+1.0,0.5);
        lp=dis/2.0;
        lslopej=-1.0/gslope[pari];
        linterceptj=gye[parj]-lslopej*gxe[parj];
        lintersectionx=(gintercept[pari]-linterceptj)/(lslopej-gslope[pari]);
        lintersectiony=lintersectionx*lslopej+linterceptj;
        lcx=(gxe[parj]+lintersectionx)/2.0;
        lcy=(gye[parj]+lintersectiony)/2.0;
        lthetaj=Math.atan(lslopej);

        //(gpboriginx,gpboriginy) is origin point for segment i and edge point of j for y^2=4lpx.
        //(gpboriginx,gpboriginy)は線分iとjの端点で放物線を描くときの原点。y^2=4lpxの式で表す際に平行移動させるｘ方向、ｙ方向の座標をあらわします。
        gpboriginx=lcx;
        gpboriginy=lcy;
        //gpbijep is lp when bisector is y^2=4lpx for line segment i and edge point of j. 線分iとjの端点の境界線放物線をy^2=4lpxであらわすときのlp
        gpbijep=lp;
        //gpbijetheta is angle of rotation when bisector is y^2=4lpx for line segment i and edge point of j. 線分iとjの端点の境界放物線をy^2=4lpxであらわすときに回転させる角度
        gpbijetheta=lthetaj;

    }//bisecsegpoie

    public int cntorder(int si, int sj, double sx, double sy, double sd){
        int lcnt;
        int l;
        lcnt=0;
        for(l=0;l<N;l++){
            if(l!=si && l!=sj){
                double disl;
                disl=Math.abs(gslope[l]*sx-sy+gintercept[l])/jou(jou(gslope[l],2.0)+1.0,0.5);
                if(disl<sd){
                    double dil;
                    double ysl;
                    double intersectionxl;
                    dil=-1.0/gslope[l];
                    ysl=sy-dil*sx;
                    intersectionxl=(ysl-gintercept[l])/(gslope[l]-dil);
                    if(intersectionxl<gxs[l] || intersectionxl>gxe[l]){
                        double disls;
                        disls=dis(sx,sy,gxs[l],gys[l]);
                        if(disls<sd){
                            lcnt++;
                        }else{
                            double disle;
                            disle=dis(sx,sy,gxe[l],gye[l]);
                            if(disle<sd){
                                lcnt++;
                            }
                        }
                    }else{
                        lcnt++;
                    }
                    if(lcnt>0){
                        break;
                    }
                }//disl<sd
            }//l!=si && l!=sj
        }//l
        return lcnt;
    }//cntorder

}


