21 #ifndef TLP_GEO_CIRCLE_H 22 #define TLP_GEO_CIRCLE_H 25 #include <tulip/Vector.h> 36 template<
typename Obj,
typename OTYPE>
37 struct Circle :
public Vector<Obj,2, OTYPE> {
39 Circle(
const Vector<Obj,2, OTYPE> &pos, Obj radius):Vector<Obj,2, OTYPE>(pos),radius(radius) {}
40 Circle(
const Circle &c):Vector<Obj,2, OTYPE>(c),radius(c.radius) {}
41 Circle(Obj x,Obj y,Obj radius):radius(radius) {
48 void translate(
const Vector<Obj,2, OTYPE> &v) {
56 Circle<Obj, OTYPE>& merge(
const Circle<Obj, OTYPE> &c);
64 bool isIncludeIn(
const Circle<Obj, OTYPE> & circle)
const;
71 template<
typename Obj,
typename OTYPE>
72 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) {
73 double d = c1.dist(c2);
74 double r1 = c1.radius;
75 double r2 = c2.radius;
77 if (c1 == c2)
return false;
79 if (d > (r1 + r2))
return false;
81 if (d < fabs(r1 - r2))
return false;
83 double a = ((r1*r1) - (r2*r2) + (d*d)) / (2.0 * d);
85 Vec2d p2(c1 + c1c2 * a/d);
87 double h = sqrt((r1*r1) - (a*a));
88 double rx = -c1c2[1] * (h/d);
89 double ry = c1c2[0] * (h/d);
103 template<
typename Obj,
typename OTYPE>
104 tlp::Circle<Obj, OTYPE> enclosingCircle(
const tlp::Circle<Obj, OTYPE> &,
const tlp::Circle<Obj, OTYPE> &);
109 template<
typename Obj,
typename OTYPE>
110 tlp::Circle<Obj, OTYPE> enclosingCircle(
const std::vector< tlp::Circle<Obj, OTYPE> > & circles);
116 template<
typename Obj,
typename OTYPE>
117 tlp::Circle<Obj, OTYPE> lazyEnclosingCircle(
const std::vector< tlp::Circle<Obj, OTYPE> > & circles);
121 template<
typename Obj,
typename OTYPE>
122 std::ostream& operator<<(std::ostream &os,const tlp::Circle<Obj, OTYPE> &);
125 typedef Circle<double, long double> Circled;
126 typedef Circle<float, double> Circlef;
127 typedef Circle<int, double> Circlei;
131 #include "cxx/Circle.cxx"