基础计算几何
这两天准备学一点计算几何,先来一发基础的计算几何板子
#include <bits/stdc++.h>
using namespace std;
#define EPS (1e-8)
bool equals(double x, double y){
return fabs(x-y) < EPS;
}
bool greater_than(double x, double y){
return x - y > EPS;
}
struct Vec{
double x, y;
Vec(){};
Vec(double _x, double _y): x(_x), y(_y){};
Vec operator+(const Vec& v) const{
return Vec(x+v.x, y+v.y);
}
Vec operator-(const Vec& v) const{
return Vec(x-v.x, y-v.y);
}
Vec operator*(double d) const{
return Vec(d*x, d*y);
}
Vec operator/(double d) const{
return Vec(x/d, y/d);
}
double norm2()const{
return x*x + y*y;
}
};
double dot(const Vec& a, const Vec& b){
return a.x * b.x + a.y * b.y;
}
double cross(const Vec& a, const Vec& b){
return a.x * b.y - a.y * b.x;
}
typedef Vec Pt;
---- suffer now and live the rest of your life as a champion ----