Написал надёжный алгоритм поиска наименьшего круга
This commit is contained in:
parent
b36187b77d
commit
b24722eefc
5 changed files with 90 additions and 6 deletions
53
ComputationalGeometry/6Ex/hope.c
Normal file
53
ComputationalGeometry/6Ex/hope.c
Normal file
|
@ -0,0 +1,53 @@
|
|||
#include "hope.h"
|
||||
|
||||
circle hope(point * ps, int length) {
|
||||
circle crcl;
|
||||
|
||||
for (int i = 0; i < length; ++i) {
|
||||
point temp = ps[i];
|
||||
ps[i] = ps[length - 1];
|
||||
ps[length - 1] = temp;
|
||||
|
||||
for (int j = 0; j < length - 1; ++j) {
|
||||
crcl = centermass(temp, ps[i]);
|
||||
if (isSuit(crcl, ps, length - 1)) return crcl;
|
||||
}
|
||||
|
||||
ps[length - 1] = ps[i];
|
||||
ps[i] = temp;
|
||||
}
|
||||
|
||||
for (int i = 0; i < length; ++i) {
|
||||
point temp = ps[i];
|
||||
ps[i] = ps[length - 1];
|
||||
ps[length - 1] = temp;
|
||||
|
||||
for (int j = 0; j < length - 1; ++j) {
|
||||
temp = ps[j];
|
||||
ps[j] = ps[length - 2];
|
||||
ps[length - 2] = temp;
|
||||
|
||||
for (int k = 0; k < length - 2; ++k) {
|
||||
point warp[] = {ps[length - 1], ps[length - 2], ps[k]};
|
||||
crcl = byThreePoints(warp);
|
||||
|
||||
if (fabs(crcl.radius + 1) > exp && isSuit(crcl, ps, length - 2)) return crcl;
|
||||
}
|
||||
|
||||
temp = ps[j];
|
||||
ps[j] = ps[length - 2];
|
||||
ps[length - 2] = temp;
|
||||
}
|
||||
|
||||
temp = ps[i];
|
||||
ps[i] = ps[length - 1];
|
||||
ps[length - 1] = temp;
|
||||
}
|
||||
|
||||
return (circle){.center=(point){0, 0}, .radius=0};
|
||||
}
|
||||
|
||||
bool isSuit(circle crcl, point * ps, int length) {
|
||||
for (int i = 0; i < length; ++i) if (!belongs(crcl, ps[i])) return false;
|
||||
return true;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue