最小距离问题 (三)

2014-11-24 10:51:00 · 作者: · 浏览: 2
p);
if (r4.isIn(p))
t4.add(p);
}

double d1 = f(t1, r1);
double d2 = f(t2, r2);
double d3 = f(t3, r3);
double d4 = f(t4, r4);
double d = d1;
if (d2 < d)
d = d2;
if (d3 < d)
d = d3;
if (d4 < d)
d = d4;

return d;
}

public static double distance(PP a1, PP b1) {
double dx = Math.abs(a1.x - b1.x);
double dy = Math.abs(a1.y - b1.y);
return Math.sqrt(dx * dx + dy * dy);
}

public static double distance(PP a, PP b, PP c, PP d) {
double dis = (distance(a, b) + distance(a, c) + distance(a, d)
+ distance(b, c) + distance(b, d) + distance(c, d)) / 6.0;
return dis;
}

public static List readPoints(String fname) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(
new FileInputStream(fname)));
List lis = new Vector();
for (;;) {
String s = br.readLine();
if (s == null)
break;

String[] ss = s.split(",");
PP e = new PP(0, 0);
e.x = Integer.parseInt(ss[0]);
e.y = Integer.parseInt(ss[1]);
lis.add(e);
}
br.close();
return lis;

}

public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
List lis = readPoints("in.txt");
double x = f(lis, new RR(0, 0, 1000, 1000));
System.out.printf("%.2f",x);
}
}