From 803d245cc906b6397ef1952df1f858cc46d0c444 Mon Sep 17 00:00:00 2001 From: Jean Fabre-Monplaisir Date: Thu, 8 Jan 2015 17:43:29 +0100 Subject: =?UTF-8?q?distance=20=C3=A0=20un=20cercle=20-=20=C3=A7a=20compile?= =?UTF-8?q?=20!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- geom.hpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'geom.hpp') diff --git a/geom.hpp b/geom.hpp index daeedaa..603abf9 100644 --- a/geom.hpp +++ b/geom.hpp @@ -17,10 +17,6 @@ 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); @@ -115,9 +111,9 @@ struct segment { 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 ; + 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); } }; @@ -134,8 +130,10 @@ struct circle { } double dist(vec p) const { - // TODO - return 1; + // distance à un cercle + double d = (c-p).norm() ; + if (d > r) return (d - r); + return 0; } }; -- cgit v1.2.3