Blog2:nchu-software-oop-2022-4+5+期中

乎语百科 115 0

Blog2:nchu-software-oop-2022-4+5+期中

一、前言

两次大作业是关于四边形和五边形的相关操作,类似于之前的三角形,但由于图形边数的变化,难度大大增加。对数学知识的运用考察较多,其中还有对正则表达式的考量。在完成五边形第二题作业是,由于前面创建的类并不好,在面对复杂的五边形时,前面的类根本没有办法延用。这两次作业对我来说都很吃力。考查的知识点有:字符串的输出和输入,强制转化变量的类型,split函数的应用,逻辑思维能力,全面考虑问题的能力,方法编写能力,正则表达式练习。其中,主要题目是图形界面类设计编写。这些作业题量和难度都很大,全部尽量写到最好要花费比较多的时间。

期中考试主要考察了PTA图形界面类设计编写,共有三道题目,题量一般。与平时题目不同的是,每题均给出了相应的类图,要求考生按照类图来书写自己的代码。且三题呈递进关系,每题均是由上一题进阶而来。第一题是点与线,要求输出点和线的属性,考察了学生对Java类的设计的掌握。而第二题则是在第一题的基础上加上了关于面的类,并要求把点、线、面三类均作为新建类Element类的子类。考察了学生对继承与多态的掌握。第三题考察了Java容器类,主要是ArrayList的应用。且相比前两题有了多种输入格式,增加了难度。

 

二、设计与分析

题目1:

7-2 点线形系列4-凸四边形的计算

分数 70
全屏浏览题目
切换布局
作者 蔡轲
单位 南昌航空大学

用户输入一组选项和数据,进行与四边形有关的计算。以下四边形顶点的坐标要求按顺序依次输入,连续输入的两个顶点是相邻顶点,第一个和最后一个输入的顶点相邻。选项包括:1:输入四个点坐标,判断是否是四边形、平行四边形,判断结果输出true/false,结果之间以一个英文空格符分隔。2:输入四个点坐标,判断是否是菱形、矩形、正方形,判断结果输出true/false,结果之间以一个英文空格符分隔。 若四个点坐标无法构成四边形,输出"not a quadrilateral"3:输入四个点坐标,判断是凹四边形(false)还是凸四边形(true),输出四边形周长、面积,结果之间以一个英文空格符分隔。 若四个点坐标无法构成四边形,输出"not a quadrilateral"4:输入六个点坐标,前两个点构成一条直线,后四个点构成一个四边形或三角形,输出直线与四边形(也可能是三角形)相交的交点数量。如果交点有两个,再按面积从小到大输出四边形(或三角形)被直线分割成两部分的面积(不换行)。若直线与四边形或三角形的一条边线重合,输出"The line is coincide with one of the lines"。若后四个点不符合四边形或三角形的输入,输出"not a quadrilateral or triangle"。后四个点构成三角形的情况:假设三角形一条边上两个端点分别是x、y,边线中间有一点z,另一顶点s:1)符合要求的输入:顶点重复或者z与xy都相邻,如x x y s、x z y s、x y x s、s x y y。此时去除冗余点,保留一个x、一个y。2) 不符合要求的输入:z 不与xy都相邻,如z x y s、x z s y、x s z y5:输入五个点坐标,输出第一个是否在后四个点所构成的四边形(限定为凸四边形,不考虑凹四边形)或三角形(判定方法见选项4)的内部(若是四边形输出in the quadrilateral/outof the quadrilateral,若是三角形输出in the triangle/outof the triangle)。如果点在多边形的某条边上,输出"on the triangle或者on the quadrilateral"。若后四个点不符合四边形或三角形,输出"not a quadrilateral or triangle"。

*****************************************************************************************************************************************************************************

这题题目难度还好,主要根据前面三角形的类和方法,在其基础上添加修改。

import java.util.Scanner;

class Point
{
    double x;
    double y;
    int flag=0;
    int exist=1;//1:存在 0:不存在 2:交点无数个
    public boolean pointchonghe(Point A,Point B)//判断两点重合
    {
        if(A.x==B.x&&A.y==B.y)
            return true;
        else
            return false;
    }
    public boolean Pointscoincide(Point A,Point B,Point C,Point D)//判断四边形四点重合
    {
        if(A.x==B.x&&A.y==B.y||A.x==C.x&&A.y==C.y||A.x==D.x&&A.y==D.y||B.x==C.x&&B.y==C.y||B.x==D.x&&B.y==D.y||C.x==D.x&&C.y==D.y)
            return true;
        else
            return false;
    }
}

class Line
{
    Point p1=new Point();
    Point p2=new Point();
    double a;
    double b;
    double c;
    double D;
    int flag;//交点是否在线段上
    public void L(Line l)//一般式系数
    {
        l.a=l.p2.y-l.p1.y;
        l.b=l.p1.x-l.p2.x;
        l.c=l.p2.x*l.p1.y-l.p1.x*l.p2.y;
    }
    public void D(Point p1,Point p2,Line lp1p2)//两点间距离
    {
        lp1p2.D=Math.sqrt(Math.pow(lp1p2.p1.x-lp1p2.p2.x,2)+Math.pow(lp1p2.p1.y-lp1p2.p2.y,2));
        lp1p2.D=Math.round(lp1p2.D*1000000000)/(double)1000000000;
    }
    public void distanse(Line l)//求线段距离D
    {
        l.D=Math.sqrt(Math.pow(l.p1.x-l.p2.x,2)+Math.pow(l.p1.y-l.p2.y,2));
        l.D=Math.round(l.D*1000000000)/(double)1000000000;
    }
    public boolean zhixian(Point X,Line l)//点是否在直线上
    {
        L(l);
        if(l.a*X.x+l.b*X.y+l.c==0)
            return true;
        else
            return false;
    }
    public boolean linechonghe(Line l1,Line l2)//判断是否两线重合
    {
        L(l1);
        L(l2);
        if(l1.b==0&&l2.b==0)
        {
            if(l1.c/l1.a==l2.c/l2.a)
                return true;
            else
                return false;
        }
        else if(l1.a==0&&l2.a==0)
        {
            if(l1.c/l1.b==l2.c/l2.b)
                return true;
            else
                return false;
        }
        else
        {
            if(l1.c/l1.a==l2.c/l2.a&&l1.c/l1.b==l2.c/l2.b)
                return true;
            else
                return false;
        }
    }
    public boolean pingxing(Line l1,Line l2)//判断是否平行(有无交点)
    {
        L(l1);
        L(l2);
        if(l1.b==0&&l2.b==0)
            return true;
        else if(l1.b!=0&&l2.b!=0&&(l1.a/l1.b==l2.a/l2.b))
            return true;
        else
            return false;
    }
    public boolean Quadrilateral(Line lAB,Point C,Point D)//判断是否四边形
    {
        L(lAB);
        if((!zhixian(C,lAB))&&(!zhixian(D,lAB))&&((lAB.a*C.x+lAB.b*C.y+lAB.c<0)&&(lAB.a*D.x+lAB.b*D.y+lAB.c<0)||(lAB.a*C.x+lAB.b*C.y+lAB.c>0)&&(lAB.a*D.x+lAB.b*D.y+lAB.c>0)))
            return true;
        else
            return false;
    }
    public boolean Quadrilateral1(Point A,Point B,Point C,Point D,Quadrilateral Q)//凹
    {
        if((!zhixian(C,Q.l1))&&(!zhixian(D,Q.l1))&&(!zhixian(D,Q.l6))&&(!zhixian(D,Q.l2)))
        {
            Point O=new Point();
            Line lAO=new Line();
            lAO.p1=A;
            lAO.p2=O;
            Line lBO=new Line();
            lBO.p1=B;
            lBO.p2=O;
            Line lCO=new Line();
            lCO.p1=C;
            lCO.p2=O;
            Line lDO=new Line();
            lDO.p1=D;
            lDO.p2=O;
            Triangle t=new Triangle();

            t.jiaodian(Q.l5,Q.l6,O);//AC和BD交点
            if(t.pointwhere(O,A,C,lAO,lCO,Q.l6)&&!t.pointwhere(O,B,D,lBO,lDO,Q.l5))//交点在线段AC和不在BD上
            {
                Q.l5.flag=0;
                Q.l6.flag=1;
                return true;
            }
            else if(!t.pointwhere(O,A,C,lAO,lCO,Q.l6)&&t.pointwhere(O,B,D,lBO,lDO,Q.l5))//交点不在线段AC和在BD上
            {
                Q.l5.flag=1;
                Q.l6.flag=0;
                return true;
            }
            else
                return false;
        }
        else
            return false;
    }
    public boolean Quadrilateral2(Point A,Point B,Point C,Point D,Quadrilateral Q)//凸
    {
        if((!zhixian(C,Q.l1))&&(!zhixian(D,Q.l1))&&(!zhixian(A,Q.l3))&&(!zhixian(D,Q.l2))&&(!A.Pointscoincide(A,B,C,D)))
        {
            Point O=new Point();
            Line lAO=new Line();
            lAO.p1=A;
            lAO.p2=O;
            Line lBO=new Line();
            lBO.p1=B;
            lBO.p2=O;
            Line lCO=new Line();
            lCO.p1=C;
            lCO.p2=O;
            Line lDO=new Line();
            lDO.p1=D;
            lDO.p2=O;
            Triangle t=new Triangle();

            t.jiaodian(Q.l5,Q.l6,O);//AC和BD交点

            if(O.exist==1&&t.pointwhere(O,A,C,lAO,lCO,Q.l6)&&t.pointwhere(O,B,D,lBO,lDO,Q.l5))//交点在线段AC和BD上
                return true;
            else
                return false;
        }
        else
            return false;
    }
    public boolean pingxingQuadrilateral(Line l1,Line l2)//判断是否平行四边形
    {

        distanse(l1);
        distanse(l2);

        if(pingxing(l1,l2)&&l1.D==l2.D)
            return true;
        else
            return false;
    }
}

class Triangle
{
    Line l1=new Line();
    Line l2=new Line();
    Line l3=new Line();
    double S;
    int num;
    int flag=0;//1:存在,0:不存在
    public boolean sanjiaox(Line l1,Line l2,Line l3)//判断是否为三角形
    {
        l1.distanse(l1);
        l2.distanse(l2);
        l3.distanse(l3);
        if((l1.D+l2.D>l3.D&&l1.D<=l3.D&&l2.D<=l3.D)||(l1.D+l3.D>l2.D&&l1.D<=l2.D&&l3.D<=l2.D)||(l2.D+l3.D>l1.D&&l2.D<=l1.D&&l2.D<=l1.D))
            return true;
        else
            return false;
    }
    public void whichsanjiaox(Point C,Point D,Point E,Point F,Line lAB,Triangle tDEF,Triangle tCEF,Triangle tCDF,Triangle tCDE,Quadrilateral Q)//判断四个点构成哪种三角形
    {
        if(sanjiaox(tDEF.l1,tDEF.l2,tDEF.l3)&&pointwhere(C,D,F,Q.l1,Q.l4,Q.l5))
        {
            if(lAB.linechonghe(lAB,Q.l1)||lAB.linechonghe(lAB,Q.l2)||lAB.linechonghe(lAB,Q.l3)||lAB.linechonghe(lAB,Q.l4))
            {
                System.out.print("The line is coincide with one of the lines");
                return;
            }
            else
                tDEF.flag=1;
        }
        else if(sanjiaox(tCEF.l1,tCEF.l2,tCEF.l3)&&pointwhere(D,C,E,Q.l1,Q.l2,Q.l6))
        {
            if(lAB.linechonghe(lAB,Q.l1)||lAB.linechonghe(lAB,Q.l2)||lAB.linechonghe(lAB,Q.l3)||lAB.linechonghe(lAB,Q.l4))
            {
                System.out.print("The line is coincide with one of the lines");
                return;
            }
            else
                tCEF.flag=1;
        }
        else if(sanjiaox(tCDF.l1,tCDF.l2,tCDF.l3)&&pointwhere(E,D,F,Q.l2,Q.l3,Q.l5))
        {
            if(lAB.linechonghe(lAB,Q.l1)||lAB.linechonghe(lAB,Q.l2)||lAB.linechonghe(lAB,Q.l3)||lAB.linechonghe(lAB,Q.l4))
            {
                System.out.print("The line is coincide with one of the lines");
                return;
            }
            else
                tCDF.flag=1;
        }
        else if(sanjiaox(tCDE.l1,tCDE.l2,tCDE.l3)&&pointwhere(F,C,E,Q.l4,Q.l3,Q.l6))
        {
            if(lAB.linechonghe(lAB,Q.l1)||lAB.linechonghe(lAB,Q.l2)||lAB.linechonghe(lAB,Q.l3)||lAB.linechonghe(lAB,Q.l4))
            {
                System.out.print("The line is coincide with one of the lines");
                return;
            }
            else
                tCDE.flag=1;
        }
    }
    public void whichsanjiaox1(Point C,Point D,Point E,Point F,Triangle tDEF,Triangle tCEF,Triangle tCDF,Triangle tCDE,Quadrilateral Q)//判断哪种三角形
    {
        if(sanjiaox(tDEF.l1,tDEF.l2,tDEF.l3)&&pointwhere(C,D,F,Q.l1,Q.l4,Q.l5))
            tDEF.flag=1;
        else if(sanjiaox(tCEF.l1,tCEF.l2,tCEF.l3)&&pointwhere(D,C,E,Q.l1,Q.l2,Q.l6))
            tCEF.flag=1;
        else if(sanjiaox(tCDF.l1,tCDF.l2,tCDF.l3)&&pointwhere(E,D,F,Q.l2,Q.l3,Q.l5))
            tCDF.flag=1;
        else if(sanjiaox(tCDE.l1,tCDE.l2,tCDE.l3)&&pointwhere(F,C,E,Q.l4,Q.l3,Q.l6))
            tCDE.flag=1;
    }
    public void jiaodian(Line l1,Line l2,Point O)//两条直线交点
    {
        if(l1.pingxing(l1,l2))
        {
            O.exist=0;
        }
        else
        {
            l1.L(l1);
            l2.L(l2);
            O.x=(l1.b*l2.c-l2.b*l1.c)/(l1.a*l2.b-l2.a*l1.b);
            O.y=(l2.a*l1.c-l1.a*l2.c)/(l1.a*l2.b-l2.a*l1.b);
            O.x=Math.round(O.x*1000000000)/(double)1000000000;
            O.y=Math.round(O.y*1000000000)/(double)1000000000;
        }
    }
    public boolean pointwhere(Point A,Point B,Point C,Line lAB,Line lAC,Line lBC)//点A是否在线段BC上
    {
        if(A.pointchonghe(A,B)||A.pointchonghe(A,C))
            return true;
        else
        {
            lAB.D(A,B,lAB);
            lAC.D(A,C,lAC);
            lBC.D(B,C,lBC);
            if(lAB.D+lAC.D-lBC.D<0.000001)
                return true;
            else
                return false;
        }
    }
    public void jiaodiannum(Point P1,Point P2,Point P3,Line lAB,Triangle t)//交点数(线和三角形)
    {
        t.num=0;
        P1.flag=0;
        P2.flag=0;
        P3.flag=0;

        t.jiaodian(lAB,t.l1,P1);
        Line lp11=new Line();
        lp11.p1=P1;
        lp11.p2=t.l1.p1;
        Line lp12=new Line();
        lp12.p1=P1;
        lp12.p2=t.l1.p2;
        if(P1.exist==1&&t.pointwhere(P1, t.l1.p1, t.l1.p2,lp11,lp12,t.l1))
        {
            t.num++;
            P1.flag=1;//交点在线段上
        }
        t.jiaodian(lAB,t.l2,P2);
        Line lp21=new Line();
        lp21.p1=P2;
        lp21.p2=t.l2.p1;
        Line lp22=new Line();
        lp22.p1=P2;
        lp22.p2=t.l2.p2;
        if(P2.exist==1&&t.pointwhere(P2,t.l2.p1,t.l2.p2,lp21,lp22,t.l2))
        {
            if(P1.flag==0||(!P1.pointchonghe(P1,P2)&&P1.flag==1))
            {
                t.num++;
                P2.flag=1;
            }
        }
        t.jiaodian(lAB,t.l3,P3);
        Line lp31=new Line();
        lp31.p1=P3;
        lp31.p2=t.l3.p1;
        Line lp32=new Line();
        lp32.p1=P3;
        lp32.p2=t.l3.p2;
        if(P3.exist==1&&t.pointwhere(P3,t.l3.p1,t.l3.p2,lp31,lp32,t.l3))
        {
            if(P1.flag==0&&P2.flag==0)
            {
                t.num++;
                P3.flag=1;
            }
            else if(P1.flag==1&&P2.flag==0&&!P1.pointchonghe(P1,P3))
            {
                t.num++;
                P3.flag=1;
            }
            else if(P1.flag==0&&P2.flag==1&&!P2.pointchonghe(P2,P3))
            {
                t.num++;
                P3.flag=1;
            }
        }
    }
    public void sanjiaoxmianji(Triangle t)//三角形面积
    {
        t.l1.distanse(t.l1);
        t.l2.distanse(t.l2);
        t.l3.distanse(t.l3);
        double x=(t.l1.D+t.l2.D+t.l3.D)/2;
        t.S=Math.sqrt(x*(x-t.l1.D)*(x-t.l2.D)*(x-t.l3.D));
    }
    public void xiaomianji(Point P1,Point P2,Point P3,Triangle t,Triangle T)//切割小三角形面积
    {
        if(P1.flag==1&&P2.flag==1)//三角形CP1P2
        {
            t.l1.p1=T.l1.p2;
            t.l1.p2=P1;
            t.l2.p1=T.l1.p2;
            t.l2.p2=P2;
            t.l3.p1=P1;
            t.l3.p2=P2;
            t.sanjiaoxmianji(t);
        }
        else if(P1.flag==1&&P3.flag==1)
        {

            t.l1.p1=T.l1.p1;
            t.l1.p2=P1;
            t.l2.p1=T.l1.p1;
            t.l2.p2=P3;
            t.l3.p1=P1;
            t.l3.p2=P3;
            t.sanjiaoxmianji(t);
        }
        else if(P2.flag==1&&P3.flag==1)
        {

            t.l1.p1=T.l2.p2;
            t.l1.p2=P2;
            t.l2.p1=T.l2.p2;
            t.l2.p2=P3;
            t.l3.p1=P2;
            t.l3.p2=P3;
            t.sanjiaoxmianji(t);
        }
    }
     public void xiaomianji1(Point P1,Point P2,Point P3,Point P4,Triangle t,Quadrilateral Q)//四边形切割小三角形面积
     {
        if(P1.flag==1&&P2.flag==1)//三角形DP1P2
        {
            t.l1.p1=Q.l1.p2;
            t.l1.p2=P1;
            t.l2.p1=Q.l1.p2;
            t.l2.p2=P2;
            t.l3.p1=P1;
            t.l3.p2=P2;
            t.sanjiaoxmianji(t);
        }
        else if(P1.flag==1&&P4.flag==1)//CP1P4
        {

            t.l1.p1=Q.l1.p1;
            t.l1.p2=P1;
            t.l2.p1=Q.l1.p1;
            t.l2.p2=P4;
            t.l3.p1=P1;
            t.l3.p2=P4;
            t.sanjiaoxmianji(t);
        }
        else if(P2.flag==1&&P3.flag==1)//EP2P3
        {
            t.l1.p1=Q.l2.p2;
            t.l1.p2=P2;
            t.l2.p1=Q.l2.p2;
            t.l2.p2=P3;
            t.l3.p1=P2;
            t.l3.p2=P3;
            t.sanjiaoxmianji(t);
        }
        else if(P3.flag==1&&P4.flag==1)//FP3P4
        {
            t.l1.p1=Q.l3.p2;
            t.l1.p2=P3;
            t.l2.p1=Q.l3.p2;
            t.l2.p2=P4;
            t.l3.p1=P3;
            t.l3.p2=P4;
            t.sanjiaoxmianji(t);
        }
    }
}

class Quadrilateral
{
    Line l1=new Line();
    Line l2=new Line();
    Line l3=new Line();
    Line l4=new Line();
    Line l5=new Line();//BD
    Line l6=new Line();//AC
    double C;
    double S;
    int num;
    int flag;//1:存在 0:不存在
    int aotu;//1:凸 0:凹
    public boolean lingxing(Quadrilateral Q)//菱形
    {
        if(!Q.l1.pingxingQuadrilateral(Q.l1,Q.l3))
            return false;
        else
        {
            Q.l1.distanse(Q.l1);
            Q.l2.distanse(Q.l2);
            if(Q.l1.D==Q.l2.D)
                return true;
            else
                return false;
        }
    }
    public boolean zhijiao(Quadrilateral Q)//判断直角
    {
        Q.l1.distanse(Q.l1);
        Q.l4.distanse(Q.l4);
        Q.l5.distanse(Q.l5);
        if(Q.l1.D*Q.l1.D+Q.l4.D*Q.l4.D-Q.l5.D*Q.l5.D<0.000000000001)
            return true;
        else
            return false;
    }
    public boolean juxing(Quadrilateral Q)//矩形
    {
        if(!Q.l1.pingxingQuadrilateral(Q.l1,Q.l3))
            return false;
        else
        {
            if(zhijiao(Q))
                return true;
            else
                return false;
        }
    }
    public boolean zhengfangxing(Quadrilateral Q)//正方形
    {
        if(!Q.juxing(Q))
            return false;
        else
        {
            Q.l1.distanse(Q.l1);
            Q.l2.distanse(Q.l2);
            if(Q.l1.D==Q.l2.D)
                return true;
            else
                return false;
        }
    }
    public void Quadrilateralzhouchang(Quadrilateral Q)//四边形周长
    {
        Q.l1.distanse(Q.l1);
        Q.l2.distanse(Q.l2);
        Q.l3.distanse(Q.l3);
        Q.l4.distanse(Q.l4);
        Q.C=Q.l1.D+Q.l2.D+Q.l3.D+Q.l4.D;
    }

    public void Quadrilateralmianji(Quadrilateral Q)//凸四边形面积
    {
        Q.l1.distanse(Q.l1);
        Q.l2.distanse(Q.l2);
        Q.l3.distanse(Q.l3);
        Q.l4.distanse(Q.l4);
        Q.l5.distanse(Q.l5);

        double x1=(l1.D+l4.D+l5.D)/2;
        double s1=Math.sqrt(x1*(x1-l1.D)*(x1-l4.D)*(x1-l5.D));
        double x2=(l2.D+l3.D+l5.D)/2;
        double s2=Math.sqrt(x2*(x2-l2.D)*(x2-l3.D)*(x2-l5.D));

        Q.S=s1+s2;
    }
    public void Quadrilateralmianji1(Quadrilateral Q)//凹四边形面积
    {
        if(Q.l5.flag==0&&Q.l6.flag==1)
        {
            Quadrilateralmianji(Q);
        }
        else if(Q.l5.flag==1&&Q.l6.flag==0)
        {
            Q.l1.distanse(Q.l1);
            Q.l2.distanse(Q.l2);
            Q.l3.distanse(Q.l3);
            Q.l4.distanse(Q.l4);
            Q.l6.distanse(Q.l6);

        double x1=(l1.D+l2.D+l6.D)/2;
        double s1=Math.sqrt(x1*(x1-l1.D)*(x1-l2.D)*(x1-l6.D));
        double x2=(l3.D+l4.D+l6.D)/2;
        double s2=Math.sqrt(x2*(x2-l3.D)*(x2-l4.D)*(x2-l6.D));

        Q.S=s1+s2;
        }
    }
    public void Quadrilateralnum(Point P1,Point P2,Point P3,Point P4,Line lAB,Triangle T,Quadrilateral Q)//交点数(线和四边形)
    {
        Q.num=0;
        P1.flag=0;
        P2.flag=0;
        P3.flag=0;
        P4.flag=0;

        T.jiaodian(lAB,Q.l1,P1);
        Line lp11=new Line();
        lp11.p1=P1;
        lp11.p2=Q.l1.p1;
        Line lp12=new Line();
        lp12.p1=P1;
        lp12.p2=Q.l1.p2;
        if(P1.exist==1&&T.pointwhere(P1,Q.l1.p1,Q.l1.p2,lp11,lp12,Q.l1))
        {
            Q.num++;
            P1.flag=1;//交点在线段上
        }
        T.jiaodian(lAB,Q.l2,P2);
        Line lp21=new Line();
        lp21.p1=P2;
        lp21.p2=Q.l2.p1;
        Line lp22=new Line();
        lp22.p1=P2;
        lp22.p2=Q.l2.p2;
        if(P2.exist==1&&T.pointwhere(P2,Q.l2.p1,Q.l2.p2,lp21,lp22,Q.l2))
        {
            if(P1.flag==0||(!P1.pointchonghe(P1,P2)&&P1.flag==1))
            {
                Q.num++;
                P2.flag=1;
            }
        }
        T.jiaodian(lAB,Q.l3,P3);
        Line lp31=new Line();
        lp31.p1=P3;
        lp31.p2=Q.l3.p1;
        Line lp32=new Line();
        lp32.p1=P3;
        lp32.p2=Q.l3.p2;
        if(P3.exist==1&&T.pointwhere(P3,Q.l3.p1,Q.l3.p2,lp31,lp32,Q.l3))
        {
            if(P1.flag==0&&P2.flag==0)
            {
                Q.num++;
                P3.flag=1;
            }
            else if(P1.flag==1&&P2.flag==0&&!P1.pointchonghe(P1,P3))
            {
                Q.num++;
                P3.flag=1;
            }
            else if(P1.flag==0&&P2.flag==1&&!P2.pointchonghe(P2,P3))
            {
                Q.num++;
                P3.flag=1;
            }
        }
        T.jiaodian(lAB,Q.l4,P4);
        Line lp41=new Line();
        lp41.p1=P4;
        lp41.p2=Q.l4.p1;
        Line lp42=new Line();
        lp42.p1=P4;
        lp42.p2=Q.l4.p2;
        if(P4.exist==1&&T.pointwhere(P4,Q.l4.p1,Q.l4.p2,lp41,lp42,Q.l4))
        {
            if(P1.flag==0&&P2.flag==0&&P3.flag==0)
            {
                Q.num++;
                P4.flag=1;
            }
            else if(P1.flag==1&&P2.flag==0&&P3.flag==0&&!P1.pointchonghe(P1,P4))
            {
                Q.num++;
                P4.flag=1;
            }
            else if(P1.flag==0&&P2.flag==1&&P3.flag==0&&!P2.pointchonghe(P2,P4))
            {
                Q.num++;
                P4.flag=1;
            }
            else if(P1.flag==0&&P2.flag==0&&P3.flag==1&&!P3.pointchonghe(P3,P4))
            {
                Q.num++;
                P4.flag=1;
            }
        }
    }
}

public class Main
{
    public static void main(String[] args)
    {
        Scanner in=new Scanner(System.in);
        String a=in.nextLine();
        int num=(int)a.charAt(0)-(int)'0';

        String[] tokens=a.split(" ");
        int length=tokens.length;
        for(int i=0;i<length;i++)
        {
            if(i==0)
            {
                 if(!tokens[i].matches("^\\d:[+-]?(0|(0\\.\\d+)?|[1-9][0-9]*(\\.\\d+)?),[+-]?(0|(0\\.\\d+)?|[1-9][0-9]*(\\.\\d+)?)$"))
                {
                    System.out.print("Wrong Format");
                    return;
                }
            }
            else if(i!=0)
            {
                if(!tokens[i].matches("^[+-]?(0|(0\\.\\d+)?|[1-9][0-9]*(\\.\\d+)?),[+-]?(0|(0\\.\\d+)?|[1-9][0-9]*(\\.\\d+)?)$"))
                {
                    System.out.print("Wrong Format");
                    return;
                }
            }
        }
        if(((num==1||num==2||num==3)&&length!=4)||(num==4&&length!=6)||(num==5&&length!=5))
        {
            System.out.print("wrong number of points");
            return;
        }
        String[] arr=a.split(" |:|,");
        switch(num)
        {
            case 1:
                {
                    Line lAB=new Line();
                    Point C=new Point();
                    Point D=new Point();
                    lAB.p1.x=Double.valueOf(arr[1]);
                    lAB.p1.y=Double.valueOf(arr[2]);
                    lAB.p2.x=Double.valueOf(arr[3]);
                    lAB.p2.y=Double.valueOf(arr[4]);
                    C.x=Double.valueOf(arr[5]);
                    C.y=Double.valueOf(arr[6]);
                    D.x=Double.valueOf(arr[7]);
                    D.y=Double.valueOf(arr[8]);
                    Line lCD=new Line();
                    lCD.p1=C;
                    lCD.p2=D;
                    Line lBC=new Line();
                    lBC.p1=lAB.p2;
                    lBC.p2=C;

                    if(lAB.p1.Pointscoincide(lAB.p1,lAB.p2,C,D))
                    {
                        System.out.print("points coincide");return;
                    }

                    if(lAB.Quadrilateral(lAB,C,D)&&lBC.Quadrilateral(lBC,lAB.p1,D))
                    {
                        System.out.print("true");
                        if(lAB.pingxingQuadrilateral(lAB,lCD))
                            System.out.print(" true");
                        else
                            System.out.print(" false");
                    }
                    else
                        System.out.print("false false");
                    break;
                }
            case 2:
                {
                    Quadrilateral Q=new Quadrilateral();
                    Q.l1.p1.x=Double.valueOf(arr[1]);
                    Q.l1.p1.y=Double.valueOf(arr[2]);
                    Q.l1.p2.x=Double.valueOf(arr[3]);
                    Q.l1.p2.y=Double.valueOf(arr[4]);
                    Q.l2.p1=Q.l1.p2;
                    Q.l2.p2.x=Double.valueOf(arr[5]);
                    Q.l2.p2.y=Double.valueOf(arr[6]);
                    Q.l3.p1=Q.l2.p2;
                    Q.l3.p2.x=Double.valueOf(arr[7]);
                    Q.l3.p2.y=Double.valueOf(arr[8]);
                    Q.l4.p1=Q.l1.p1;
                    Q.l4.p2=Q.l3.p2;
                    Q.l5.p1=Q.l1.p2;
                    Q.l5.p2=Q.l4.p2;

                    if(Q.l1.p1.Pointscoincide(Q.l1.p1,Q.l1.p2,Q.l3.p1,Q.l3.p2))
                    {
                        System.out.print("not a quadrilateral");return;
                    }
                    if(!Q.l1.Quadrilateral(Q.l1,Q.l3.p1,Q.l3.p2)||!Q.l2.Quadrilateral(Q.l2,Q.l4.p1,Q.l4.p2))
                    {
                        System.out.print("not a quadrilateral");return;
                    }

                    if(Q.lingxing(Q))
                        System.out.print("true");
                    else
                        System.out.print("false");

                    if(Q.juxing(Q))
                        System.out.print(" true");
                    else
                        System.out.print(" false");

                    if(Q.zhengfangxing(Q))
                            System.out.print(" true");
                        else
                            System.out.print(" false");
                    break;
                }
            case 3:
                {
                    Quadrilateral Q=new Quadrilateral();
                    Q.l1.p1.x=Double.valueOf(arr[1]);
                    Q.l1.p1.y=Double.valueOf(arr[2]);
                    Q.l1.p2.x=Double.valueOf(arr[3]);
                    Q.l1.p2.y=Double.valueOf(arr[4]);
                    Q.l2.p1=Q.l1.p2;
                    Q.l2.p2.x=Double.valueOf(arr[5]);
                    Q.l2.p2.y=Double.valueOf(arr[6]);
                    Q.l3.p1=Q.l2.p2;
                    Q.l3.p2.x=Double.valueOf(arr[7]);
                    Q.l3.p2.y=Double.valueOf(arr[8]);
                    Q.l4.p1=Q.l1.p1;
                    Q.l4.p2=Q.l3.p2;
                    Q.l5.p1=Q.l1.p2;
                    Q.l5.p2=Q.l4.p2;
                    Q.l6.p1=Q.l1.p1;
                    Q.l6.p2=Q.l2.p2;
                    Point A=new Point();
                    Point B=new Point();
                    Point C=new Point();
                    Point D=new Point();
                    A.x=Double.valueOf(arr[1]);
                    A.y=Double.valueOf(arr[2]);
                    B.x=Double.valueOf(arr[3]);
                    B.y=Double.valueOf(arr[4]);
                    C.x=Double.valueOf(arr[5]);
                    C.y=Double.valueOf(arr[6]);
                    D.x=Double.valueOf(arr[7]);
                    D.y=Double.valueOf(arr[8]);

                    if(Q.l1.p1.Pointscoincide(Q.l1.p1,Q.l1.p2,Q.l3.p1,Q.l3.p2))
                    {
                        System.out.print("not a quadrilateral");return;
                    }

                    int X;
                    if(Q.l1.Quadrilateral(Q.l1,Q.l3.p1,Q.l3.p2)&&Q.l2.Quadrilateral(Q.l2,Q.l4.p1,Q.l4.p2)&&!Q.l6.zhixian(D,Q.l6)&&!Q.l6.zhixian(B,Q.l6))//涵盖凸四边形和D点凹进去的四边形
                    {
                        Point o=new Point();
                        Line lBo=new Line();
                        lBo.p1=B;
                        lBo.p2=o;
                        Line lDo=new Line();
                        lDo.p1=D;
                        lDo.p2=o;
                        Line lAo=new Line();
                        lAo.p1=A;
                        lAo.p2=o;
                        Line lCo=new Line();
                        lCo.p1=C;
                        lCo.p2=o;
                        Triangle t=new Triangle();
                        t.jiaodian(Q.l5,Q.l6,o);
                        if(!t.pointwhere(o,Q.l5.p1,Q.l5.p2,lBo,lDo,Q.l5)&&t.pointwhere(o,Q.l6.p1,Q.l6.p2,lAo,lCo,Q.l6))
                        {
                            X=0;
                            Q.l5.flag=0;
                            Q.l6.flag=1;
                            System.out.print("false ");
                        }
                        else
                        {
                            X=1;
                            System.out.print("true ");
                        }
                    }
                    else
                    {
                        if(Q.l5.Quadrilateral1(A,B,C,D,Q))//凹四边形
                        {
                            X=0;
                            System.out.print("false ");
                        }
                        else
                        {
                            System.out.print("not a quadrilateral");
                            return;
                        }
                    }

                    Q.Quadrilateralzhouchang(Q);//周长面积
                    System.out.print(Math.round(Q.C*1000)/(double)1000);
                    if(X==1)
                    {
                        System.out.print(" ");
                        Q.Quadrilateralmianji(Q);
                        System.out.print(Math.round(Q.S*1000)/(double)1000);
                    }
                    else if(X==0)
                    {
                        System.out.print(" ");
                        Q.Quadrilateralmianji1(Q);
                        System.out.print(Math.round(Q.S*1000)/(double)1000);
                    }
                    break;
                }
            case 4:
                {
                    Point A=new Point();
                    Point B=new Point();
                    A.x=Double.valueOf(arr[1]);
                    A.y=Double.valueOf(arr[2]);
                    B.x=Double.valueOf(arr[3]);
                    B.y=Double.valueOf(arr[4]);
                    Line lAB=new Line();
                    lAB.p1=A;
                    lAB.p2=B;

                    if(A.pointchonghe(A,B))
                    {
                        System.out.print("points coincide");return;
                    }

                    Point C=new Point();
                    Point D=new Point();
                    Point E=new Point();
                    Point F=new Point();
                    C.x=Double.valueOf(arr[5]);
                    C.y=Double.valueOf(arr[6]);
                    D.x=Double.valueOf(arr[7]);
                    D.y=Double.valueOf(arr[8]);
                    E.x=Double.valueOf(arr[9]);
                    E.y=Double.valueOf(arr[10]);
                    F.x=Double.valueOf(arr[11]);
                    F.y=Double.valueOf(arr[12]);
                    Quadrilateral Q=new Quadrilateral();
                    Q.l1.p1=C;
                    Q.l1.p2=D;
                    Q.l2.p1=D;
                    Q.l2.p2=E;
                    Q.l3.p1=E;
                    Q.l3.p2=F;
                    Q.l4.p1=C;
                    Q.l4.p2=F;
                    Q.l5.p1=D;
                    Q.l5.p2=F;
                    Q.l6.p1=C;
                    Q.l6.p2=E;
                    Triangle tDEF=new Triangle();
                    tDEF.l1.p1=D;
                    tDEF.l1.p2=E;
                    tDEF.l2.p1=E;
                    tDEF.l2.p2=F;
                    tDEF.l3.p1=D;
                    tDEF.l3.p2=F;
                    Triangle tCEF=new Triangle();
                    tCEF.l1.p1=C;
                    tCEF.l1.p2=E;
                    tCEF.l2.p1=E;
                    tCEF.l2.p2=F;
                    tCEF.l3.p1=C;
                    tCEF.l3.p2=F;
                    Triangle tCDF=new Triangle();
                    tCDF.l1.p1=C;
                    tCDF.l1.p2=D;
                    tCDF.l2.p1=D;
                    tCDF.l2.p2=F;
                    tCDF.l3.p1=C;
                    tCDF.l3.p2=F;
                    Triangle tCDE=new Triangle();
                    tCDE.l1.p1=C;
                    tCDE.l1.p2=D;
                    tCDE.l2.p1=D;
                    tCDE.l2.p2=E;
                    tCDE.l3.p1=C;
                    tCDE.l3.p2=E;
                    Point P1=new Point();
                    Point P2=new Point();
                    Point P3=new Point();
                    Point P4=new Point();

                    tDEF.whichsanjiaox(C,D,E,F,lAB,tDEF,tCEF,tCDF,tCDE,Q);//判断是哪三个点构成三角形
                    if(tDEF.flag==1||C.pointchonghe(C,E))//求直线AB与三角形交点数
                    {
                        if(C.pointchonghe(C,E)&&lAB.linechonghe(lAB,Q.l5))
                        {
                            System.out.print("The line is coincide with one of the lines");return;
                        }
                        tDEF.jiaodiannum(P1,P2,P3,lAB,tDEF);
                        System.out.print(tDEF.num);
                        if(tDEF.num==2)
                        {
                            System.out.print(" ");
                            tDEF.sanjiaoxmianji(tDEF);
                            Triangle t=new Triangle();
                            tDEF.xiaomianji(P1,P2,P3,t,tDEF);//切割小三角形面积
                            double s=tDEF.S-t.S;
                            if(t.S<s)
                                System.out.print(Math.round(t.S*1000)/(double)1000+" "+Math.round(s*1000)/(double)1000);
                            else
                                System.out.print(Math.round(s*1000)/(double)1000+" "+Math.round(t.S*1000)/(double)1000);
                        }
                    }
                    else if(tCEF.flag==1||D.pointchonghe(D,F))
                    {
                        if(D.pointchonghe(D,F)&&lAB.linechonghe(lAB,Q.l6))
                        {
                            System.out.print("The line is coincide with one of the lines");return;
                        }
                        tCEF.jiaodiannum(P1,P2,P3,lAB,tCEF);
                        System.out.print(tCEF.num);
                        if(tCEF.num==2)
                        {
                            System.out.print(" ");
                            tCEF.sanjiaoxmianji(tCEF);
                            Triangle t=new Triangle();
                            tCEF.xiaomianji(P1,P2,P3,t,tCEF);//切割小三角形面积
                            double s=tCEF.S-t.S;
                            if(t.S<s)
                                System.out.print(Math.round(t.S*1000)/(double)1000+" "+Math.round(s*1000)/(double)1000);
                            else
                                System.out.print(Math.round(s*1000)/(double)1000+" "+Math.round(t.S*1000)/(double)1000);
                        }
                    }
                    else if(tCDF.flag==1||E.pointchonghe(E,C))
                    {
                        if(C.pointchonghe(C,E)&&lAB.linechonghe(lAB,Q.l5))
                        {
                            System.out.print("The line is coincide with one of the lines");return;
                        }
                        tCDF.jiaodiannum(P1,P2,P3,lAB,tCDF);
                        System.out.print(tCDF.num);
                        if(tCDF.num==2)
                        {
                            System.out.print(" ");
                            tCDF.sanjiaoxmianji(tCDF);
                            Triangle t=new Triangle();
                            tCDF.xiaomianji(P1,P2,P3,t,tCDF);//切割小三角形面积
                            double s=tCDF.S-t.S;
                            if(t.S<s)
                                System.out.print(Math.round(t.S*1000)/(double)1000+" "+Math.round(s*1000)/(double)1000);
                            else
                                System.out.print(Math.round(s*1000)/(double)1000+" "+Math.round(t.S*1000)/(double)1000);
                        }
                    }
                    else if(tCDE.flag==1||F.pointchonghe(F,D))
                    {
                        if(D.pointchonghe(D,F)&&lAB.linechonghe(lAB,Q.l6))
                        {
                            System.out.print("The line is coincide with one of the lines");return;
                        }
                        tCDE.jiaodiannum(P1,P2,P3,lAB,tCDE);
                        System.out.print(tCDE.num);
                        if(tCDE.num==2)
                        {
                            System.out.print(" ");
                            tCDE.sanjiaoxmianji(tCDE);
                            Triangle t=new Triangle();
                            tCDE.xiaomianji(P1,P2,P3,t,tCDE);//切割小三角形面积
                            double s=tCDE.S-t.S;
                            if(t.S<s)
                                System.out.print(Math.round(t.S*1000)/(double)1000+" "+Math.round(s*1000)/(double)1000);
                            else
                                System.out.print(Math.round(s*1000)/(double)1000+" "+Math.round(t.S*1000)/(double)1000);
                        }
                    }
                    else if(Q.l1.Quadrilateral2(C,D,E,F,Q))
                    {
                        if(lAB.linechonghe(lAB,Q.l1)||lAB.linechonghe(lAB,Q.l2)||lAB.linechonghe(lAB,Q.l3)||lAB.linechonghe(lAB,Q.l4))
                        {
                        System.out.print("The line is coincide with one of the lines");return;
                        }
                        Triangle t=new Triangle();
                        Q.Quadrilateralnum(P1,P2,P3,P4,lAB,t,Q);
                        System.out.print(Q.num);
                        if(Q.num==2)
                        {
                            System.out.print(" ");
                            Q.Quadrilateralmianji(Q);//大四边形面积
                            if(P1.flag==1&&P2.flag==1)
                            {
                                t.xiaomianji1(P1,P2,P3,P4,t,Q);
                                double s=Q.S-t.S;
                                if(t.S<s)
                                    System.out.print(Math.round(t.S*1000)/(double)1000+" "+Math.round(s*1000)/(double)1000);
                                else
                                    System.out.print(Math.round(s*1000)/(double)1000+" "+Math.round(t.S*1000)/(double)1000);
                            }
                            else if(P1.flag==1&&P3.flag==1)
                            {
                                Triangle tCFP3=new Triangle();
                                tCFP3.l1.p1=C;
                                tCFP3.l1.p2=F;
                                tCFP3.l2.p1=C;
                                tCFP3.l2.p2=P3;
                                tCFP3.l3.p1=F;
                                tCFP3.l3.p2=P3;
                                tCFP3.sanjiaoxmianji(tCFP3);
                                Triangle tCP1P3=new Triangle();
                                tCP1P3.l1.p1=C;
                                tCP1P3.l1.p2=P1;
                                tCP1P3.l2.p1=C;
                                tCP1P3.l2.p2=P3;
                                tCP1P3.l3.p1=P1;
                                tCP1P3.l3.p2=P3;
                                tCP1P3.sanjiaoxmianji(tCP1P3);
                                double s1=tCFP3.S+tCP1P3.S;

                                Triangle tDP1P3=new Triangle();
                                tDP1P3.l1.p1=D;
                                tDP1P3.l1.p2=P1;
                                tDP1P3.l2.p1=D;
                                tDP1P3.l2.p2=P3;
                                tDP1P3.l3.p1=P1;
                                tDP1P3.l3.p2=P3;
                                tDP1P3.sanjiaoxmianji(tDP1P3);
                                Triangle tDEP3=new Triangle();
                                tDEP3.l1.p1=D;
                                tDEP3.l1.p2=E;
                                tDEP3.l2.p1=D;
                                tDEP3.l2.p2=P3;
                                tDEP3.l3.p1=E;
                                tDEP3.l3.p2=P3;
                                tDEP3.sanjiaoxmianji(tDEP3);
                                double s2=tDEP3.S+tDP1P3.S;
                                if(s1<s2)
                                    System.out.print(Math.round(s1*1000)/(double)1000+" "+Math.round(s2*1000)/(double)1000);
                                else
                                    System.out.print(Math.round(s2*1000)/(double)1000+" "+Math.round(s1*1000)/(double)1000);
                            }
                            else if(P1.flag==1&&P4.flag==1)
                            {
                                t.xiaomianji1(P1,P2,P3,P4,t,Q);
                                double s=Q.S-t.S;
                                if(t.S<s)
                                    System.out.print(Math.round(t.S*1000)/(double)1000+" "+Math.round(s*1000)/(double)1000);
                                else
                                    System.out.print(Math.round(s*1000)/(double)1000+" "+Math.round(t.S*1000)/(double)1000);
                            }
                            else if(P2.flag==1&&P3.flag==1)
                            {
                                t.xiaomianji1(P1,P2,P3,P4,t,Q);
                                double s=Q.S-t.S;
                                if(t.S<s)
                                    System.out.print(Math.round(t.S*1000)/(double)1000+" "+Math.round(s*1000)/(double)1000);
                                else
                                    System.out.print(Math.round(s*1000)/(double)1000+" "+Math.round(t.S*1000)/(double)1000);
                            }
                            else if(P2.flag==1&&P4.flag==1)
                            {
                                Triangle tCDP2=new Triangle();
                                tCDP2.l1.p1=C;
                                tCDP2.l1.p2=D;
                                tCDP2.l2.p1=C;
                                tCDP2.l2.p2=P2;
                                tCDP2.l3.p1=D;
                                tCDP2.l3.p2=P2;
                                tCDP2.sanjiaoxmianji(tCDP2);
                                Triangle tCP2P4=new Triangle();
                                tCP2P4.l1.p1=C;
                                tCP2P4.l1.p2=P2;
                                tCP2P4.l2.p1=C;
                                tCP2P4.l2.p2=P4;
                                tCP2P4.l3.p1=P2;
                                tCP2P4.l3.p2=P4;
                                tCP2P4.sanjiaoxmianji(tCP2P4);
                                double s1=tCDP2.S+tCP2P4.S;

                                Triangle tFP2P4=new Triangle();
                                tFP2P4.l1.p1=F;
                                tFP2P4.l1.p2=P2;
                                tFP2P4.l2.p1=F;
                                tFP2P4.l2.p2=P4;
                                tFP2P4.l3.p1=P2;
                                tFP2P4.l3.p2=P4;
                                tFP2P4.sanjiaoxmianji(tFP2P4);
                                Triangle tEFP2=new Triangle();
                                tEFP2.l1.p1=E;
                                tEFP2.l1.p2=F;
                                tEFP2.l2.p1=E;
                                tEFP2.l2.p2=P2;
                                tEFP2.l3.p1=F;
                                tEFP2.l3.p2=P2;
                                tEFP2.sanjiaoxmianji(tEFP2);
                                double s2=tFP2P4.S+tEFP2.S;
                                if(s1<s2)
                                    System.out.print(Math.round(s1*1000)/(double)1000+" "+Math.round(s2*1000)/(double)1000);
                                else
                                    System.out.print(Math.round(s2*1000)/(double)1000+" "+Math.round(s1*1000)/(double)1000);
                            }
                            else if(P3.flag==1&&P4.flag==1)
                            {
                                t.xiaomianji1(P1,P2,P3,P4,t,Q);
                                double s=Q.S-t.S;
                                if(t.S<s)
                                    System.out.print(Math.round(t.S*1000)/(double)1000+" "+Math.round(s*1000)/(double)1000);
                                else
                                    System.out.print(Math.round(s*1000)/(double)1000+" "+Math.round(t.S*1000)/(double)1000);
                            }
                        }
                    }
                    else//判断非三角形四边形情况
                    {
                        System.out.print("not a quadrilateral or triangle");
                    }
                    break;
                }

            case 5:
                {
                    Point A=new Point();
                    Point C=new Point();
                    Point D=new Point();
                    Point E=new Point();
                    Point F=new Point();
                    A.x=Double.valueOf(arr[1]);
                    A.y=Double.valueOf(arr[2]);
                    C.x=Double.valueOf(arr[3]);
                    C.y=Double.valueOf(arr[4]);
                    D.x=Double.valueOf(arr[5]);
                    D.y=Double.valueOf(arr[6]);
                    E.x=Double.valueOf(arr[7]);
                    E.y=Double.valueOf(arr[8]);
                    F.x=Double.valueOf(arr[9]);
                    F.y=Double.valueOf(arr[10]);
                    Quadrilateral Q=new Quadrilateral();
                    Q.l1.p1=C;
                    Q.l1.p2=D;
                    Q.l2.p1=D;
                    Q.l2.p2=E;
                    Q.l3.p1=E;
                    Q.l3.p2=F;
                    Q.l4.p1=C;
                    Q.l4.p2=F;
                    Q.l5.p1=D;
                    Q.l5.p2=F;
                    Q.l6.p1=C;
                    Q.l6.p2=E;
                    Triangle tDEF=new Triangle();
                    tDEF.l1.p1=D;
                    tDEF.l1.p2=E;
                    tDEF.l2.p1=E;
                    tDEF.l2.p2=F;
                    tDEF.l3.p1=D;
                    tDEF.l3.p2=F;
                    Triangle tCEF=new Triangle();
                    tCEF.l1.p1=C;
                    tCEF.l1.p2=E;
                    tCEF.l2.p1=E;
                    tCEF.l2.p2=F;
                    tCEF.l3.p1=C;
                    tCEF.l3.p2=F;
                    Triangle tCDF=new Triangle();
                    tCDF.l1.p1=C;
                    tCDF.l1.p2=D;
                    tCDF.l2.p1=D;
                    tCDF.l2.p2=F;
                    tCDF.l3.p1=C;
                    tCDF.l3.p2=F;
                    Triangle tCDE=new Triangle();
                    tCDE.l1.p1=C;
                    tCDE.l1.p2=D;
                    tCDE.l2.p1=D;
                    tCDE.l2.p2=E;
                    tCDE.l3.p1=C;
                    tCDE.l3.p2=E;
                    Point P1=new Point();
                    Point P2=new Point();
                    Point P3=new Point();
                    Point P4=new Point();
                    Line lAC=new Line();
                    lAC.p1=A;
                    lAC.p2=C;
                    Line lAD=new Line();
                    lAD.p1=A;
                    lAD.p2=D;
                    Line lAE=new Line();
                    lAE.p1=A;
                    lAE.p2=E;
                    Line lAF=new Line();
                    lAF.p1=A;
                    lAF.p2=F;

                    int num1=0,num2=0,num3=0,num4=0;
                    tDEF.whichsanjiaox1(C,D,E,F,tDEF,tCEF,tCDF,tCDE,Q);//判断是哪三个点构成三角形
                    if(tDEF.flag==1||C.pointchonghe(C,E))//求直线与三角形交点数
                    {
                        if(tDEF.pointwhere(A,D,E,lAD,lAE,Q.l2)||tDEF.pointwhere(A,E,F,lAE,lAF,Q.l3)||tDEF.pointwhere(A,D,F,lAD,lAF,Q.l5))
                        {
                            System.out.print("on the triangle");return;
                        }
                        tDEF.jiaodiannum(P1,P2,P3,lAD,tDEF);
                        num1=tDEF.num;
                        tDEF.jiaodiannum(P1,P2,P3,lAE,tDEF);
                        num2=tDEF.num;
                        tDEF.jiaodiannum(P1,P2,P3,lAF,tDEF);
                        num3=tDEF.num;
                        if(num1==2&&num2==2&&num3==2)
                            System.out.print("in the triangle");
                        else
                            System.out.print("outof the triangle");
                    }
                    else if(tCEF.flag==1||D.pointchonghe(D,F))
                    {
                        if(tCEF.pointwhere(A,C,E,lAC,lAE,Q.l6)||tCEF.pointwhere(A,E,F,lAE,lAF,Q.l3)||tCEF.pointwhere(A,C,F,lAC,lAF,Q.l4))
                        {
                            System.out.print("on the triangle");return;
                        }
                        tCEF.jiaodiannum(P1,P2,P3,lAC,tCEF);
                        num1=tCEF.num;
                        tCEF.jiaodiannum(P1,P2,P3,lAE,tCEF);
                        num2=tCEF.num;
                        tCEF.jiaodiannum(P1,P2,P3,lAF,tCEF);
                        num3=tCEF.num;
                        if(num1==2&&num2==2&&num3==2)
                            System.out.print("in the triangle");
                        else
                            System.out.print("outof the triangle");
                    }
                    else if(tCDF.flag==1||E.pointchonghe(E,C))
                    {
                        if(tCDF.pointwhere(A,C,D,lAC,lAD,Q.l1)||tCDF.pointwhere(A,D,F,lAD,lAF,Q.l5)||tCDF.pointwhere(A,C,F,lAC,lAF,Q.l4))
                        {
                            System.out.print("on the triangle");return;
                        }
                        tCDF.jiaodiannum(P1,P2,P3,lAC,tCDF);
                        num1=tCDF.num;
                        tCDF.jiaodiannum(P1,P2,P3,lAD,tCDF);
                        num2=tCDF.num;
                        tCDF.jiaodiannum(P1,P2,P3,lAF,tCDF);
                        num3=tCDF.num;
                        if(num1==2&&num2==2&&num3==2)
                            System.out.print("in the triangle");
                        else
                            System.out.print("outof the triangle");
                    }
                    else if(tCDE.flag==1||F.pointchonghe(F,D))
                    {
                        if(tCDE.pointwhere(A,C,D,lAC,lAD,Q.l1)|tCDE.pointwhere(A,D,E,lAD,lAE,Q.l2)||tCDE.pointwhere(A,C,E,lAC,lAE,Q.l6))
                        {
                            System.out.print("on the triangle");return;
                        }
                        tCDE.jiaodiannum(P1,P2,P3,lAC,tCDE);
                        num1=tCDE.num;
                        tCDE.jiaodiannum(P1,P2,P3,lAD,tCDE);
                        num2=tCDE.num;
                        tCDE.jiaodiannum(P1,P2,P3,lAE,tCDE);
                        num3=tCDE.num;
                        if(num1==2&&num2==2&&num3==2)
                            System.out.print("in the triangle");
                        else
                            System.out.print("outof the triangle");
                    }
                    else if(Q.l1.Quadrilateral2(C,D,E,F,Q))
                    {
                        Triangle t=new Triangle();
                        if(t.pointwhere(A,C,D,lAC,lAD,Q.l1)||t.pointwhere(A,D,E,lAD,lAE,Q.l2)||t.pointwhere(A,E,F,lAE,lAF,Q.l3)||t.pointwhere(A,C,F,lAC,lAF,Q.l4))
                        {
                            System.out.print("on the quadrilateral");return;
                        }

                        Triangle tACD=new Triangle();
                        tACD.l1.p1=A;
                        tACD.l1.p2=C;
                        tACD.l2.p1=A;
                        tACD.l2.p2=D;
                        tACD.l3.p1=C;
                        tACD.l3.p2=D;
                        Triangle tADE=new Triangle();
                        tADE.l1.p1=A;
                        tADE.l1.p2=D;
                        tADE.l2.p1=A;
                        tADE.l2.p2=E;
                        tADE.l3.p1=D;
                        tADE.l3.p2=E;
                        Triangle tAEF=new Triangle();
                        tAEF.l1.p1=A;
                        tAEF.l1.p2=E;
                        tAEF.l2.p1=A;
                        tAEF.l2.p2=F;
                        tAEF.l3.p1=E;
                        tAEF.l3.p2=F;
                        Triangle tACF=new Triangle();
                        tACF.l1.p1=A;
                        tACF.l1.p2=C;
                        tACF.l2.p1=A;
                        tACF.l2.p2=F;
                        tACF.l3.p1=C;
                        tACF.l3.p2=F;

                        Q.Quadrilateralmianji(Q);//四边形面积
                        tACD.sanjiaoxmianji(tACD);
                        tADE.sanjiaoxmianji(tADE);
                        tAEF.sanjiaoxmianji(tAEF);
                        tACF.sanjiaoxmianji(tACF);
                        double S;
                        S=tACD.S+tADE.S+tAEF.S+tACF.S;
                        if(S-Q.S<0.001)
                            System.out.print("in the quadrilateral");
                        else
                            System.out.print("outof the quadrilateral");
                    }
                    else
                        System.out.print("not a quadrilateral or triangle");

                    /*
                        Q.Quadrilateralnum(P1,P2,P3,P4,lAC,t,Q);
                        num1=Q.num;
                        Q.Quadrilateralnum(P1,P2,P3,P4,lAD,t,Q);
                        num2=Q.num;
                        Q.Quadrilateralnum(P1,P2,P3,P4,lAE,t,Q);
                        num3=Q.num;
                        Q.Quadrilateralnum(P1,P2,P3,P4,lAF,t,Q);
                        num4=Q.num;
                        System.out.println(num1+" "+num2+" "+num3+" "+num4);

                        if(num1==2&&num2==2&&num3==2&&num4==2)
                            System.out.print("in the quadrilateral");
                        else
                            System.out.print("outof the quadrilateral");
                    }
                    else
                        System.out.print("not a quadrilateral or triangle");
                        */

                    break;
                }
        }
    }
}

  Blog2:nchu-software-oop-2022-4+5+期中

虽然使用了面向对象的方法,但是创建类是并没有创建的很完善。

另外,很多内容还是挤在一起,没有去单独构造成函数。

*******************************************************************************************************************************************************

题目2:

7-1 点线形系列5-凸五边形的计算-1

分数 50
全屏浏览题目
切换布局
作者 蔡轲
单位 南昌航空大学

用户输入一组选项和数据,进行与五边形有关的计算。以下五边形顶点的坐标要求按顺序依次输入,连续输入的两个顶点是相邻顶点,第一个和最后一个输入的顶点相邻。选项包括:1:输入五个点坐标,判断是否是五边形,判断结果输出true/false。2:输入五个点坐标,判断是凹五边形(false)还是凸五边形(true),如果是凸五边形,则再输出五边形周长、面积,结果之间以一个英文空格符分隔。 若五个点坐标无法构成五边形,输出"not a pentagon"3:输入七个点坐标,前两个点构成一条直线,后五个点构成一个凸五边形、凸四边形或凸三角形,输出直线与五边形、四边形或三角形相交的交点数量。如果交点有两个,再按面积从小到大输出被直线分割成两部分的面积(不换行)。若直线与多边形形的一条边线重合,输出"The line is coincide with one of the lines"。若后五个点不符合五边形输入,若前两点重合,输出"points coincide"。

以上3选项中,若输入的点无法构成多边形,则输出"not a polygon"。输入的五个点坐标可能存在冗余,假设多边形一条边上两个端点分别是x、y,边线中间有一点z,另一顶点s:1)符合要求的输入:顶点重复或者z与xy都相邻,如:x x y s、x z y s、x y x s、s x y y。此时去除冗余点,保留一个x、一个y。2) 不符合要求的输入:z不与xy都相邻,如:z x y s、x z s y、x s z y

import java.util.Scanner;

class Point
{
    double x;
    double y;
    int exist=1;//1:存在0:不存在2:交点无数个
    int flag=0;
    public boolean pointchonghe(Point A,Point B)//判断两点重合
    {
        if(A.x==B.x&&A.y==B.y)
            return true;
        else
            return false;
    }
    public boolean Pointscoincide(Point A,Point B,Point C,Point D)//判断四边形四点重合
    {
        if(A.x==B.x&&A.y==B.y||A.x==C.x&&A.y==C.y||A.x==D.x&&A.y==D.y||B.x==C.x&&B.y==C.y||B.x==D.x&&B.y==D.y||C.x==D.x&&C.y==D.y)
            return true;
        else
            return false;
    }
}
//==========================================================================================================
class Line
{
    Point p1=new Point();
    Point p2=new Point();
    double a;
    double b;
    double c;
    double D;//线段距离

    public void L(Line l)//一般式系数
    {
        l.a=l.p2.y-l.p1.y;
        l.b=l.p1.x-l.p2.x;
        l.c=l.p2.x*l.p1.y-l.p1.x*l.p2.y;
    }
    public void distanse(Line l)//求线段距离D
    {
        l.D=Math.sqrt(Math.pow(l.p1.x-l.p2.x,2)+Math.pow(l.p1.y-l.p2.y,2));
        l.D=Math.round(l.D*1000000000)/(double)1000000000;
    }
    public void D(Point p1,Point p2,Line lp1p2)//两点间距离
    {
        lp1p2.D=Math.sqrt(Math.pow(lp1p2.p1.x-lp1p2.p2.x,2)+Math.pow(lp1p2.p1.y-lp1p2.p2.y,2));
        lp1p2.D=Math.round(lp1p2.D*1000000000)/(double)1000000000;
    }
    public boolean zhixian(Point X,Line l)//点是否在直线上
    {
        L(l);
        if(l.a*X.x+l.b*X.y+l.c==0)
            return true;
        else
            return false;
    }
    public boolean pingxing(Line l1,Line l2)//判断是否平行(有无交点)
    {
        L(l1);
        L(l2);
        if(l1.b==0&&l2.b==0)
            return true;
        else if(l1.b!=0&&l2.b!=0&&(l1.a/l1.b==l2.a/l2.b))
            return true;
        else
            return false;
    }
    public boolean linechonghe(Line l1,Line l2)//判断是否两线重合
    {
        L(l1);
        L(l2);
        if(l1.b==0&&l2.b==0)
        {
            if(l1.c/l1.a==l2.c/l2.a)
                return true;
            else
                return false;
        }
        else if(l1.a==0&&l2.a==0)
        {
            if(l1.c/l1.b==l2.c/l2.b)
                return true;
            else
                return false;
        }
        else
        {
            if(l1.c/l1.a==l2.c/l2.a&&l1.c/l1.b==l2.c/l2.b)
                return true;
            else
                return false;
        }
    }
    public void jiaodian(Line l1,Line l2,Point O)//两条直线交点
    {
        if(l1.pingxing(l1,l2))
        {
            O.exist=0;
            //System.out.println("@@@@@@@@");
        }
        else
        {
            l1.L(l1);
            l2.L(l2);
            O.x=(l1.b*l2.c-l2.b*l1.c)/(l1.a*l2.b-l2.a*l1.b);
            O.y=(l2.a*l1.c-l1.a*l2.c)/(l1.a*l2.b-l2.a*l1.b);
            O.x=Math.round(O.x*1000000000)/(double)1000000000;
            O.y=Math.round(O.y*1000000000)/(double)1000000000;
        }
    }
    public boolean pointwhere(Point A,Point B,Point C,Line lBC)//点A是否在线段BC上(含端点)
    {
        if(A.pointchonghe(A,B)||A.pointchonghe(A,C))
            return true;
        else
        {
            Line lAB=new Line();
            lAB.p1=A;
            lAB.p2=B;
            Line lAC=new Line();
            lAC.p1=A;
            lAC.p2=C;
            lAB.D(A,B,lAB);
            lAC.D(A,C,lAC);
            lBC.D(B,C,lBC);
            if(lAB.D+lAC.D-lBC.D<0.000001)
                return true;
            else
                return false;
        }
    }
    public boolean pointwhere1(Point A,Point B,Point C,Line lBC)//点A是否在线段BC上(不含端点)
    {
        if(A.pointchonghe(A,B)||A.pointchonghe(A,C))
            return false;
        else
        {
            Line lAB=new Line();
            lAB.p1=A;
            lAB.p2=B;
            Line lAC=new Line();
            lAC.p1=A;
            lAC.p2=C;
            lAB.D(A,B,lAB);
            lAC.D(A,C,lAC);
            lBC.D(B,C,lBC);
            if(lAB.D+lAC.D-lBC.D<0.000001)
                return true;
            else
                return false;
        }
    }
}
//=======================================================================================================
class Triangle
{
    Point p1=new Point();
    Point p2=new Point();
    Point p3=new Point();
    Line l1=new Line();
    Line l2=new Line();
    Line l3=new Line();
    double S;//面积
    int num;//交点数量
    int flag=0;//0:不存在/1-10:10种三角形组合

    public void Set(Point A,Point B,Point C,Triangle T)
    {
        T.p1=A;
        T.p2=B;
        T.p3=C;
    }
    public void Line(Point A,Point B,Point C,Triangle T)//newLine
    {
        T.l1.p1=A;
        T.l1.p2=B;
        T.l2.p1=B;
        T.l2.p2=C;
        T.l3.p1=A;
        T.l3.p2=C;
    }
    public boolean sanjiaox(Point A,Point B,Point C,Triangle T)//判断是否为三角形
    {
        T.Line(A,B,C,T);
        l1.distanse(l1);
        l2.distanse(l2);
        l3.distanse(l3);
        if((l1.D+l2.D>l3.D&&l1.D<=l3.D&&l2.D<=l3.D)||(l1.D+l3.D>l2.D&&l1.D<=l2.D&&l3.D<=l2.D)||(l2.D+l3.D>l1.D&&l2.D<=l1.D&&l2.D<=l1.D))
            return true;
        else
            return false;
    }
    public void sanjiaoxmianji(Triangle t)//三角形面积
    {
        t.Line(t.p1,t.p2,t.p3,t);
        t.l1.distanse(t.l1);
        t.l2.distanse(t.l

标签:

留言评论

  • 这篇文章还没有收到评论,赶紧来抢沙发吧~