日期:2014-05-20  浏览次数:20665 次

二维直角坐标系,输入四个点的坐标(x1, y1), (x2, y2), (x3, y3), (x4, y4)。写一算法,判断这四个点是不是能够围成一个矩形
如题。
每个点的坐标值都是double型(四则运算可以认为不损失精度)。要求:不能使用开平方运算。
------解决方案--------------------
打错个数字。。。
	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;
}