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) {
46 Circle &operator=(
const Circle &) =
default;
50 void translate(
const Vector<Obj, 2, OTYPE> &v) {
58 Circle<Obj, OTYPE> &merge(
const Circle<Obj, OTYPE> &c);
66 bool isIncludeIn(
const Circle<Obj, OTYPE> &circle)
const;
74 template <
typename Obj,
typename OTYPE>
75 bool intersection(
const tlp::Circle<Obj, OTYPE> &c1,
const tlp::Circle<Obj, OTYPE> &c2,
76 tlp::Vector<Obj, 2, OTYPE> &sol1, tlp::Vector<Obj, 2, OTYPE> &sol2) {
77 double d = c1.dist(c2);
78 double r1 = c1.radius;
79 double r2 = c2.radius;
87 if (d < fabs(r1 - r2))
90 double a = ((r1 * r1) - (r2 * r2) + (d * d)) / (2.0 * d);
92 Vec2d p2(c1 + c1c2 * a / d);
94 double h = sqrt((r1 * r1) - (a * a));
95 double rx = -c1c2[1] * (h / d);
96 double ry = c1c2[0] * (h / d);
101 sol2[0] = p2[0] - rx;
102 sol2[1] = p2[1] - ry;
110 template <
typename Obj,
typename OTYPE>
111 tlp::Circle<Obj, OTYPE> enclosingCircle(
const tlp::Circle<Obj, OTYPE> &,
112 const tlp::Circle<Obj, OTYPE> &);
117 template <
typename Obj,
typename OTYPE>
118 tlp::Circle<Obj, OTYPE> enclosingCircle(
const std::vector<tlp::Circle<Obj, OTYPE>> &circles);
124 template <
typename Obj,
typename OTYPE>
125 tlp::Circle<Obj, OTYPE> lazyEnclosingCircle(
const std::vector<tlp::Circle<Obj, OTYPE>> &circles);
129 template <
typename Obj,
typename OTYPE>
130 std::ostream &
operator<<(std::ostream &os,
const tlp::Circle<Obj, OTYPE> &);
132 typedef Circle<double, long double> Circled;
133 typedef Circle<float, double> Circlef;
134 typedef Circle<int, double> Circlei;
137 #include "cxx/Circle.cxx"
std::ostream & operator<<(std::ostream &os, const Array< T, N > &array)
operator << stream operator to easily print an array, or save it to a file.