From dff0febbbbb01e7884c9b1ccaf4444261a23573e Mon Sep 17 00:00:00 2001 From: artem-ogre Date: Wed, 17 Jun 2020 08:48:34 +0200 Subject: [PATCH] =?UTF-8?q?Make=20super-triangle=20an=20equilateral=20tria?= =?UTF-8?q?ngle=20=D1=81ircumscribed=20around=20bounding=20square?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/CDT.hpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/include/CDT.hpp b/include/CDT.hpp index 12198c45..d9769eb9 100644 --- a/include/CDT.hpp +++ b/include/CDT.hpp @@ -408,11 +408,13 @@ void Triangulation::addSuperTriangle(const Box2d& 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 posV1 = {center.x - shift, center.y - shift}; - const V2d posV2 = {center.x + shift, center.y - shift}; - const V2d 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 posV1 = {center.x - shiftX, center.y - r}; + const V2d posV2 = {center.x + shiftX, center.y - r}; + const V2d posV3 = {center.x, center.y + R}; vertices.push_back(Vertex::make(posV1, TriInd(0))); vertices.push_back(Vertex::make(posV2, TriInd(0))); vertices.push_back(Vertex::make(posV3, TriInd(0)));