注意:點逆序可以用半平面交或者多邊形面積交
半平面交**至
#include using namespace std;
#define e exp(1.0);
#define mod 1000000007
#define inf 0x3f3f3f3f
typedef long long ll;
#define inf 0x7fffffff
#define zero(x) (((x)>0?(x):(-x))eps ? 1 : 0;
}inline double sqr(double x)
struct point
; void input()
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 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)
double norm()
};//計算兩個向量的叉積
double cross(const point &a, const point &b)
double cross3(point a, point b, point c) //叉乘
//計算兩個點的點積
double dot(const point &a, const point &b)
double dot3(point a, point b, point c) //點乘
//求n邊形的面積,多邊形上的點要按逆時針的順序儲存在p中
double convexpolygonarea(point *p, int n)
//typedef complexpoint;
//typedef pairhalfplane;
struct halfplane
; halfplane(point a, point b): a(a), b(b) {};
};inline double satisfy(point a, halfplane p)
point crosspoint(const halfplane &a, const halfplane &b)
double arg(point p)
bool cmp(const halfplane &a, const halfplane &b)
int halfplaneintersection(halfplane *v, int n, point *out)
while(ans.size() > 0 && !satisfy(ans.back(), v[i]))
while(ans.size() > 0 && !satisfy(ans.front(), v[i]))
ans.push_back(crosspoint(q.back(), v[i]));
q.push_back(v[i]);
}while(ans.size() > 0 && !satisfy(ans.back(), q.front()))
while(ans.size() > 0 && !satisfy(ans.front(), q.back()))
ans.push_back(crosspoint(q.back(), q.front()));
int m = 0;
while(ans.empty() == false)
return m;
}halfplane v[222];
point out[222];
point a[222], b[222];
int main()
else if(x1 > x2 && y1 < y2)
else if(x1 < x2 && y1 > y2)
else if(x1 < x2 && y1 < y2)
b[0] = point(x3, y3);
b[1] = point(x4, y3);
b[2] = point(x4, y4);
b[3] = point(x3, y4);
v[n++] = halfplane(b[0], b[1]);
v[n++] = halfplane(b[1], b[2]);
v[n++] = halfplane(b[2], b[3]);
v[n++] = halfplane(b[3], b[0]);
int m = halfplaneintersection(v, n, out);
printf("%.8f\n", convexpolygonarea(out, m));
}return 0;
}
多邊形面積交
#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
; 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)
return fabs(s * 0.5);
}double cpia(point a, point b, int na, int nb)
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 res;
}//多邊形a、b的點的順序需要按照逆時針排序
point a[10],b[10];
int main()
return 0;
}
CSU 1812 三角形和矩形 幾何
description bobo 有乙個三角形和乙個矩形,他想求他們交的面積。具體地,三角形和矩形由 8 個整數 x 1,y 1,x 2,y 2,x 3,y 3,x 4,y 4 描述。表示三角形的頂點座標是 x 1,y 1 x 1,y2 x 2,y 1 矩形的頂點座標是 x 3,y 3 x 3,y ...
csu J 1812 三角形和矩形
submit page summary time limit 5 sec memory limit 128 mb submitted 7 solved 3 specialjudge bobo 有乙個三角形和乙個矩形,他想求他們交的面積。具體地,三角形和矩形由 8 個整數 x1,y1,x2,y2,x3...
canvas繪製矩形 三角形 圓形
1 繪製矩形 charset utf 8 canvas繪製矩形title canvas style window.onload function script head id canvas1 width 600 height 300 canvas body html 效果如下 方法詳解 contex...