-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGeometry2.cpp
More file actions
43 lines (35 loc) · 1.07 KB
/
Geometry2.cpp
File metadata and controls
43 lines (35 loc) · 1.07 KB
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
36
37
38
39
40
41
42
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <cmath>
using namespace std;
static const double EPS = 1e-8;
double add(double a, double b) {
if (abs(a + b) < EPS * (abs(a) + abs(b))) return 0;
return a + b;
}
struct Point {
double x, y;
Point() {}
Point(double x, double y) : x(x), y(y) {}
Point operator + (Point p) { return Point(add(x, p.x), add(y, p.y)); }
Point operator - (Point p) { return Point(add(x, -p.x), add(y, p.y)); }
Point operator * (double d) { return Point(x * d, y * d); }
double dot(Point p) { return add(x * p.x, y * p.y); }
double det(Point p) { return add(x * p.y, -y * p.x); }
};
struct Line { Point s, t; };
Point Intersection(Line p, Line q) {
return p.s + (p.t - p.s) * ((q.t - q.s).det(q.s - p.s) / (q.t - q.s).det(p.t - p.s));
}
bool Intersect(Line p, Line q) {
if (abs((q.t - q.s).det(p.t - p.s)) < EPS) return false;
return true;
}
int main() {
return 0;
}