二维计算几何基础 - OI Wiki (oi-wiki.org)
记录直线:
判断点与直线的位置关系:
练习:2007 -- Scrambled Polygon (poj.org)
大意:给定一些点,保证第一个点为原点,其他点不在坐标轴上且任意三点不共线,从远点开始逆时针排序
思路:向量叉积排序
#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <climits>
// #include <unordered_map>
using namespace std;
#define mst(x, y) memset(x, y, sizeof x)
#define X first
#define Y second
#define int long long
#define FAST ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
const int N = 200010, INF = 0x3f3f3f3f, MOD = 1e9 + 7;
const double EPS = 1e-6;
// typedef pair<int, int> PII;
// typedef unordered_map<int, int> Ump;
int idx = 1;
int m, n;
struct Point
{
int x, y;
} P[N];
bool cmp(Point a, Point b)
{
return (b.x * a.y) - (b.y * a.x) < 0;
}
signed main()
{
FAST;
cin >> n >> m;
while (cin >> P[idx].x >> P[idx].y)
idx++;
cout << "(0,0)" << endl;
sort(P + 1, P + idx, cmp);
for (int i = 1; i < idx; i++)
{
cout << "(" << P[i].x << "," << P[i].y << ")" << endl;
}
return 0;
}
判断两线段是否相交:
求两直线交点:
已知直线上的一个点和直线的方向向量,求直线外一点P到直线的距离
方法一:
立体几何:如何用空间向量方法求点到直线的距离? - 知乎 (zhihu.com)
如图,设 k : 1 - k = |EC| : |ED| = d(D到AB的距离) : d(C到AB的距离) = m : n
其中 d(D到AB的距离)仿下图可得
此时k = n / n + m,带入可得E点
求任意多边形的面积( 与上面例题有相似之处 ,向量积的和 ):