aboutsummaryrefslogtreecommitdiff
path: root/geom.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'geom.hpp')
-rw-r--r--geom.hpp10
1 files changed, 7 insertions, 3 deletions
diff --git a/geom.hpp b/geom.hpp
index e9a4512..1b5c058 100644
--- a/geom.hpp
+++ b/geom.hpp
@@ -67,6 +67,11 @@ struct line {
double a, b, c;
line(double aa, double bb, double cc) : a(aa), b(bb), c(cc) {}
+ line(vec p1, vec p2) {
+ a = p1.x-p2.x ;
+ b = p1.y-p2.y ;
+ c = p1.x*(p2.x-p1.x)+p1.y*(p2.y-p1.y);
+ }
bool on_line(vec p) const {
return a * p.x + b * p.y + c == 0;
@@ -74,8 +79,7 @@ struct line {
double dist(vec p) const {
// calculate distance from p to the line
- // TODO
- return 1;
+ return abs(a*p.x+b*p.y+c)/sqrt(a*a+b*b);
}
vec proj(vec p) const {
@@ -102,7 +106,7 @@ struct segment {
}
double dist(vec p) const {
- // TODO
+
return 1;
}
};