1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| namespace Geometric { #define eps 1e-8 struct Point { double x, y; Point(double x = 0, double y = 0) : x(x), y(y) {} friend Point operator + (Point a, Point b) {return Point(a.x + b.x, a.y + b.y);} friend Point operator - (Point a, Point b) {return Point(a.x - b.x, a.y - b.y);} friend Point operator * (Point a, double b){return Point(a.x * b, a.y * b);} friend Point operator / (Point a, double b){return Point(a.x / b, a.y / b);} }origin; #define Vector Point double dis(Point a, Point b){return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));} double len(Vector v){return dis(origin, v);} double dot(Vector a, Vector b){return a.x * b.x + a.y * b.y;} double cross(Vector a, Vector b){return a.x * b.y - b.x * a.y;} double corner(Vector a, Vector b){return dot(a, b) / (len(a) * len(b));} double area (Vector a, Vector b){return cross(a, b) / 2.0;} double angle(Vector v){return atan2(v.y, v.x);} Vector rotate_counterclockwise(Vector v, double t) {return Vector(v.x * cos(t) - v.y * sin(t), v.x * sin(t) + v.y * cos(t));} Vector rotate_clockwise(Vector v, double t) {return Vector(v.x * cos(t) + v.y * sin(t), v.y * cos(t) - v.x * sin(t));} struct line { Point A; Vector B; double An; line(Point a = 0, Vector b = 0) : A(a), B(b) {An = atan2(B.y, B.x);} friend bool operator < (line a, line b){return a.An < b.An;} }; Point sdot(line a, line b){Point c = a.A - b.A;double k = cross(b.B, c) / cross(a.B, b.B);return a.A + a.B * k;} int sure(double x){return fabs(x) < eps ? 0 : (x > 0 ? 1 : -1);} }
using namespace Geometric;
|