aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean Fabre-Monplaisir <jean-isaac-fm@live.fr>2015-01-08 17:30:28 +0100
committerJean Fabre-Monplaisir <jean-isaac-fm@live.fr>2015-01-08 17:30:28 +0100
commit2a0597a8d3d088df43f9787fd78d4d50155f6d3c (patch)
treef37fac6c4595f3beb7c86dd014ab12eed0e18432
parent3e7f796b17150cb96b332c619271152df3015756 (diff)
downloadRobotique-Projet-2a0597a8d3d088df43f9787fd78d4d50155f6d3c.tar.gz
Robotique-Projet-2a0597a8d3d088df43f9787fd78d4d50155f6d3c.zip
Ajout de fonction de distance d'un point à un segment.
-rw-r--r--geom.hpp18
1 files changed, 15 insertions, 3 deletions
diff --git a/geom.hpp b/geom.hpp
index 1b5c058..0b07bdd 100644
--- a/geom.hpp
+++ b/geom.hpp
@@ -11,6 +11,10 @@ struct vec {
return sqrt(x*x + y*y);
}
+ double sqnorm() const {
+ return x*x + y*y;
+ }
+
double angle() const {
double xx = x / norm();
double a = acos(x);
@@ -81,11 +85,14 @@ struct line {
// calculate distance from p to the line
return abs(a*p.x+b*p.y+c)/sqrt(a*a+b*b);
}
+ vec dir() const {
+ // calculate a directional vector oh the line
+ return vec(-b,a);
+ }
vec proj(vec p) const {
// calculate orthogonal projection of point p on the line
- // TODO
- return vec(0, 0);
+ return p-(a*p.x+b*p.y+c)/(a*a+b*b)*vec(a,b);
}
double angle() const {
@@ -101,12 +108,17 @@ struct segment {
bool on_segment(vec p) const {
// TODO
+
// does point intersect segment?
return false;
}
double dist(vec p) const {
-
+ double scal = vec::dot(b-a, p-a);
+ double sqn = (b-a).sqnorm
+ if(scal > sqn)return (p-b).norm ;
+ if(scal < 0) return (p-a).norm ;
+ return line(a,b).dist(p);
return 1;
}
};