码迷,mamicode.com
首页 > 其他好文 > 详细

计算几何板子

时间:2020-01-28 17:32:27      阅读:48      评论:0      收藏:0      [点我收藏+]

标签:const   计算几何   str   pre   ble   ring   class   cto   基础   

基础

#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;
}

计算几何板子

标签:const   计算几何   str   pre   ble   ring   class   cto   基础   

原文地址:https://www.cnblogs.com/kcn999/p/12238251.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!