POJ 3525 (compute geometry + convex polygon max inscribed circle)

Source: Internet
Author: User

Problem Description:

The main land of Japan called Honshu is a island surrounded by the sea. In such-an, it's natural to ask a question: "Where's the most distant point from the sea?" The answer to this question for Honshu is found in 1996. The most distant point was located in former Usuda, Nagano Prefecture, whose distance from the sea was 114.86 km.

In this problem, you is asked to write a program which, given a map of a, finds the most distant point from the s EA in the island, and reports its distance from the sea. In order to simplify the problem, we have consider maps representable by convex polygons.

Input

The input consists of multiple datasets. Each dataset represents a map of the island, which is a convex polygon. The format of a dataset is as follows.

N
X1 Y1
Xn Yn

Every input item in a dataset is a non-negative integer. The input items in a line is separated by a space.

N in the first line is the number of vertices of the polygon, satisfying 3≤n≤100. Subsequent n lines is the X-and y-coordinates of the n vertices. Line segments (xi, Yi) – (xi+1, yi+1) (1≤i≤n−1) and the line segment (xn, yn) – (x1, y1) Form the border of the polygon In counterclockwise order. That's, these line segments see the inside of the polygon in the left of their directions. All coordinate values is between 0 and 10000, inclusive.

You can assume the polygon are simple, that's, its border never crosses or touches itself. As stated above, the given polygon is always a convex one.

The last dataset was followed by a line containing a single zero.

Output

For each dataset in the input, one line containing the distance of the most distant point from the sea should be output. An output line should not contain extra characters such as spaces. The answer should not has an error greater than 0.00001 (10−5). You could output any number of digits after the decimal point, provided that the above accuracy condition is satisfied.

Sample Input

4
0 0
10000 0
10000 10000
0 10000
3
0 0
10000 0
7000
6
0
100 20< c11/>250
0
3
0 0
10000 10000
5001
0
Sample Output

5000.000000
494.233641
34.542948
0.353553

Topic test Instructions: Give us a convex polygon, let us find the maximum inscribed circle radius.

Title Analysis: Convex polygon can be seen on the side (straight line) of the half-plane intersection, in fact, as long as this half-plane of the intersection exists, then this inscribed circle exists, when the half-plane of the intersection does not exist, the inscribed circle does not exist. (Turns into a point at last)

Because it is a convex polygon, we can judge the existence of the nucleus of convex polygon.

We translate each side of the convex polygon until the nucleus does not exist, and the distance of the translation is the radius of the maximum inscribed circle.

The code is as follows: (semi-planar code is template code)

#include <iostream> #include <cstdio> #include <cstring> #include <cmath> using namespace std;
const double eps=1e-8;
const double INF=1E9;
const int maxn=210;
int m;//Save the number of points of the polygon double r;//Save the distance int ccnt,curcnt;//the vertex count of the polygon ccnt for the final cut, the number of scratch vertices struct point {double x, y;}; Point points[maxn],p[maxn],q[maxn];//the vertex of the polygon read in (clockwise), p for the array that holds the resulting polygon vertices, and the vertex void getline of the staged nucleus (point X,point y,double
    &a,double &b,double &c)//two points x, y to determine a line A, B, c for its coefficient {a = y.y-x.y;
    b = x.x-y.x;
c = y.x * x.y-x.x * Y.Y;
    } void Initial () {for (int i = 1; I <= m; ++i) p[i] = points[i];
    P[M+1] = p[1];
    P[0] = p[m];
ccnt = m;
    } point intersect (Point x,point y,double a,double b,double c) {Double u = fabs (A * x.x + b * x.y + c);
    Double v = fabs (A * y.x + b * y.y + c);
    Point pt;
    pt.x= (x.x * v + y.x * u)/(U + V);
    pt.y= (x.y * v + y.y * u)/(U + V);
Return pt;
    } void Cut (double a,double B, double c) {curcnt = 0; for (int i = 1; I <= ccnt;
        ++i) {if (a*p[i].x + b*p[i].y + C >= 0) q[++curcnt] = P[i]; else {if (a*p[i-1].x + b*p[i-1].y + C > 0) {q[++curcnt] = intersect (p[
            I],P[I-1],A,B,C); } if (a*p[i+1].x + b*p[i+1].y + C > 0) {q[++curcnt] = intersect (p[i],p[i+1],a,b
            , c);
    }}} for (int i = 1; I <= curcnt; ++i) p[i] = Q[i];
    P[CURCNT+1] = q[1];
    P[0] = p[curcnt];
ccnt = curcnt;
    } int dcmp (double x) {if (Fabs (x) <eps) return 0;
else return x<0?-1:1;
      } void Solve () {initial ();
          for (int i = 1; I <= m; ++i) {Point TA, TB, TT;
          Tt.x = POINTS[I+1].Y-POINTS[I].Y;
          Tt.y = points[i].x-points[i+1].x;
          Double k = r/sqrt (Tt.x * tt.x + tt.y * tt.y);
          Tt.x = Tt.x * k;
          Tt.y = Tt.y * k;
          ta.x = points[i].x + tt.x;
          TA.Y = Points[i].y + tt.y;tb.x = points[i+1].x + tt.x;
          TB.Y = Points[i+1].y + tt.y;
          Double a,b,c;
          Getline (TA,TB,A,B,C);
      Cut (A,B,C); }} void Guizhenghua () {//normalized direction, counterclockwise clockwise, clockwise anticlockwise for (int i = 1; i < (m+1)/2; i + +) swap (Points[i], points[m-i]
);
        } int main () {while (scanf ("%d", &m)!=eof) {if (m==0) break;
        for (int i=1;i<=m;i++) scanf ("%lf%lf", &points[i].x,&points[i].y);
        Guizhenghua ();
        POINTS[M+1]=POINTS[1];
        Double Left=0,right=inf,mid;
           while ((Right-left) >=eps) {//two min radius mid= (left+right)/2.0;
            cout<<1<<endl;
            R=mid;
            Solve ();
            if (ccnt<=0) Right=mid;
        else Left=mid;
    } printf ("%.6f\n", left);
} return 0;
 }





Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.