Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

point.h

Go to the documentation of this file.
00001 //----------------------------------------------------------------------
00002 //               The Motion Strategy Library (MSL)
00003 //----------------------------------------------------------------------
00004 //
00005 // Copyright (c) University of Illinois and Steven M. LaValle.     
00006 // All Rights Reserved.
00007 //
00008 // Permission to use, copy, and distribute this software and its
00009 // documentation is hereby granted free of charge, provided that
00010 // (1) it is not a component of a commercial product, and
00011 // (2) this notice appears in all copies of the software and
00012 //     related documentation.
00013 //
00014 // The University of Illinois and the author make no representations
00015 // about the suitability or fitness of this software for any purpose.
00016 // It is provided "as is" without express or implied warranty.
00017 //----------------------------------------------------------------------
00018 
00019 #ifndef MSL_POINT_H
00020 #define MSL_POINT_H
00021 
00022 
00023 #ifdef WIN32
00024         #include <iostream>
00025         #include <list>
00026         using namespace std;
00027 #else
00028         #include <iostream.h>
00029         #include <list.h>
00030 #endif
00031 
00032 #include "mslio.h"
00033 
00034 class MSLPoint
00035 {
00036   double xrep;
00037   double yrep;
00038 
00039 public:
00040  
00041   MSLPoint();
00042   MSLPoint(double x, double y);
00043   ~MSLPoint() {}
00044   double xcoord()  const   { return xrep; }
00045   double ycoord()  const   { return yrep; }
00046   void normalize() const {}
00047   int dim() const { return 2; }
00048   double sqr_dist(const MSLPoint& q) const;
00049   double xdist(const MSLPoint& q) const;
00050   double ydist(const MSLPoint& q) const;
00051   double distance(const MSLPoint& q) const;
00052   double distance() const { return distance(MSLPoint(0,0)); }
00053   double angle(const MSLPoint& q, const MSLPoint& r) const;
00054   MSLPoint translate_by_angle(double alpha, double d) const;
00055   MSLPoint translate(double dx, double dy) const;
00056   MSLPoint rotate(const MSLPoint& q, double a) const;
00057   MSLPoint rotate(double a) const;
00058   MSLPoint rotate90(const MSLPoint& q) const;
00059   MSLPoint rotate90() const;
00060   MSLPoint reflect(const MSLPoint& q, const MSLPoint& r) const;
00061   MSLPoint reflect(const MSLPoint& q) const;
00062   bool operator==(const MSLPoint& q) const;
00063   bool operator!=(const MSLPoint& q)  const { return !operator==(q);}
00064 
00065   friend ostream& operator<<(ostream& O, const MSLPoint& p) ;
00066   friend istream& operator>>(istream& I, MSLPoint& p) ;
00067   //friend istream& operator>>(istream& is, list<MSLPoint>& vl);
00068   //friend ostream& operator<<(ostream& os, const list<MSLPoint>& vl);
00069   //friend istream& operator>>(istream& is, list<list<MSLPoint> >& vl);
00070   //friend ostream& operator<<(ostream& os, const list<list<MSLPoint> >& vl);
00071 };
00072 
00073 ostream& operator<<(ostream& O, const MSLPoint& p) ;
00074 istream& operator>>(istream& I, MSLPoint& p) ;
00075 
00076 
00077 inline MSLPoint center(const MSLPoint& a, const MSLPoint& b) { 
00078   return MSLPoint((a.xcoord()+b.xcoord())/2,(a.ycoord()+b.ycoord())/2); 
00079 } 
00080 
00081 
00082 inline MSLPoint midMSLPoint(const MSLPoint& a, const MSLPoint& b) { 
00083   return center(a,b); 
00084 }
00085 
00086 
00087 inline int orientation(const MSLPoint& a, const MSLPoint& b, const MSLPoint& c)
00088 { double d1 = (a.xcoord() - b.xcoord()) * (a.ycoord() - c.ycoord());
00089   double d2 = (a.ycoord() - b.ycoord()) * (a.xcoord() - c.xcoord()); 
00090   if (d1 == d2) return 0; else return (d1 > d2) ? +1 : -1;
00091 }
00092 
00093 inline int cmp_signed_dist(const MSLPoint& a, const MSLPoint& b, 
00094                            const MSLPoint& c, const MSLPoint& d)
00095 { double d1 = (a.xcoord() - b.xcoord()) * (d.ycoord() - c.ycoord());
00096   double d2 = (a.ycoord() - b.ycoord()) * (d.xcoord() - c.xcoord()); 
00097   if (d1 == d2) return 0; else return (d1 > d2) ? +1 : -1;
00098 }
00099 
00100 inline double area(const MSLPoint& a, const MSLPoint& b, const MSLPoint& c)
00101 { return ((a.xcoord()-b.xcoord()) * (a.ycoord()-c.ycoord()) -
00102           (a.ycoord()-b.ycoord()) * (a.xcoord()-c.xcoord()))/2; }
00103 
00104 inline bool collinear(const MSLPoint& a, const MSLPoint& b, const MSLPoint& c)
00105 { return (a.ycoord()-b.ycoord()) * (a.xcoord()-c.xcoord()) ==
00106          (a.xcoord()-b.xcoord()) * (a.ycoord()-c.ycoord()); }
00107 
00108 inline bool right_turn(const MSLPoint& a, const MSLPoint& b, const MSLPoint& c)
00109 { return (a.xcoord()-b.xcoord()) * (a.ycoord()-c.ycoord()) <
00110          (a.ycoord()-b.ycoord()) * (a.xcoord()-c.xcoord()); }
00111 
00112 inline bool left_turn(const MSLPoint& a, const MSLPoint& b, const MSLPoint& c)
00113 { return (a.xcoord()-b.xcoord()) * (a.ycoord()-c.ycoord()) >
00114          (a.ycoord()-b.ycoord()) * (a.xcoord()-c.xcoord()); }
00115 
00116 extern int side_of_circle(const MSLPoint& a, const MSLPoint& b, 
00117                                     const MSLPoint& c, const MSLPoint& d);
00118 
00119 inline bool incircle(const MSLPoint& a, const MSLPoint& b, const MSLPoint& c,
00120                                                      const MSLPoint& d)
00121 { return (orientation(a,b,c) * side_of_circle(a,b,c,d)) > 0; }
00122 
00123 inline bool outcircle(const MSLPoint& a, const MSLPoint& b, const MSLPoint& c,
00124                                                       const MSLPoint& d)
00125 { return (orientation(a,b,c) * side_of_circle(a,b,c,d)) < 0; }
00126 
00127 inline bool cocircular(const MSLPoint& a, const MSLPoint& b, const MSLPoint& c,
00128                                                        const MSLPoint& d)
00129 { return side_of_circle(a,b,c,d) == 0; }
00130 
00131 
00132 // Add a fake polygon class which is a list of points
00133 // typedef list<MSLPoint> MSLPolygon;
00134 
00135 #endif
00136 
Motion Strategy Library


Web page maintained by Steve LaValle
Partial support provided by NSF CAREER Award IRI-970228 (LaValle), Honda Research.
Contributors: Anna Atramentov, Peng Cheng, James Kuffner, Steve LaValle, and Libo Yang.