Poj 3525
#include
<
iostream
>
#include < math.h >
#include < string .h >
#define eps 1e-7
using namespace std;
struct point{
double x, y;
void read(){scanf( " %lf %lf " , & x, & y);}
void write(){printf( " %.2lf %.2lf\n " , x, y);}
point operator - (point & a)
{
point t;
t.x = x - a.x;
t.y = y - a.y;
return t;
}
point operator + (point & a)
{
point t;
t.x = x + a.x;
t.y = y + a.y;
return t;
}
};
int n;
point p[ 105 ];
double dist(point a, point b)
{
point c = a - b;
return sqrt( c.x * c.x + c.y * c.y);
}
bool flag;
double xmul(point a, point b, point c)
{ return (c.x - a.x) * (b.y - a.y) - (c.y - a.y) * (b.x - a.x);}
point intersection(point u1, point u2,point v1, point v2)
{
point ret = u1;
double t = ((u1.x - v1.x) * (v1.y - v2.y) - (u1.y - v1.y) * (v1.x - v2.x))
/ ((u1.x - u2.x) * (v1.y - v2.y) - (u1.y - u2.y) * (v1.x - v2.x));
ret.x += (u2.x - u1.x) * t;
ret.y += (u2.y - u1.y) * t;
return ret;
}
point change(point a, point b, point next, double L)
{
point t;
t.x = - (b - a).y;
t.y = (b - a).x;
double len = sqrt(t.x * t.x + t.y * t.y);
t.x /= len; t.y /= len;
t.x *= L; t.y *= L;
t = t + next;
return t;
}
int jud( double h)
{
point tp[ 105 ], tt[ 105 ], ns, ne, s, e, pp ;
int len = 0 , tlen, i, j;
for (i = 0 ; i <= n; i ++ ) tp[i] = p[i];
len = n;
for (i = 0 ; i < n; i ++ )
{
s = change(p[i], p[i + 1 ], p[i], h);
e = change(p[i], p[i + 1 ], p[i + 1 ], h);
// s.write();
// e.write();
tlen = 0 ;
for (j = 0 ; j < len; j ++ )
{
ns = tp[j]; ne = tp[j + 1 ];
if (xmul(s, e, ns) <= 0 )
tt[tlen ++ ] = ns;
if (xmul(s, e, ns) * xmul(s, e, ne) < 0 )
{
pp = intersection(s, e, ns, ne);
tt[tlen ++ ] = pp;
}
}
tt[tlen] = tt[ 0 ];
for (j = 0 ; j <= tlen; j ++ )
{
tp[j] = tt[j];
// printf("point: ");
// tp[j].write();
}
len = tlen;
// printf("%d\n", len);
}
return len;
}
double bsearch( double left, double right)
{
while (right - left > eps)
{
double mid = (left + right) / 2 ;
// printf("%lf %lf %lf:\n", left, mid, right);
if (jud(mid))left = mid;
else right = mid;
}
return left;
}
int main()
{
while (scanf( " %d " , & n), n)
{
for ( int i = 0 ; i < n; i ++ )
p[i].read();
p[n] = p[ 0 ];
double minn = - 1 , maxx = - 1 ;
for ( int i = 0 ; i < n; i ++ )
for ( int j = i + 1 ; j < n; j ++ )
{
double dis = dist(p[i], p[j]) / 2 ;
if (dis < minn || minn < eps)
minn = dis;
if (dis > maxx || maxx < eps)
maxx = dis;
}
flag = 0 ;
// printf("%.2lf %.2lf\n", minn, maxx); while(1);
double ans = bsearch( 0 , maxx);
printf( " %.6lf\n " , ans);
}
}
#include < math.h >
#include < string .h >
#define eps 1e-7
using namespace std;
struct point{
double x, y;
void read(){scanf( " %lf %lf " , & x, & y);}
void write(){printf( " %.2lf %.2lf\n " , x, y);}
point operator - (point & a)
{
point t;
t.x = x - a.x;
t.y = y - a.y;
return t;
}
point operator + (point & a)
{
point t;
t.x = x + a.x;
t.y = y + a.y;
return t;
}
};
int n;
point p[ 105 ];
double dist(point a, point b)
{
point c = a - b;
return sqrt( c.x * c.x + c.y * c.y);
}
bool flag;
double xmul(point a, point b, point c)
{ return (c.x - a.x) * (b.y - a.y) - (c.y - a.y) * (b.x - a.x);}
point intersection(point u1, point u2,point v1, point v2)
{
point ret = u1;
double t = ((u1.x - v1.x) * (v1.y - v2.y) - (u1.y - v1.y) * (v1.x - v2.x))
/ ((u1.x - u2.x) * (v1.y - v2.y) - (u1.y - u2.y) * (v1.x - v2.x));
ret.x += (u2.x - u1.x) * t;
ret.y += (u2.y - u1.y) * t;
return ret;
}
point change(point a, point b, point next, double L)
{
point t;
t.x = - (b - a).y;
t.y = (b - a).x;
double len = sqrt(t.x * t.x + t.y * t.y);
t.x /= len; t.y /= len;
t.x *= L; t.y *= L;
t = t + next;
return t;
}
int jud( double h)
{
point tp[ 105 ], tt[ 105 ], ns, ne, s, e, pp ;
int len = 0 , tlen, i, j;
for (i = 0 ; i <= n; i ++ ) tp[i] = p[i];
len = n;
for (i = 0 ; i < n; i ++ )
{
s = change(p[i], p[i + 1 ], p[i], h);
e = change(p[i], p[i + 1 ], p[i + 1 ], h);
// s.write();
// e.write();
tlen = 0 ;
for (j = 0 ; j < len; j ++ )
{
ns = tp[j]; ne = tp[j + 1 ];
if (xmul(s, e, ns) <= 0 )
tt[tlen ++ ] = ns;
if (xmul(s, e, ns) * xmul(s, e, ne) < 0 )
{
pp = intersection(s, e, ns, ne);
tt[tlen ++ ] = pp;
}
}
tt[tlen] = tt[ 0 ];
for (j = 0 ; j <= tlen; j ++ )
{
tp[j] = tt[j];
// printf("point: ");
// tp[j].write();
}
len = tlen;
// printf("%d\n", len);
}
return len;
}
double bsearch( double left, double right)
{
while (right - left > eps)
{
double mid = (left + right) / 2 ;
// printf("%lf %lf %lf:\n", left, mid, right);
if (jud(mid))left = mid;
else right = mid;
}
return left;
}
int main()
{
while (scanf( " %d " , & n), n)
{
for ( int i = 0 ; i < n; i ++ )
p[i].read();
p[n] = p[ 0 ];
double minn = - 1 , maxx = - 1 ;
for ( int i = 0 ; i < n; i ++ )
for ( int j = i + 1 ; j < n; j ++ )
{
double dis = dist(p[i], p[j]) / 2 ;
if (dis < minn || minn < eps)
minn = dis;
if (dis > maxx || maxx < eps)
maxx = dis;
}
flag = 0 ;
// printf("%.2lf %.2lf\n", minn, maxx); while(1);
double ans = bsearch( 0 , maxx);
printf( " %.6lf\n " , ans);
}
}