1.前言
pta第四次作业总共有3题,题量不是很多。其中,1、3题比较简单,第二题难度较大,第1题考察的正则表达式,第3题考察的是类的使用,第2题考查了关于四边形的算法,正则表达式以及类的使用,难度较大。
pta第五次作业总共有2题,实际上2题都是关于五边形的算法,可以看作为1题,题目难度很难,主要是关于五边形(多边形)的算法和正则表达式。
期中作业总共有3题,题量不是很多。3题层层递进,每题在前一题的基础上有所增加,整体难度不难。第一题考察的是类设计方面的知识,难度低,只需要根据题目给出的类图以及题意,使用Java类设计的方法和语法语句就能够完成。第二题考察的是继承与多态方面的知识,难度较低。第三题考察的是容器类方面的知识,创建一个容器存入Element类对象,根据类图和题意,创建相应方法能够完成该题目。
2.设计与分析
7-2 点线形系列4-凸四边形的计算
用户输入一组选项和数据,进行与四边形有关的计算。
以下四边形顶点的坐标要求按顺序依次输入,连续输入的两个顶点是相邻顶点,第一个和最后一个输入的顶点相邻。
选项包括:
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 y
5:输入五个点坐标,输出第一个是否在后四个点所构成的四边形(限定为凸四边形,不考虑凹四边形)或三角形(判定方法见选项4)的内部(若是四边形输出in the quadrilateral/outof the quadrilateral,若是三角形输出in the triangle/outof the triangle)。如果点在多边形的某条边上,输出"on the triangle或者on the quadrilateral"。若后四个点不符合四边形或三角形,输出"not a quadrilateral or triangle"。
输入格式:
基本格式:选项+":"+坐标x+","+坐标y+" "+坐标x+","+坐标y。点的x、y坐标之间以英文","分隔,点与点之间以一个英文空格分隔。
输出格式:
基本输出格式见每种选项的描述。
异常情况输出:
如果不符合基本格式,输出"Wrong Format"。
如果符合基本格式,但输入点的数量不符合要求,输出"wrong number of points"。
注意:输出的数据若小数点后超过3位,只保留小数点后3位,多余部分采用四舍五入规则进到最低位。小数点后若不足3位,按原始位数显示,不必补齐。例如:1/3的结果按格式输出为 0.333,1.0按格式输出为1.0
选项1、2、3中,若四边形四个点中有重合点,输出"points coincide"。
选项4中,若前两个输入线的点重合,输出"points coincide"。
输入样例1:
选项1,点重合。例如:
1:-1,-1 -1,-1 1,2 1,-2
输出样例:
在这里给出相应的输出。例如:
points coincide
输入样例2:
不符合基本格式。例如:
1:-1,-1 1,2 -1,1 ++1,0
输出样例:
在这里给出相应的输出。例如:
Wrong Format
输入样例3:
选项1,输入点数量不对。例如:
1:-1,-1 -1,2
输出样例:
在这里给出相应的输出。例如:
wrong number of points
输入样例4:
选项1,正确输入判断。例如:
1:-1,-1 -1,1 1,2 1,-2
输出样例:
在这里给出相应的输出。例如:
true false
输入样例5:
选项2,输入点不构成四边形。例如:
2:10,10 1,1 0,0 1,20
输出样例:
在这里给出相应的输出。例如:
not a quadrilateral
输入样例6:
选项2,正方形。例如:
2:0,0 0,80 80,80 80,0
输出样例:
在这里给出相应的输出。例如:
true true true
输入样例7:
选项2。例如:
2:0,0 -10,80 0,160 -10,80
输出样例:
在这里给出相应的输出。例如:
not a quadrilateral
输入样例8:
选项3,凸四边形。例如:
3:-1,-1 -1,1 1,2 1,-2
输出样例:
在这里给出相应的输出。例如:
true 10.472 6.0
输入样例9:
选项3,。例如:
3:0,0 -10,100 0,99 10,100
输出样例:
在这里给出相应的输出。例如:
false 221.097 990.0
我的代码:
import javax.print.DocFlavor; import java.util.Scanner; import java.text.DecimalFormat; public class Main { public static void main(String[] args) { DecimalFormat d = new DecimalFormat("0.0##"); Scanner input = new Scanner(System.in); String str = input.nextLine(); char[] a = new char[50]; if (!str.matches("^[1-5]:(([+-]?(0(\\.\\d+)?|[1-9][0-9]*(\\.\\d+)?)),([+-]?(0(\\.\\d+)?|[1-9][0-9]*(\\.\\d+)?)) )*(([+-]?(0(\\.\\d+)?|[1-9][0-9]*(\\.\\d+)?)),([+-]?(0(\\.\\d+)?|[1-9][0-9]*(\\.\\d+)?))) *" )) System.out.println("Wrong Format"); else { a = str.toCharArray(); if (a[1] == ':') { String[] str1 = str.split(":"); String[] str2 = str1[1].split(" "); double x1, y1, x2, y2, x3, y3, x4, y4, x5, y5, x6, y6; boolean b = true; for (int i = 0; i < str2.length; i++) { b = geshi(str2[i]); if (!b) break; } switch (a[0]) { case '1': if (str2.length == 4) { String[] s0 = str2[0].split(",");//x1,y1 String[] s1 = str2[1].split(",");//x2,y2 String[] s2 = str2[2].split(",");//x3,y3 String[] s3 = str2[3].split(",");//x4,y4 x1 = Double.parseDouble(s0[0]); y1 = Double.parseDouble(s0[1]); x2 = Double.parseDouble(s1[0]); y2 = Double.parseDouble(s1[1]); x3 = Double.parseDouble(s2[0]); y3 = Double.parseDouble(s2[1]); x4 = Double.parseDouble(s3[0]); y4 = Double.parseDouble(s3[1]); dian A = new dian(x1, y1); dian B = new dian(x2, y2); dian C = new dian(x3, y3); dian D = new dian(x4, y4); sibianxing m = new sibianxing(); if (A.chonghe(B) || A.chonghe(C) || A.chonghe(D) || B.chonghe(C) || B.chonghe(D) || C.chonghe(D)) System.out.println("points coincide"); else { if (m.panduan(A, B, C, D)) System.out.print("true "); else System.out.print("false "); if (m.pingxing(A, B, C, D)) System.out.println("true"); else System.out.println("false"); } } else System.out.println("wrong number of points"); break; case '2': if (str2.length == 4) { String[] s0 = str2[0].split(",");//x1,y1 String[] s1 = str2[1].split(",");//x2,y2 String[] s2 = str2[2].split(",");//x3,y3 String[] s3 = str2[3].split(",");//x4,y4 x1 = Double.parseDouble(s0[0]); y1 = Double.parseDouble(s0[1]); x2 = Double.parseDouble(s1[0]); y2 = Double.parseDouble(s1[1]); x3 = Double.parseDouble(s2[0]); y3 = Double.parseDouble(s2[1]); x4 = Double.parseDouble(s3[0]); y4 = Double.parseDouble(s3[1]); dian A = new dian(x1, y1); dian B = new dian(x2, y2); dian C = new dian(x3, y3); dian D = new dian(x4, y4); sibianxing m = new sibianxing(); if (!m.panduan(A, B, C, D)) System.out.println("not a quadrilateral"); else { if (!A.chonghe(B) || !A.chonghe(C) || !A.chonghe(D) || !B.chonghe(C) || !B.chonghe(D) || !C.chonghe(D)) { if (m.lingxing(A, B, C, D)) System.out.print("true "); else System.out.print("false "); if (m.juxing(A, B, C, D)) System.out.print("true "); else System.out.print("false "); if (m.zhengfangxing(A, B, C, D)) System.out.println("true"); else System.out.println("false"); } else System.out.println("points coincide"); } } else System.out.println("wrong number of points"); break; case '3': if (str2.length == 4) { String[] s0 = str2[0].split(",");//x1,y1 String[] s1 = str2[1].split(",");//x2,y2 String[] s2 = str2[2].split(",");//x3,y3 String[] s3 = str2[3].split(",");//x4,y4 x1 = Double.parseDouble(s0[0]); y1 = Double.parseDouble(s0[1]); x2 = Double.parseDouble(s1[0]); y2 = Double.parseDouble(s1[1]); x3 = Double.parseDouble(s2[0]); y3 = Double.parseDouble(s2[1]); x4 = Double.parseDouble(s3[0]); y4 = Double.parseDouble(s3[1]); dian A = new dian(x1, y1); dian B = new dian(x2, y2); dian C = new dian(x3, y3); dian D = new dian(x4, y4); sibianxing m = new sibianxing(); if (A.chonghe(B) || A.chonghe(C) || A.chonghe(D) || B.chonghe(C) || B.chonghe(D) || C.chonghe(D)) System.out.println("points coincide"); else { if (m.panduan(A, B, C, D)) { if (m.aotu(A, B, C, D)) System.out.print("true "); else System.out.print("false "); System.out.println(d.format(m.zhouchang(A, B, C, D)) + " " + d.format(m.mianji(A, B, C, D))); } else System.out.println("not a quadrilateral"); } } else System.out.println("wrong number of points"); break; case '4': if (str2.length == 6) { String[] s0 = str2[0].split(",");//x1,y1 String[] s1 = str2[1].split(",");//x2,y2 String[] s2 = str2[2].split(",");//x3,y3 String[] s3 = str2[3].split(",");//x4,y4 String[] s4 = str2[4].split(",");//x5,y5 String[] s5 = str2[5].split(",");//x6,y6 x1 = Double.parseDouble(s0[0]); y1 = Double.parseDouble(s0[1]); x2 = Double.parseDouble(s1[0]); y2 = Double.parseDouble(s1[1]); x3 = Double.parseDouble(s2[0]); y3 = Double.parseDouble(s2[1]); x4 = Double.parseDouble(s3[0]); y4 = Double.parseDouble(s3[1]); x5 = Double.parseDouble(s4[0]); y5 = Double.parseDouble(s4[1]); x6 = Double.parseDouble(s5[0]); y6 = Double.parseDouble(s5[1]); dian A = new dian(x1, y1); dian B = new dian(x2, y2); dian C = new dian(x3, y3); dian D = new dian(x4, y4); dian E = new dian(x5, y5); dian F = new dian(x6, y6); xian l = new xian(); sibianxing m = new sibianxing(); sanjiaoxing n = new sanjiaoxing(); if (A.x == B.x && A.y == B.y) System.out.println("points coincide"); else if (l.zhixianchonghe(A, B, C, D) || l.zhixianchonghe(A, B, D, E) || l.zhixianchonghe(A, B, E, F) || l.zhixianchonghe(A, B, F, C)) { System.out.println("The line is coincide with one of the lines"); return; } else if (m.panduan(C, D, E, F)) { if (m.zhixiansibianxingjiaodian(A, B, C, D, E, F) == 0) System.out.println("0"); else if (m.zhixiansibianxingjiaodian(A, B, C, D, E, F) == 1) System.out.println("1"); else if (m.zhixiansibianxingjiaodian(A, B, C, D, E, F) == 2) System.out.println("2 "); } else if (m.sanjiaoxing(C, D, E, F)) { } else if (m.sanjiaoxing(D, E, F, C)) { } else if (m.sanjiaoxing(E, F, C, D)) { } else if (m.sanjiaoxing(F, E, C, D)) { } else System.out.println("not a quadrilateral or triangle"); } else System.out.println("wrong number of points"); break; case '5': if (str2.length == 5) { String[] s0 = str2[0].split(",");//x1,y1 String[] s1 = str2[1].split(",");//x2,y2 String[] s2 = str2[2].split(",");//x3,y3 String[] s3 = str2[3].split(",");//x4,y4 String[] s4 = str2[4].split(",");//x5,y5 x1 = Double.parseDouble(s0[0]); y1 = Double.parseDouble(s0[1]); x2 = Double.parseDouble(s1[0]); y2 = Double.parseDouble(s1[1]); x3 = Double.parseDouble(s2[0]); y3 = Double.parseDouble(s2[1]); x4 = Double.parseDouble(s3[0]); y4 = Double.parseDouble(s3[1]); x5 = Double.parseDouble(s4[0]); y5 = Double.parseDouble(s4[1]); dian A = new dian(x1, y1); dian B = new dian(x2, y2); dian C = new dian(x3, y3); dian D = new dian(x4, y4); dian E = new dian(x5, y5); xian l = new xian(); sibianxing m = new sibianxing(); sanjiaoxing n = new sanjiaoxing(); if (!m.panduan(B, C, D, E) && !m.sanjiaoxing(B, C, D, E) && !m.sanjiaoxing(C, D, E, B) && !m.sanjiaoxing(D, E, B, C) && !m.sanjiaoxing(E, B, C, D) && !B.chonghe(C) && !B.chonghe(D) && !B.chonghe(E) && !D.chonghe(C) && !E.chonghe(C) && !D.chonghe(E)) System.out.println("not a quadrilateral or triangle"); if (m.panduan(B, C, D, E)) { if (l.dianzaixianduanshang(A, B, C) || l.dianzaixianduanshang(A, C, D) || l.dianzaixianduanshang(A, D, E) || l.dianzaixianduanshang(A, E, B)) System.out.println("on the quadrilateral"); else if (m.dianzaimiannei(B, C, D, E, A)) System.out.println("in the quadrilateral"); else System.out.println("outof the quadrilateral"); } else if // (m.sanjiaoxing(B, C, D, E)) { // dian[] dians = m.fanhuishanjiaoxing(B, C, D, E); // n.shuchudianmian(A, dians[0], dians[1], dians[2]); // return; (m.sanjiaoxing(B, C, D, E) || C.chonghe(E)) { n.shuchudianmian(A, B, D, E); } else if (m.sanjiaoxing(C, D, E, B) || D.chonghe(B)) { n.shuchudianmian(A, C, E, B); } else if (m.sanjiaoxing(D, E, B, C) || E.chonghe(C)) { n.shuchudianmian(A, D, B, C); } else if (m.sanjiaoxing(E, B, C, D) || B.chonghe(D)) { n.shuchudianmian(A, E, C, D); } } else System.out.println("wrong number of points"); break; default: System.out.println("Wrong Format"); break; } } else System.out.println("Wrong Format"); } } public static boolean geshi(String a) { String[] b = a.split(" "); boolean flag = true; String regex = "^[+-]?(0|(0\\\\.\\\\d+)?|[1-9][0-9]*(\\\\.\\\\d+)?)$"; for (int i = 0; i < b.length; i++) { flag = b[i].matches(regex); if (!flag) break; } if (flag) { return true; } else return false; } } class dian { double x, y; dian(double x, double y) { this.x = x; this.y = y; } boolean chonghe(dian p2) { if (this.x == p2.x && p2.y == this.y) return true; else return false; } double changdu(dian p2) { double d1 = Math.pow(p2.x - this.x, 2); double d2 = Math.pow(p2.y - this.y, 2); return Math.pow(d2 + d1, 0.5); } double k(dian p2) { return (y - p2.y) / (x - p2.x); } } class xian { //线段AC与BD的交点是否在线段上 boolean xianduanjioadian(dian A, dian B, dian C, dian D) { double x, y; y = (B.x * C.y * D.y - D.x * B.y * C.y - A.y * B.x * D.y + D.x * B.y * A.y + C.x * A.y * D.y - A.x * C.y * D.y - C.x * B.y * A.y + A.x * B.y * C.y) / (D.y * C.x - A.x * D.y - B.y * C.x + A.x * B.y + B.x * C.y - D.x * C.y - A.y * B.x + A.y * D.x); x = (D.y * (C.x - A.x) * (B.x - D.x) - A.y * (C.x - A.x) * (B.x - D.x) + A.x * (C.y - A.y) * (B.x - D.x) + D.x * (D.y - B.y) * (C.x - A.x)) / ((C.y - A.y) * (B.x - D.x) + (D.y - B.y) * (C.x - A.x)); if (B.x > D.x && A.x > C.x) { if (x < B.x && x > D.x && x < A.x && x > C.x) return true; else return false; } if (B.x < D.x && A.x > C.x) { if (x > B.x && x < D.x && x < A.x && x > C.x) return true; else return false; } if (B.x < D.x && A.x < C.x) { if (x > B.x && x < D.x && x > A.x && x < C.x) return true; else return false; } if (B.x > D.x && A.x < C.x) { if (x < B.x && x > D.x && x > A.x && x < C.x) return true; else return false; } if (B.x < D.x && A.x > C.x) { if (x > B.x && x < D.x && x > A.x && x < C.x) return true; else return false; } else return false; } dian xianduanjioafanhuidian(dian A, dian B, dian C, dian D) { double x, y; y = (B.x * C.y * D.y - D.x * B.y * C.y - A.y * B.x * D.y + D.x * B.y * A.y + C.x * A.y * D.y - A.x * C.y * D.y - C.x * B.y * A.y + A.x * B.y * C.y) / (D.y * C.x - A.x * D.y - B.y * C.x + A.x * B.y + B.x * C.y - D.x * C.y - A.y * B.x + A.y * D.x); x = (D.y * (C.x - A.x) * (B.x - D.x) - A.y * (C.x - A.x) * (B.x - D.x) + A.x * (C.y - A.y) * (B.x - D.x) + D.x * (D.y - B.y) * (C.x - A.x)) / ((C.y - A.y) * (B.x - D.x) + (D.y - B.y) * (C.x - A.x)); dian dian = new dian(x, y); return dian; } //交点是否在线段CD上 boolean jiaodianzaixianduanshang(dian A, dian B, dian C, dian D) { if (C.x > D.x) { if (xianduanjioafanhuidian(A, B, C, D).x > D.x && xianduanjioafanhuidian(A, B, C, D).x < C.x) return true; else return false; } else if (C.x < D.x) { if (xianduanjioafanhuidian(A, B, C, D).x < D.x && xianduanjioafanhuidian(A, B, C, D).x > C.x) return true; else return false; } else return false; } boolean dianzaixiangshang(dian A, dian B, dian C) { if (A.x == B.x && B.x == C.x && A.x == C.x) return true; else { if (Math.abs(A.k(B) - B.k(C)) < 1e-6) return true; else return false; } } //点A在线段BC上 boolean dianzaixianduanshang(dian A, dian B, dian C) { if (dianzaixiangshang(A, B, C)) { if (B.x < C.x) if (B.x <= A.x && A.x <= C.x) return true; else return false; else if (B.x > C.x) if (B.x >= A.x && A.x >= C.x) return true; else return false; else return false; } else return false; } boolean zhixianchonghe(dian A, dian B, dian C, dian D) { if ((Math.abs(A.k(B) - C.k(D)) < 1e-6 && dianzaixiangshang(A, C, D))) return true; else return false; } } class sanjiaoxing { double mianji(dian A, dian B, dian C) { double a, b, c, p; a = C.changdu(B); b = A.changdu(C); c = A.changdu(B); p = (A.changdu(B) + C.changdu(B) + A.changdu(C)) / 2; return Math.pow(p * (p - a) * (p - b) * (p - c), 0.5); } //点A是否在三角形BCD内 boolean dianzaimiannei(dian A, dian B, dian C, dian D) { if (Math.abs((mianji(A, B, D) + mianji(A, C, D) + mianji(A, B, C)) - mianji(B, C, D)) < 1e-6) return true; else return false; } //点A与三角形的关系 void shuchudianmian(dian A, dian B, dian C, dian D) { xian l = new xian(); if (l.dianzaixianduanshang(A, B, C) || l.dianzaixianduanshang(A, B, D) || l.dianzaixianduanshang(A, C, D)) System.out.println("on the triangle"); else if (dianzaimiannei(A, B, C, D)) System.out.println("in the triangle"); else System.out.println("outof the triangle"); } } class sibianxing { xian l1 = new xian(); boolean panduan(dian A, dian B, dian C, dian D) { if (!l1.xianduanjioadian(A, C, B, D) && !l1.xianduanjioadian(C, A, B, D) && Math.abs(A.k(B) - C.k(B)) > 1e-6 && Math.abs(C.k(B) - C.k(D)) > 1e-6 && Math.abs(C.k(D) - A.k(D)) > 1e-6) { return true; } else return false; } boolean pingxing(dian A, dian B, dian C, dian D) { if ((Math.abs((A.x + C.x) - (B.x + D.x)) < 1e-6) && (Math.abs((A.y + C.y) - (B.y + D.y)) < 1e-6)) { return true; } else return false; } boolean lingxing(dian A, dian B, dian C, dian D) { if (A.changdu(B) == A.changdu(D) && A.changdu(D) == B.changdu(C) && A.changdu(B) == D.changdu(C)) return true; else return false; } boolean juxing(dian A, dian B, dian C, dian D) { if (A.changdu(C) == B.changdu(D)) return true; else return false; } boolean zhengfangxing(dian A, dian B, dian C, dian D) { if (lingxing(A, B, C, D) && juxing(A, B, C, D)) return true; else return false; } boolean aotu(dian A, dian B, dian C, dian D) { sanjiaoxing sjx = new sanjiaoxing(); double s1, s2; s1 = (sjx.mianji(A, B, C) + sjx.mianji(A, C, D)); s2 = (sjx.mianji(A, B, D) + sjx.mianji(B, C, D)); if (Math.abs(s1 - s2) < 1e-6) return true; else return false; } double zhouchang(dian A, dian B, dian C, dian D) { return A.changdu(B) + B.changdu(C) + C.changdu(D) + D.changdu(A); } double mianji(dian A, dian B, dian C, dian D) { sanjiaoxing sjx = new sanjiaoxing(); double s1, s2; s1 = (sjx.mianji(A, B, C) + sjx.mianji(A, C, D)); s2 = (sjx.mianji(A, B, D) + sjx.mianji(B, C, D)); if (Math.abs(s1 - s2) < 1e-6) return s1; else if (s1 > s2) return s2; else return s1; } //点E是否在四边形面内 boolean dianzaimiannei(dian A, dian B, dian C, dian D, dian E) { sanjiaoxing a = new sanjiaoxing(); if (Math.abs((a.mianji(A, B, E) + a.mianji(B, C, E) + a.mianji(C, D, E) + a.mianji(D, A, E)) - mianji(A, B, C, D)) < 1e-6) return true; else return false; } //是否能构成三角形 boolean sanjiaoxing(dian A, dian B, dian C, dian D) { xian l = new xian(); // if (ac.dianzaixianduanshang(A, B, D) || ac.dianzaixianduanshang(C, B, D) || ac.dianzaixianduanshang(B, A, C) || ac.dianzaixianduanshang(D, A, C)) // return true; // return false; if (!A.chonghe(B) || !A.chonghe(C) || !A.chonghe(D) || !B.chonghe(C) || !B.chonghe(D) || !C.chonghe(D)) if (l.dianzaixianduanshang(B, A, C) && Math.abs((A.changdu(B) + B.changdu(C)) - A.changdu(C)) <= 1e-6) return true; else return false; else if (B.chonghe(D)) return true; else return false; } dian[] fanhuishanjiaoxing(dian A, dian B, dian C, dian D) { dian[] dians = new dian[3]; xian ac = new xian(); int num = 0; if (!ac.dianzaixianduanshang(A, B, D)) dians[num++] = A; if (ac.dianzaixianduanshang(C, B, D)) dians[num++] = C; if (ac.dianzaixianduanshang(B, A, C)) dians[num++] = B; if (ac.dianzaixianduanshang(D, A, C)) dians[num++] = D; return dians; } //点A与点B重合构成三角形A(B)CD boolean chsanjiaoxing(dian A, dian B, dian C, dian D) { if (A.chonghe(B)) return true; else return false; } int zhixiansibianxingjiaodian(dian A, dian B, dian C, dian D, dian E, dian F) { int i = 0; if (l1.jiaodianzaixianduanshang(A, B, C, D)) i++; else if (l1.jiaodianzaixianduanshang(A, B, D, E)) i++; else if (l1.jiaodianzaixianduanshang(A, B, E, F)) i++; else if (l1.jiaodianzaixianduanshang(A, B, F, C)) i++; return i; } }
总结:本题先用正则表达式判断是否输入正确,判断四边形可以采用邻边相交,对边不相交。判断凹凸性可以判断对角线切割的两个三角形面积和是否等于四边形面积,若不相等,则为凹,反之,则为凸。判断交点可以不用射线法,可以线的切割点有几个在线上。点与面的位置判断,先判断点是否在线上,再用点与各边组成的三角形的面积是否等于四边形的面积是否相等,相等则在面内,反之,在面外。
标签:dian,return,Double,parseDouble,else,BLOG,&&
From: https://www.cnblogs.com/wuwuwang/p/16836633.html