基礎計算幾何,第1張

這兩天準備學一點計算幾何,先來一發基礎的計算幾何板子

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

生活常識_百科知識_各類知識大全»基礎計算幾何

0條評論

    發表評論

    提供最優質的資源集郃

    立即查看了解詳情