diff options
-rw-r--r-- | geom.hpp | 36 | ||||
-rw-r--r-- | problem.cpp | 94 | ||||
-rw-r--r-- | problem.hpp | 36 |
3 files changed, 83 insertions, 83 deletions
@@ -14,9 +14,9 @@ inline double frand(double a, double b) { } inline double canon_angle(double ref, double move_it){ - while (ref>move_it) move_it += 2*M_PI; - while (move_it >= ref + 2*M_PI) move_it -= 2*M_PI; - return move_it ; + while (ref>move_it) move_it += 2*M_PI; + while (move_it >= ref + 2*M_PI) move_it -= 2*M_PI; + return move_it ; } struct vec { @@ -195,20 +195,20 @@ struct angular_sector { assert(i.c.c == o.c.c); assert(i.theta1 == o.theta1); assert(i.theta2 == o.theta2); - - } - bool is_in_sector(vec p) const{ - if(inner.is_in_pie(p) && (p-inner.c.c).norm() <=outer.c.r && inner.c.r <=(p-inner.c.c).norm())return true; - return false; - } - - double dist(vec p) const{ - if (is_in_sector(p)) return 0; - return std::min(std::min(std::min(inner.dist(p),outer.dist(p)), - segment(vec::from_polar(inner.c.r,inner.theta1)+inner.c.c, - vec::from_polar(outer.c.r,inner.theta2)+inner.c.c).dist(p)), - segment(vec::from_polar(inner.c.r,inner.theta2)+inner.c.c, - vec::from_polar(outer.c.r,inner.theta2)+inner.c.c).dist(p)) ; - } + + } + bool is_in_sector(vec p) const{ + if(inner.is_in_pie(p) && (p-inner.c.c).norm() <=outer.c.r && inner.c.r <=(p-inner.c.c).norm())return true; + return false; + } + + double dist(vec p) const{ + if (is_in_sector(p)) return 0; + return std::min(std::min(std::min(inner.dist(p),outer.dist(p)), + segment(vec::from_polar(inner.c.r,inner.theta1)+inner.c.c, + vec::from_polar(outer.c.r,inner.theta2)+inner.c.c).dist(p)), + segment(vec::from_polar(inner.c.r,inner.theta2)+inner.c.c, + vec::from_polar(outer.c.r,inner.theta2)+inner.c.c).dist(p)) ; + } }; /* vim: set ts=4 sw=4 tw=0 noet :*/ diff --git a/problem.cpp b/problem.cpp index c733200..350836e 100644 --- a/problem.cpp +++ b/problem.cpp @@ -12,60 +12,60 @@ using namespace std; double hilare_a_mvt::length() { // returns length traveled by the car - if (is_arc) return domega * (center - from.pos()).norm(); - return ds ; + if (is_arc) return domega * (center - from.pos()).norm(); + return ds ; } bool hilare_a::intersects(const obstacle &o) const { - - if((pos()-o.c.c).norm() < o.c.r + param->r_c_car)return true ; - if((pos_trolley()-o.c.c).norm() < o.c.r + param->r_c_trolley)return true ; - if(segment(pos(),pos_trolley()).dist(o.c.c) < o.c.r)return true ; - return false ; + + if((pos()-o.c.c).norm() < o.c.r + param->r_c_car)return true ; + if((pos_trolley()-o.c.c).norm() < o.c.r + param->r_c_trolley)return true ; + if(segment(pos(),pos_trolley()).dist(o.c.c) < o.c.r)return true ; + return false ; } bool hilare_a_mvt::intersects(const obstacle &o) const { - hilare_a_param *p = from.param; - vec pos_init = from.pos(); - vec pos_init_trolley = from.pos_trolley(); - if(is_arc){ - double r_min = - min((pos_init - center).norm()-(p->r_c_car), - (pos_init_trolley - center).norm()-(p->r_c_trolley)); - double r_max = - max((pos_init - center).norm()+(p->r_c_car), - (pos_init_trolley - center).norm()+(p->r_c_trolley)); - //TODO - double theta1; - double theta2; - if (domega>=0) { - if(from.phi > 0){ - theta1 = (from.pos()-center).angle(); - theta2 = (to.pos_trolley()-center).angle(); - } - else { - theta1 = (from.pos_trolley()-center).angle(); - theta2 = (to.pos()-center).angle(); + hilare_a_param *p = from.param; + vec pos_init = from.pos(); + vec pos_init_trolley = from.pos_trolley(); + if(is_arc){ + double r_min = + min((pos_init - center).norm()-(p->r_c_car), + (pos_init_trolley - center).norm()-(p->r_c_trolley)); + double r_max = + max((pos_init - center).norm()+(p->r_c_car), + (pos_init_trolley - center).norm()+(p->r_c_trolley)); + //TODO + double theta1; + double theta2; + if (domega>=0) { + if(from.phi > 0){ + theta1 = (from.pos()-center).angle(); + theta2 = (to.pos_trolley()-center).angle(); + } + else { + theta1 = (from.pos_trolley()-center).angle(); + theta2 = (to.pos()-center).angle(); + } } - } - else { - if(from.phi > 0){ //TODO ?? - theta2 = (from.pos()-center).angle(); - theta1 = (to.pos_trolley()-center).angle(); - } - else { - theta2 = (from.pos_trolley()-center).angle(); - theta1 = (to.pos()-center).angle(); + else { + if(from.phi > 0){ //TODO ?? + theta2 = (from.pos()-center).angle(); + theta1 = (to.pos_trolley()-center).angle(); + } + else { + theta2 = (from.pos_trolley()-center).angle(); + theta1 = (to.pos()-center).angle(); + } } + theta2 = canon_angle(theta1,theta2); + angular_sector sector = angular_sector(circarc(circle(center,r_min), theta1, theta2), circarc(circle(center,r_max), theta1, theta2)); + if (sector.dist(o.c.c)<=o.c.r)return true; + if (from.intersects(o)) return true; + if (to.intersects(o)) return true; + return false; + } - theta2 = canon_angle(theta1,theta2); - angular_sector sector = angular_sector(circarc(circle(center,r_min), theta1, theta2), circarc(circle(center,r_max), theta1, theta2)); - if (sector.dist(o.c.c)<=o.c.r)return true; - if (from.intersects(o)) return true; - if (to.intersects(o)) return true; - return false; - - } return false; } @@ -86,7 +86,7 @@ solution solution::direct_sol(const hilare_a &pos_a, const hilare_a &pos_b) { // - trouver les quatre droites tangentes aux deux cercles canoniques // - pour chacune de ces droites, se mettre dessus, aller droit, s'en séparer // (vérifier la cohérence : il n'y en a que deux qui sont dans le bon sens !) - + // cas où la position de départ ou d'arrivée n'a pas pour courbe canonique un cercle : se tourner de pi/6 par exemple // (ce cas n'arrivera pas, car on tire complètement au hasard...) @@ -139,7 +139,7 @@ solution solution::direct_sol(const hilare_a &pos_a, const hilare_a &pos_b) { if (fabs(xx) < 0.01 || fabs(xx - 2*M_PI) < 0.01 && fabs(xx + 2*M_PI) < 0.01) { vector<hilare_a_mvt> sol; - + hilare_a_mvt r1; r1.is_arc = true; r1.from = pos_a; diff --git a/problem.hpp b/problem.hpp index 5d9269a..40361d9 100644 --- a/problem.hpp +++ b/problem.hpp @@ -46,7 +46,7 @@ struct hilare_a { // System A return vec(xc, yc); } - bool intersects(const obstacle &o) const; // intersects an obstacle ? + bool intersects(const obstacle &o) const; // intersects an obstacle ? }; @@ -82,10 +82,10 @@ struct hilare_a_mvt { double ds; // longueur par double length(); // length of a movement - + bool intersects(const obstacle &o) const; // intersects an obstacle ? - bool intersects(const problem &p) const; // intersects any obstacle on the map ? + bool intersects(const problem &p) const; // intersects any obstacle on the map ? }; struct solution { @@ -116,28 +116,28 @@ class solver { private: - sf::Mutex _d_lock; - solver_internal _d; - problem _p; + sf::Mutex _d_lock; + solver_internal _d; + problem _p; + + bool _please_stop; + bool _running; + bool _done; + solution _s; - bool _please_stop; - bool _running; - bool _done; - solution _s; - - sf::Thread _worker; + sf::Thread _worker; public: - solver(); + solver(); - void start(const problem &p); + void start(const problem &p); - void run(); // worker thread + void run(); // worker thread - bool finished(); - solution get_solution(); + bool finished(); + solution get_solution(); - solver_internal peek_internal(); + solver_internal peek_internal(); }; |