Skip to content

Commit

Permalink
Make super-triangle an equilateral triangle сircumscribed around boun…
Browse files Browse the repository at this point in the history
…ding square
  • Loading branch information
artem-ogre committed Jun 17, 2020
1 parent 597af6f commit dff0feb
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions include/CDT.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -408,11 +408,13 @@ void Triangulation<T>::addSuperTriangle(const Box2d<T>& box)
(box.min.y + box.max.y) / T(2)};
const T w = box.max.x - box.min.x;
const T h = box.max.y - box.min.y;
const T diag = T(4) * std::sqrt(w * w + h * h);
const T shift = diag / std::sqrt(T(2)); // diagonal * sin(45deg)
const V2d<T> posV1 = {center.x - shift, center.y - shift};
const V2d<T> posV2 = {center.x + shift, center.y - shift};
const V2d<T> posV3 = {center.x, center.y + diag};
T r = std::sqrt(w * w + h * h) / 2.0; // incircle radius
r *= 1.1;
const T R = 2.0 * r; // excircle radius
const T shiftX = R * std::sqrt(T(3)) / 2.0; // R * cos(30 deg)
const V2d<T> posV1 = {center.x - shiftX, center.y - r};
const V2d<T> posV2 = {center.x + shiftX, center.y - r};
const V2d<T> posV3 = {center.x, center.y + R};
vertices.push_back(Vertex<T>::make(posV1, TriInd(0)));
vertices.push_back(Vertex<T>::make(posV2, TriInd(0)));
vertices.push_back(Vertex<T>::make(posV3, TriInd(0)));
Expand Down

0 comments on commit dff0feb

Please sign in to comment.