Skip to content

Commit b201776

Browse files
committed
Better Welzl
1 parent f30375b commit b201776

2 files changed

Lines changed: 10 additions & 13 deletions

File tree

‎code/geometry/welzl.cpp‎

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
11
#include "circles.cpp"
22
vector<point> wP, wR;
33
pair<point,double> welzl() {
4-
point res;
54
if (wP.empty() || wR.size() == 3) {
6-
if (wR.empty()) { }
7-
else if (wR.size() == 1) res = wR[0];
8-
else if (wR.size() == 2) res = (wR[0] + wR[1])/2.0;
9-
else if (abs(cross(wR[1]-wR[0], wR[2]-wR[0])) < EPS) {
10-
double mx = -INFINITY, d;
5+
if (wR.empty()) return make_pair(point(), 0);
6+
if (wR.size() == 1) return make_pair(wR[0], 0);
7+
if (wR.size() == 2) return make_pair((wR[0]+wR[1])/2.0,
8+
abs(wR[0]-wR[1])/2);
9+
if (abs(cross(wR[1]-wR[0], wR[2]-wR[0])) < EPS) {
10+
point res; double mx = -INFINITY, d;
1111
rep(i,0,3) rep(j,i+1,3)
1212
if ((d = abs(wR[i] - wR[j])) > mx)
13-
mx = d, res = (wR[i] + wR[j]) / 2.0; }
14-
else res = circumcircle(wR[0], wR[1], wR[2]).first;
15-
double mx = 0.0;
16-
iter(it,wP) mx = max(mx, abs(res - *it));
17-
iter(it,wR) mx = max(mx, abs(res - *it));
18-
return make_pair(res, mx); }
13+
mx = d, res = (wR[i] + wR[j]) / 2.0;
14+
return make_pair(res, mx/2.0); }
15+
return circumcircle(wR[0], wR[1], wR[2]); }
1916
swap(wP[rand() % wP.size()], wP.back());
20-
res = wP.back(); wP.pop_back();
17+
point res = wP.back(); wP.pop_back();
2118
pair<point,double> D = welzl();
2219
if (abs(res - D.first) > D.second + EPS) {
2320
wR.push_back(res); D = welzl(); wR.pop_back();

‎comprog.pdf‎

31 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)