计算几何基础

来源:互联网 发布:淘宝水星小飞船证吗 编辑:程序博客网 时间:2024/06/04 18:40

唉,高中数学都忘干净了、

 叉积都不知道了

点积、叉积:传送门

关于两个求反正切函数的比较:传送门

比较:黑猫

关于极角排序:黑猫

POJ 2318

这题利用叉积判断点在线段的左侧还是右侧

叉积 < 0 左侧

叉积 > 0 右侧

#include <cstdio>#include <cstring>#include <cmath>#include <cstdlib>#include <ctime>#include <iostream>#include <algorithm>#include <sstream>#include <string>#include <vector>#include <queue>#include <stack>#include <map>#include <set>#include <utility>using namespace std;#define LL long long#define pb push_back#define mk make_pair#define mst(a, b)memset(a, b, sizeof a)#define REP(i, x, n)for(int i = x; i <= n; ++i)const int MOD = 1e9 + 7;//const int qq = 2e5 + 10;const int INF = 1e9 + 10;struct Point {int x, y;Point(){}Point(int _x, int _y) {x = _x, y = _y;}Point operator - (const Point &A) const {return Point(x - A.x, y - A.y);}int operator * (const Point &A) const {return x * A.x + y * A.y;}int operator ^ (const Point &A) const {return x * A.y - y * A.x;}};struct Line {Point s, e;Line(){}Line(Point _s, Point _e) {s = _s, e = _e;}};int xmult(Point p0, Point p1, Point p2) {return (p1 - p0) ^ (p2 - p0);}const int qq = 5050;Line line[qq];int ans[qq];int main(){int n, m, x1, y1, x2, y2;bool first = true;while(scanf("%d", &n) != EOF) {if(!n)break;if(first)first = false;elseputs("");scanf("%d%d%d%d%d", &m, &x1, &y1, &x2, &y2);int Ui, Li;for(int i = 0; i < n; ++i) {scanf("%d%d", &Ui, &Li);line[i] = Line(Point(Ui, y1), Point(Li, y2));}line[n] = Line(Point(x2, y1), Point(x2, y2));int x, y;Point p;mst(ans, 0);while(m--) {scanf("%d%d", &x, &y);p = Point(x, y);int l = 0, r = n;int tmp;while(l <= r) {int mid = (l + r) >> 1;if(xmult(p, line[mid].s, line[mid].e) < 0) {tmp = mid;r = mid - 1;} else {l = mid + 1;}}ans[tmp]++;}for(int i = 0; i <= n; ++i) {printf("%d: %d\n", i, ans[i]);}}return 0;}


原创粉丝点击