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)
40 : Vector<Obj, 2, OTYPE>(pos), radius(radius) {}
41 Circle(
const Circle &c) : Vector<Obj, 2, OTYPE>(c), radius(c.radius) {}
42 Circle(Obj x, Obj y, Obj radius) : radius(radius) {
49 void translate(
const Vector<Obj, 2, OTYPE> &v) {
57 Circle<Obj, OTYPE> &merge(
const Circle<Obj, OTYPE> &c);
65 bool isIncludeIn(
const Circle<Obj, OTYPE> &circle)
const;
73 template <
typename Obj,
typename OTYPE>
74 bool intersection(
const tlp::Circle<Obj, OTYPE> &c1,
const tlp::Circle<Obj, OTYPE> &c2,
75 tlp::Vector<Obj, 2, OTYPE> &sol1, tlp::Vector<Obj, 2, OTYPE> &sol2) {
76 double d = c1.dist(c2);
77 double r1 = c1.radius;
78 double r2 = c2.radius;
86 if (d < fabs(r1 - r2))
89 double a = ((r1 * r1) - (r2 * r2) + (d * d)) / (2.0 * d);
91 Vec2d p2(c1 + c1c2 * a / d);
93 double h = sqrt((r1 * r1) - (a * a));
94 double rx = -c1c2[1] * (h / d);
95 double ry = c1c2[0] * (h / d);
100 sol2[0] = p2[0] - rx;
101 sol2[1] = p2[1] - ry;
109 template <
typename Obj,
typename OTYPE>
110 tlp::Circle<Obj, OTYPE> enclosingCircle(
const tlp::Circle<Obj, OTYPE> &,
111 const tlp::Circle<Obj, OTYPE> &);
116 template <
typename Obj,
typename OTYPE>
117 tlp::Circle<Obj, OTYPE> enclosingCircle(
const std::vector<tlp::Circle<Obj, OTYPE>> &circles);
123 template <
typename Obj,
typename OTYPE>
124 tlp::Circle<Obj, OTYPE> lazyEnclosingCircle(
const std::vector<tlp::Circle<Obj, OTYPE>> &circles);
128 template <
typename Obj,
typename OTYPE>
129 std::ostream &operator<<(std::ostream &os, const tlp::Circle<Obj, OTYPE> &);
131 typedef Circle<double, long double> Circled;
132 typedef Circle<float, double> Circlef;
133 typedef Circle<int, double> Circlei;
136 #include "cxx/Circle.cxx"