NBUT 1640多邊形的公共部分 多邊形面積交

2021-07-22 09:56:49 字數 2022 閱讀 1088

description

給定兩個簡單多邊形,你的任務是判斷二者是否有面積非空的公共部分。如下圖,(a)中的兩個矩形只有一條公共線段,沒有公共面積。

在本題中,簡單多邊形是指不自交(也不會接觸自身)、不含重複頂點並且相鄰邊不共線的多 

邊形。注意:本題並不複雜,但有很多看上去正確的演算法實際上暗藏缺陷,請仔細考慮各種情況。

input 

輸入包含不超過 100 組資料。每組資料報含兩行,每個多邊形佔一行。多邊形的格式是:第一 個整數 n 表示頂點的個數 (3<=n<=100),接下來是 n 對整數(x,y) (-1000<=x,y<=1000),即多邊 形的各個頂點,按照逆時針順序排列。

output 

對於每組資料,如果有非空的公共部分,輸出」yes」,否則輸出」no」。

sample input

4 0 0 2 0 2 2 0 2 

4 2 0 4 0 4 2 2 2 

4 0 0 2 0 2 2 0 2 

4 1 0 3 0 3 2 1 2

sample output

case 1: no 

case 2: yes

hint

無直接求連個多邊形的面積交。。這裡有可能是凹邊形。所以用三角劃分的辦法求。(直接半平面交的話。。一直wa).最最坑的一點。求出的面積》0wa了。而面積》eps過了。。。(臥槽啊)。

#include#include#include#include#include#include#include#include#include#includeusing namespace std;

const int maxn=555;

const int maxisn=10;

const double eps=1e-8;

const double pi=acos(-1.0);

int dcmp(double x)

inline double sqr(double x)

struct point

point(double x,double y):x(x),y(y) {};

friend point operator + (const point &a,const point &b)

friend point operator - (const point &a,const point &b)

friend bool operator == (const point &a,const point &b)

friend point operator * (const point &a,const double &b)

friend point operator * (const double &a,const point &b)

friend point operator / (const point &a,const double &b)

friend bool operator < (const point &a, const point &b)

inline double dot(const point &b)const

inline double cross(const point &b,const point &c)const

};point linecross(const point &a,const point &b,const point &c,const point &d)

double polygonarea(point p,int n)

memcpy(p,temp,sizeof(point)*tn);

nb=tn,p[nb]=p[0];

}if(nb<3) return 0.0;

return polygonarea(p,nb);

}double spia(point a,point b,int na,int nb)

return 0;

}

多邊形與多邊形 位置關係的判斷

c 判斷點的位置方法一 public intisleft point p0,point p1,point p2 private boolpointinfences point pnt1,point fencepnts else if wn 0 return false else return tru...

多邊形的面積

1 三角形面積 xy平面內,有三角形 123,如下圖所示 1 借助向量叉積和點積,這個三角形的面積公式非常簡單 這個面積是有符號的 1 2 3逆時針排列,則面積為正 1 2 3順時針排列,則面積為負。這是對右手系的總結,如果從背面看這個座標系就成了左手系。在左手系下,面積的正負情況正好相反。所以,關...

計算多邊形的面積

題目 輸入乙個點列,順次連線成乙個封閉多邊形,計算多邊形的面積 分析 方法一,計算面積可以考慮定積分的形式,定積分有正有負,順次求和,重複部分相互抵消,最後剩下的總面積的絕對值就是多邊形的面積。從線性積分後的結果可以容易的看出,直線段的積分實際上就是求該直線段與x軸所圍成的區域的梯形的面積int p...