Mercurial > hg > orthanc-stone
diff Samples/Common/MeasureToolsToolbox.cpp @ 651:62f6ff016085
Iteration in angle measuring tool. Text label is not ok and handles and arcs
(and maybe angle sides) should not scale with zoom.
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Tue, 14 May 2019 09:48:14 +0200 |
parents | 1e9ed656318e |
children | 462a5074f914 |
line wrap: on
line diff
--- a/Samples/Common/MeasureToolsToolbox.cpp Tue May 14 09:48:01 2019 +0200 +++ b/Samples/Common/MeasureToolsToolbox.cpp Tue May 14 09:48:14 2019 +0200 @@ -29,6 +29,11 @@ namespace OrthancStone { + double RadiansToDegrees(double angleRad) + { + static const double factor = 180.0 / g_pi; + return angleRad * factor; + } void AddSquare(PolylineSceneLayer::Chain& chain, const Scene2D& scene, @@ -58,7 +63,7 @@ chain.push_back(startRB); chain.push_back(startLB); } - +#if 0 void AddArc( PolylineSceneLayer::Chain& chain , const Scene2D& scene @@ -75,11 +80,21 @@ chain, scene, c, radiusS, p1cAngle, p2cAngle, clockwise, subdivisionsCount); } +#endif - double RadiansToDegrees(double angleRad) + void AddShortestArc( + PolylineSceneLayer::Chain& chain + , const Scene2D& scene + , const ScenePoint2D& p1 + , const ScenePoint2D& c + , const ScenePoint2D& p2 + , const double& radiusS + , const int subdivisionsCount) { - static const double factor = 180.0 / g_pi; - return angleRad * factor; + double p1cAngle = atan2(p1.GetY() - c.GetY(), p1.GetX() - c.GetX()); + double p2cAngle = atan2(p2.GetY() - c.GetY(), p2.GetX() - c.GetX()); + AddShortestArc( + chain, scene, c, radiusS, p1cAngle, p2cAngle, subdivisionsCount); } void GetPositionOnBisectingLine( @@ -100,6 +115,39 @@ result = ScenePoint2D(posX, posY); } + + void AddShortestArc( + PolylineSceneLayer::Chain& chain + , const Scene2D& scene + , const ScenePoint2D& centerS + , const double& radiusS + , const double startAngleRad + , const double endAngleRad + , const int subdivisionsCount) + { + // this gives a signed difference between angle which + // is the smallest difference (in magnitude) between + // the angles + double delta = NormalizeAngle(endAngleRad-startAngleRad); + + chain.clear(); + chain.reserve(subdivisionsCount + 1); + + double angleIncr = delta/static_cast<double>(subdivisionsCount); + + double theta = startAngleRad; + for (int i = 0; i < subdivisionsCount + 1; ++i) + { + double offsetX = radiusS * cos(theta); + double offsetY = radiusS * sin(theta); + double pointX = centerS.GetX() + offsetX; + double pointY = centerS.GetY() + offsetY; + chain.push_back(ScenePoint2D(pointX, pointY)); + theta += angleIncr; + } + } + +#if 0 void AddArc( PolylineSceneLayer::Chain& chain , const Scene2D& scene @@ -145,6 +193,7 @@ theta += angleIncr; } } +#endif void AddCircle(PolylineSceneLayer::Chain& chain, const Scene2D& scene, @@ -179,9 +228,9 @@ double NormalizeAngle(double angle) { double retAngle = angle; - while (retAngle < 0) + while (retAngle < -1.0*g_pi) retAngle += 2 * g_pi; - while (retAngle >= 2 * g_pi) + while (retAngle >= g_pi) retAngle -= 2 * g_pi; return retAngle; }