【模板】计算几何

基础

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>

using namespace std;

const double PI = acos(-1.0);
const double eps = 1e-8;

int cmp(double a, double b)
{
    if (a - b > eps) return 1;
    if (a - b < -eps) return -1;
    return 0;
}

struct Vector
{
    double x, y;

    Vector(double x = 0, double y = 0) : x(x), y(y) {}
    friend Vector operator + (Vector a, Vector b) {return Vector(a.x + b.x, a.y + b.y);}
    friend Vector operator - (Vector a, Vector b) {return Vector(a.x - b.x, a.y - b.y);}
    friend Vector operator * (Vector a, double k) {return Vector(a.x * k, a.y * k);}
    friend Vector operator / (Vector a, double k) {return Vector(a.x / k, a.y / k);}
    friend bool operator < (Vector a, Vector b) {return cmp(a.x, b.x) ? cmp(a.x, b.x) == -1 : cmp(a.y, b.y) == -1;}
    friend bool operator == (Vector a, Vector b) {return cmp(a.x, b.x) == 0 && cmp(a.y, b.y) == 0;}
    friend double operator * (Vector a, Vector b) {return a.x * b.x + a.y * b.y;}
    friend double operator ^ (Vector a, Vector b) {return a.x * b.y - a.y * b.x;}
    double Length() {return sqrt(x * x + y * y);}
};
typedef Vector Point;

double Angle(Vector a, Vector b) {return acos(a * b / a.Length() / b.Length());}


int main()
{
    
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/kcn999/p/12238251.html