![]() |
Tulip
4.6.0
Better Visualization Through Research
|
00001 /* 00002 * 00003 * This file is part of Tulip (www.tulip-software.org) 00004 * 00005 * Authors: David Auber and the Tulip development Team 00006 * from LaBRI, University of Bordeaux 00007 * 00008 * Tulip is free software; you can redistribute it and/or modify 00009 * it under the terms of the GNU Lesser General Public License 00010 * as published by the Free Software Foundation, either version 3 00011 * of the License, or (at your option) any later version. 00012 * 00013 * Tulip is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00016 * See the GNU General Public License for more details. 00017 * 00018 */ 00019 ///@cond DOXYGEN_HIDDEN 00020 00021 #ifndef TLP_GEO_CIRCLE_H 00022 #define TLP_GEO_CIRCLE_H 00023 00024 #include <vector> 00025 #include <tulip/Vector.h> 00026 namespace tlp { 00027 /** 00028 * @ingroup Structures 00029 * \brief class for circle 00030 * 00031 * Enables to both create and manipulate a circle 00032 * 00033 * \author David Auber auber@tulip-software.org 00034 * \version 0.0.1 24/01/2003 00035 */ 00036 template<typename Obj, typename OTYPE> 00037 struct Circle : public Vector<Obj,2, OTYPE> { 00038 Circle() {} 00039 Circle(const Vector<Obj,2, OTYPE> &pos, Obj radius):Vector<Obj,2, OTYPE>(pos),radius(radius) {} 00040 Circle(const Circle &c):Vector<Obj,2, OTYPE>(c),radius(c.radius) {} 00041 Circle(Obj x,Obj y,Obj radius):radius(radius) { 00042 (*this)[0]=x; 00043 (*this)[1]=y; 00044 } 00045 /** 00046 * Translate "this" by vector v 00047 */ 00048 void translate(const Vector<Obj,2, OTYPE> &v) { 00049 (*this)+=v; 00050 } 00051 /** 00052 * Merges this circle with another circle; merging operation 00053 * consists in computing the smallest enclosing circle of the 00054 * two circle and to store the result in "this". 00055 */ 00056 Circle<Obj, OTYPE>& merge(const Circle<Obj, OTYPE> &c); 00057 /** 00058 * Radius of the circle 00059 */ 00060 Obj radius; 00061 /** 00062 * Returns true if the circle is include in an other circle, false otherwise. 00063 */ 00064 bool isIncludeIn(const Circle<Obj, OTYPE> & circle) const; 00065 }; 00066 00067 /** 00068 * Give the instersction of two circles, return false if no intersection exist else put the two points in p1 & p2, 00069 * if there is only one solution p1 == p2; 00070 */ 00071 template<typename Obj, typename OTYPE> 00072 bool intersection(const tlp::Circle<Obj, OTYPE> &c1, const tlp::Circle<Obj, OTYPE> &c2, tlp::Vector<Obj,2, OTYPE> &sol1, tlp::Vector<Obj,2, OTYPE> &sol2) { 00073 double d = c1.dist(c2); 00074 double r1 = c1.radius; 00075 double r2 = c2.radius; 00076 00077 if (c1 == c2) return false; 00078 00079 if (d > (r1 + r2)) return false; //outside 00080 00081 if (d < fabs(r1 - r2)) return false; //inside 00082 00083 double a = ((r1*r1) - (r2*r2) + (d*d)) / (2.0 * d); 00084 Vec2d c1c2(c2 - c1); 00085 Vec2d p2(c1 + c1c2 * a/d); 00086 00087 double h = sqrt((r1*r1) - (a*a)); 00088 double rx = -c1c2[1] * (h/d); 00089 double ry = c1c2[0] * (h/d); 00090 00091 sol1[0] = p2[0] + rx; 00092 sol1[1] = p2[1] + ry; 00093 00094 sol2[0] = p2[0] - rx; 00095 sol2[1] = p2[1] - ry; 00096 00097 return true; 00098 } 00099 00100 /** 00101 * Compute the optimum enclosing circle of 2 circles. 00102 */ 00103 template<typename Obj, typename OTYPE> 00104 tlp::Circle<Obj, OTYPE> enclosingCircle(const tlp::Circle<Obj, OTYPE> &,const tlp::Circle<Obj, OTYPE> &); 00105 00106 /** 00107 * Compute the optimum enclosing circle of a set of circles. 00108 */ 00109 template<typename Obj, typename OTYPE> 00110 tlp::Circle<Obj, OTYPE> enclosingCircle(const std::vector< tlp::Circle<Obj, OTYPE> > & circles); 00111 /** 00112 * Compute an enclosing circle of a set of circles, 00113 * this algorithm is an aproximation of the smallest 00114 * enclosing circle. 00115 */ 00116 template<typename Obj, typename OTYPE> 00117 tlp::Circle<Obj, OTYPE> lazyEnclosingCircle(const std::vector< tlp::Circle<Obj, OTYPE> > & circles); 00118 /** 00119 * Write circle in a stream 00120 */ 00121 template<typename Obj, typename OTYPE> 00122 std::ostream& operator<<(std::ostream &os,const tlp::Circle<Obj, OTYPE> &); 00123 00124 00125 typedef Circle<double, long double> Circled; 00126 typedef Circle<float, double> Circlef; 00127 typedef Circle<int, double> Circlei; 00128 00129 } 00130 00131 #include "cxx/Circle.cxx" 00132 #endif 00133 ///@endcond