00001 // ***************************************************************************** 00002 // 00003 // Copyright (c) 2014, Southwest Research Institute® (SwRI®) 00004 // All rights reserved. 00005 // 00006 // Redistribution and use in source and binary forms, with or without 00007 // modification, are permitted provided that the following conditions are met: 00008 // * Redistributions of source code must retain the above copyright 00009 // notice, this list of conditions and the following disclaimer. 00010 // * Redistributions in binary form must reproduce the above copyright 00011 // notice, this list of conditions and the following disclaimer in the 00012 // documentation and/or other materials provided with the distribution. 00013 // * Neither the name of Southwest Research Institute® (SwRI®) nor the 00014 // names of its contributors may be used to endorse or promote products 00015 // derived from this software without specific prior written permission. 00016 // 00017 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00018 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00019 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00020 // ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY 00021 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00022 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00023 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00024 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00025 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00026 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00027 // 00028 // ***************************************************************************** 00029 00030 #ifndef POLYGON_H_ 00031 #define POLYGON_H_ 00032 00033 #include <sstream> 00034 00035 #ifndef DEG_TO_RAD 00036 #define DEG_TO_RAD 0.0174532925 00037 #endif 00038 00039 namespace swri_geometry_util 00040 { 00041 //structure for defining the vertices of a polygon 00042 typedef struct 00043 { 00044 //vertices 00045 double *x; 00046 double *y; 00047 }PolygonD; 00048 00049 typedef struct 00050 { 00051 //vertex 00052 double x; 00053 double y; 00054 }Vertex; 00055 00056 class Polygon{ 00057 public: 00058 00059 Polygon(); 00060 Polygon(const Polygon & other); 00061 Polygon & operator= (const Polygon & other); 00062 00063 Polygon(double Xs[], double Ys[], int numVertx); 00064 00065 bool VertexInPolygon(Vertex vertex); 00066 00067 double* GetXVerticies(); 00068 00069 double* GetYVerticies(); 00070 00071 double GetXVerticie(int num); 00072 00073 double GetYVerticie(int num); 00074 00075 int GetNumVerticies(); 00076 00077 bool LineOverlapsPolygon(Vertex start, Vertex end); 00078 00079 ~Polygon(); 00080 00081 private: 00082 00083 Vertex FindLineIntersectLine(Vertex start1, Vertex end1, Vertex start2, 00084 Vertex end2); 00085 00086 PolygonD _shape; //list of polygon vertices 00087 int _nvert; //number of vertices in this polygon 00088 }; 00089 } // end namespace swri_geometry_util 00090 #endif /* POLYGON_H_ */