poj 3675 Telescope(三角剖分求多边形和圆交面积)

Telescope
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 2271   Accepted: 673

Description

Updog is watching a plane object with a telescope. The field of vision in the telescope can be described as a circle. The center is at the origin and the radius is R. The object can be seen as a simple polygon of N vertexes. Updog wants to know the area of the part of the object that can be seen in the telescope.

Input

The input will contain several test cases. For each case:
The first line contains only one real number R
The second line contains an integer N. The following N lines contain two real numbers xi and yi each, which describe the coordinates of a vertex. Two vertexes in adjacent lines are also adjacent on the polygon. 
Constraints: 3 ≤ N ≤50, 0.1 ≤ R ≤1000, -1000 ≤ xiyi ≤ 1000

Output

For each test case, output one real number on a separate line, which is the area of the part that can be seen. The result should be rounded to two decimal places.

Sample Input

10
3
0 20
10 0
-10 0

Sample Output

144.35

Source

POJ Founder Monthly Contest – 2008.07.27, Updog

题意:求一个圆心为原点半径为r的圆和一个多边形的交面积,保证多边形不退化不自交
题解:根据圆心将多边形划分为n部分的三角形和圆的交,然后分情况计算三角形和圆的交面积。。。
就是一堆解释几何的问题,做完能很好的熟悉关于圆的各种计算。。。不过很麻烦。。。很容易错。。。我做了近5个小时
而三角形和圆交的基本情况在这个博客很详细  http://hi.baidu.com/billdu/item/703ad4e15d819db52f140b0b

#include
#include
#include
#define eps 1e-8
using namespace std;
struct point{
    double x,y;
    point(){}
    point(double x_,double y_):x(x_),y(y_){}
}p[58],tp[2],origin;
double r,area;
int n;
double MIN(double x,double y){ return xy?x:y; }
double cross(point p1,point p2,point p3)
{
    return (p2.x-p1.x)*(p3.y-p1.y)-(p3.x-p1.x)*(p2.y-p1.y);
}
double dot(point p1,point p2)
{
    return p1.x*p2.x+p1.y*p2.y;
}
double dis(point p1,point p2)
{
    return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));
}
struct point get_intersect()
{
    struct point temp=point(tp[0].x-tp[1].x,tp[0].y-tp[1].y);
    struct point vec=point(temp.y,-temp.x);
    struct point origin2=point(origin.x+vec.x,origin.y+vec.y);
    double a1=tp[0].y-tp[1].y;
    double b1=tp[1].x-tp[0].x;
    double c1=(tp[0].x*tp[1].y-tp[1].x*tp[0].y);
    double a2=origin.y-origin2.y;
    double b2=origin2.x-origin.x;
    double c2=(origin.x*origin2.y-origin2.x*origin.y);
    double tmd=a1*b2-a2*b1;
    return point((b1*c2-b2*c1)/tmd,(a2*c1-a1*c2)/tmd);
};
int on_line(point p0,point p1,point p2)
{
    if(p0.x>MAX(p1.x,p2.x)) return 0;
    if(p0.xMAX(p1.y,p2.y)) return 0;
    if(p0.y0)
    {
        for(int i=1;i<=n;i++) scanf("%lf%lf",&p[i].x,&p[i].y);
        p[n+1]=p[1];
        solve();
        printf("%.2lf\n",fabs(area));
    }

    return 0;
}


你可能感兴趣的:(计算几何,ACM之路(c/c++))