diff options
author | Alex Auvolat <alex.auvolat@ens.fr> | 2015-01-08 16:34:17 +0100 |
---|---|---|
committer | Alex Auvolat <alex.auvolat@ens.fr> | 2015-01-08 16:34:17 +0100 |
commit | 4bf549ed7af5d2b972a4be616420ffc0958d6baa (patch) | |
tree | 20a3347ebd042f1686b34ff740ac1d0da6e600bc | |
parent | 8aa7f2ee67640b6c76b45f99905529ef01078509 (diff) | |
parent | 2a0597a8d3d088df43f9787fd78d4d50155f6d3c (diff) | |
download | Robotique-Projet-4bf549ed7af5d2b972a4be616420ffc0958d6baa.tar.gz Robotique-Projet-4bf549ed7af5d2b972a4be616420ffc0958d6baa.zip |
Merge branch 'master' of github.com:Alexis211/Robotique
Conflicts:
geom.hpp
-rw-r--r-- | geom.hpp | 21 |
1 files changed, 16 insertions, 5 deletions
@@ -17,6 +17,10 @@ struct vec { return x*x + y*y; } + double sqnorm() const { + return x*x + y*y; + } + double angle() const { double xx = x / norm(); double a = acos(x); @@ -79,13 +83,16 @@ struct line { double dist(vec p) const { // calculate distance from p to the line - return abs(a*p.x + b*p.y + c) / sqrt(a*a + b*b); + 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,13 +108,17 @@ struct segment { bool on_segment(vec p) const { // TODO + // does point intersect segment? return false; } double dist(vec p) const { - //TODO - return 1; + 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); } }; |