示例#1
0
 circle_2 get_circumcircle(triangle_2 const &t) const
 {
     if (t[0] == t[1] && t[1] == t[2])
         return circle_2(t[0], 0);
     if (orientation(t[0], t[1], t[2]) == cg::CG_COLLINEAR)
     {
         auto minmax = std::minmax({t[0], t[1], t[2]});
         point_2 p1 = minmax.first;
         point_2 p2 = minmax.second;
         if (t[0] != t[1])
             p2 = t[1];
         else
             p2 = t[2];
         point_2 center = p1 + vector_2((p2.x - p1.x) / 2, (p2.y - p1.y) / 2);
         double radius = segment_2(p1, p2).length() / 2;
         return circle_2(center, radius);
     }
     double A1 = t[1].x - t[0].x;
     double B1 = t[1].y - t[0].y;
     double C1 = (t[1].x - t[0].x) * (t[1].x + t[0].x) / 2 + (t[1].y - t[0].y) * (t[1].y + t[0].y) / 2;
     double A2 = t[2].x - t[0].x;
     double B2 = t[2].y - t[0].y;
     double C2 = (t[2].x - t[0].x) * (t[2].x + t[0].x) / 2 + (t[2].y - t[0].y) * (t[2].y + t[0].y) / 2;
     point_2 center((C1 * B2 - C2 * B1) / (A1 * B2 - A2 * B1),
                    (A1 * C2 - A2 * C1) / (A1 * B2 - A2 * B1));
     double radius = segment_2(center, t[0]).length();
     return circle_2(center, radius);
 }
示例#2
0
 void calc_visibility_graph()
 {
     int n = 0;
     for (contour_2 &c : contours)
     {
         if (!counterclockwise(c))
         {
             c.reverse();
             std::reverse(points.begin() + n, points.begin() + n + c.size());
         }
         n += c.size();
     }
     graph g = visibility_graph(contours.begin(), contours.end(), true);
     visibility_segments.clear();
     for (int i = 0; i < (int) points.size(); ++i)
     {
         std::vector<int> const &edges = g.get_edges(i);
         for (int j : edges)
             visibility_segments.push_back(segment_2(points[i], points[j]));
     }
 }