计算几何模板

#include<iostream>
#include<cstdio>
#include<cmath>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <vector>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef long double ld;
const int N =111;
const ld eps = 1e-9;
int dcmp(ld a, ld b) {
    if (fabs(a - b) < eps)
        return 0;
    else if (a > b)
        return 1;
    else
        return -1;
}
struct Point {
    ld x, y;
    int kind;
    Point(ld X = 0, ld Y = 0) { x = X, y = Y; }
    Point operator-(Point a) { return Point(x - a.x, y - a.y); }
    Point operator+(Point a) { return Point(x + a.x, y + a.y); }
    ld operator*(Point a) { return x * a.y - y * a.x; }
    ld operator^(Point a) { return x * a.x + y * a.y; }
    Point operator*(ld a) { return Point(x * a, y * a); }
    Point rotate(ld thi) {
        return Point(x * cos(thi) + y * sin(thi), -x * sin(thi) + y * cos(thi));
    }
    ld dis() { return sqrt(x * x + y * y); }
    void out() { printf("%.2Lf %.2Lf
", x, y); }
} p[N];

typedef Point Vector;
Point get_inseration(Point p1, Point p2, Point p3, Point p4, bool &exist) {
    exist = 0;
    Vector v1 = p2 - p1, v2 = p4 - p3, v3 = p1 - p3;
    if (dcmp(v1 * (p3 - p1) * (v1 * (p4 - p1)), 0) <= 0) {
        if (dcmp((v2 * (p1 - p3)) * (v2 * (p2 - p3)), 0) <= 0) {
            exist = 1;
        }
    }
    if (!exist) return Point{-1, -1};
    // v1.out();
    return p1 + v1 * ((v2 * v3) / (v1 * v2));
}

struct Line {
    Point s, t;
    Vector dir;
}l[N];
ld angle(Vector v1, Vector v2) { return acos(v1 ^ v2) / v1.dis() / v2.dis(); }
void out(ld x) { printf("%.2Lf
", x); }
void solve() {
    
}
signed main() {
    ll t = 1;//cin >> t;
    while (t--) {
       solve();
    }
}
原文地址:https://www.cnblogs.com/Xiao-yan/p/14690764.html