解决方案 »

  1.   

    余弦定理:a平方=b平方+c平方—2*b*c*cosA
    这个算不算;
      

  2.   


    你要是能自己写个求cosA的算法而不用库函数,就算你解决问题了。
      

  3.   

    public static void main(String[] args) {
    System.out.println(isRectangle(3,1,2,-1,0,0,1,2));
    } public static boolean isRectangle(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4) {
    return (isRightangle(x1, y1, x2, y2, x4, y4) && isRightangle(x3, y3, x2, y2, x4, y4))
    ||(isRightangle(x1, y1, x2, y2, x3, y3) && isRightangle(x4, y4, x2, y2, x3, y3))
    ||(isRightangle(x1, y1, x3, y3, x4, y4) && isRightangle(x2, y2, x3, y3, x4, y4));
    } public static boolean isRightangle(double x1, double y1, double x2, double y2, double x3, double y3) {
    return (x2 - x1) * (x3 - x1) + (y2 - y1) * (y3 - y1) == 0.0;
    }
      

  4.   


    对于输入System.out.println(isRectangle(7,0,161,47,7,0,161,0)),输出是true。但是应该输出false吧?
      

  5.   

    把他们放在一个数组里array[0] = {p1, p2, p3, p4} 排序,先y后x,那么array[0].y == array[1].y,...,如果不满足则不能。
      

  6.   

    考虑有重复点的话那么就这样变下
    public static void main(String[] args) {
    System.out.println(isRectangle(1,1,23,-18,11,-23,13,6));
    } public static boolean isRectangle(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4) {
    return (isRightangle(x1, y1, x2, y2, x4, y4) && isRightangle(x3, y3, x2, y2, x4, y4))
    || (isRightangle(x1, y1, x2, y2, x3, y3) && isRightangle(x4, y4, x2, y2, x3, y3))
    || (isRightangle(x1, y1, x3, y3, x4, y4) && isRightangle(x2, y2, x3, y3, x4, y4));
    } public static boolean isRightangle(double x1, double y1, double x2, double y2, double x3, double y3) {
    return !(((x1 == x2) && (y1 == y2)) || ((x1 == x3) && (y1 == y3)))
    && (x2 - x1) * (x3 - x1) + (y2 - y1) * (y3 - y1) == 0.0;
    }
      

  7.   

    上面的只判断了对角直角,用3个直角才行,或者换个思路,用平行+直角判断。
    public static void main(String[] args) {
    System.out.println(isRectangle(1, 1, 23, -18, 13, 6, 11, -23));
    } public static boolean isRectangle(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4) {
    return (isRightangle(x1, y1, x2, y2, x4, y4) && x1 + x3 == x2 + x4 && y1 + y3 == y2 + y4)
    || (isRightangle(x1, y1, x2, y2, x3, y3) && x1 + x4 == x2 + x3 && y1 + y4 == y2 + y2)
    || (isRightangle(x1, y1, x3, y3, x4, y4) && x1 + x2 == x3 + x4 && y1 + y2 == y3 + y4);
    } public static boolean isRightangle(double x1, double y1, double x2, double y2, double x3, double y3) {
    return !(((x1 == x2) && (y1 == y2)) || ((x1 == x3) && (y1 == y3)))
    && (x2 - x1) * (x3 - x1) + (y2 - y1) * (y3 - y1) == 0.0;
    }
      

  8.   

    打错个数字
    public static void main(String[] args) {
    System.out.println(isRectangle(1, 1, 23, -18, 13, 6, 11, -23));
    } public static boolean isRectangle(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4) {
    return (isRightangle(x1, y1, x2, y2, x4, y4) && x1 + x3 == x2 + x4 && y1 + y3 == y2 + y4)
    || (isRightangle(x1, y1, x2, y2, x3, y3) && x1 + x4 == x2 + x3 && y1 + y4 == y2 + y3)
    || (isRightangle(x1, y1, x3, y3, x4, y4) && x1 + x2 == x3 + x4 && y1 + y2 == y3 + y4);
    } public static boolean isRightangle(double x1, double y1, double x2, double y2, double x3, double y3) {
    return !(((x1 == x2) && (y1 == y2)) || ((x1 == x3) && (y1 == y3)))
    && (x2 - x1) * (x3 - x1) + (y2 - y1) * (y3 - y1) == 0.0;
    }