随笔分类 - 计算几何
计算几何之极角排序
摘要:1.利用叉积的正负来作cmp.(即是按逆时针排序). bool cmp(const point &a, const point &b)//逆时针排序 { point origin; origin.x = origin.y = 0; return cross(origin,b,origin,a) bool cmp(const Point& p1, const Point& p2)//360度范围逆时针排序 { complex c1(p1.x,p1.y),c2(p2.x,p2.y); return arg(c1) b.x; if (a.y == ...
阅读全文
HDUOJ Pick-up sticks 判断线段相交
摘要:Pick-up sticksTime Limit: 4000/2000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1771Accepted Submission(s): 672Problem DescriptionStan has n sticks of various length. He throws them one at a time on the floor in a random way. After finishing throwing, Stan tries to
阅读全文
POJ TOY叉乘+二分
摘要:#define DeBUG#include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std ;#define zero {0}#define INF 2000000000#define EPS 1e-6typedef long long LL;const double PI = acos(-1.0);inline int sgn(double x){return fabs
阅读全文
Ural 1750 Pakhom and the Gully (线段交,最短路)
摘要:#define DeBUG#include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std ;#define zero {0}#define INF 200000000#define EPS 1e-6#define MM 1typedef long long LL;inline int sgn(dou...
阅读全文
POJ2187旋转卡壳
摘要:// POJ 2187 Beauty Contest -- Andrew凸包算法 + 点对距离最长(旋转卡壳)// 大意:给你一堆点,让你求出相隔最远的两点距离并输出// 要求:最后结果不需要开平方 应为距离的平方///*test data51 32 14 15 33 5 == 17*/#include #include #include using namespace std;const double Pzero = 0.000001;const int MAXP = 50005;struct Point{ double x, y;//点对应坐标 Point() {} ...
阅读全文
HDU4741异面直线距离与中垂线交点
摘要:#include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std ;#define zero {0}#define INF 2000000000#define eps 1e-6typedef long long LL;struct Point3{ double x, y, z; Point3() {} Point3(double x, double y,...
阅读全文
HDU1791三点确定一个圆
摘要:1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #include 10 #include 11 #include 12 #include 13 #include 14 using namespace std ;15 #ifdef DeBUG16 #define bug assert17 #else18 #define bug //19 #endif20 #define zero {0}21 #define INF 200000000022 #de...
阅读全文
计算几何公式集锦
摘要:1---计算多边形重心方法:(1)划分多边形为三角形:以多边形的一个顶点V为源点(V可取输入的第一个顶点),作连结V与所有非相邻顶点的线段,即将原N边形或分为(N-2)个三角形;(2)求每个三角形的重心和面积:设某个三角形的重心为G(cx,cy),顶点坐标分别为A1(x1,y1),A2(x2,y2),A3(x3,y3),则有cx = (x1 + x2 + x3)/3.同理求得cy。求面积的方法是s = ( (x2 - x1) * (y3 - y1) - (x3 - x1) * (y2 - y1) ) / 2,当A1,A2,A3顺时针排列时取-,否则取正(此定理不证)。事实上,在求每个三角形时.
阅读全文
HDUOJ 1392凸包graham算法
摘要:#include #include #include #include #include using namespace std;const int Max = 1100;struct Point{ int x; int y;};int num;Point p[Max]; ///原始点集Point ch[Max]; ///凸包点集///p0p1叉乘p0p2int xmult(const Point &p0, const Point &p1, const Point &p2){ return (p1.x-p0.x)*(p2.y-p0.y) - (p2.x-p0.x)*(p
阅读全文
HDU1086判断线段相交
摘要:1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 #include 10 #include 11 #include 12 using namespace std ; 13 #ifdef DeBUG 14 #define bug assert 15 #else 16 #define bug // 17 #endif 18 #define eps 1e-6 19 struct segment 20 { 21 double x...
阅读全文