comparison 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
comparison
equal deleted inserted replaced
650:200f7e1d57d1 651:62f6ff016085
27 double g_pi = boost::math::constants::pi<double>(); 27 double g_pi = boost::math::constants::pi<double>();
28 } 28 }
29 29
30 namespace OrthancStone 30 namespace OrthancStone
31 { 31 {
32 double RadiansToDegrees(double angleRad)
33 {
34 static const double factor = 180.0 / g_pi;
35 return angleRad * factor;
36 }
32 37
33 void AddSquare(PolylineSceneLayer::Chain& chain, 38 void AddSquare(PolylineSceneLayer::Chain& chain,
34 const Scene2D& scene, 39 const Scene2D& scene,
35 const ScenePoint2D& centerS, 40 const ScenePoint2D& centerS,
36 const double& sideLength) 41 const double& sideLength)
56 chain.push_back(startLT); 61 chain.push_back(startLT);
57 chain.push_back(startRT); 62 chain.push_back(startRT);
58 chain.push_back(startRB); 63 chain.push_back(startRB);
59 chain.push_back(startLB); 64 chain.push_back(startLB);
60 } 65 }
61 66 #if 0
62 void AddArc( 67 void AddArc(
63 PolylineSceneLayer::Chain& chain 68 PolylineSceneLayer::Chain& chain
64 , const Scene2D& scene 69 , const Scene2D& scene
65 , const ScenePoint2D& p1 70 , const ScenePoint2D& p1
66 , const ScenePoint2D& c 71 , const ScenePoint2D& c
73 double p2cAngle = atan2(p2.GetY() - c.GetY(), p2.GetX() - c.GetX()); 78 double p2cAngle = atan2(p2.GetY() - c.GetY(), p2.GetX() - c.GetX());
74 AddArc( 79 AddArc(
75 chain, scene, c, radiusS, p1cAngle, p2cAngle, 80 chain, scene, c, radiusS, p1cAngle, p2cAngle,
76 clockwise, subdivisionsCount); 81 clockwise, subdivisionsCount);
77 } 82 }
78 83 #endif
79 double RadiansToDegrees(double angleRad) 84
80 { 85 void AddShortestArc(
81 static const double factor = 180.0 / g_pi; 86 PolylineSceneLayer::Chain& chain
82 return angleRad * factor; 87 , const Scene2D& scene
88 , const ScenePoint2D& p1
89 , const ScenePoint2D& c
90 , const ScenePoint2D& p2
91 , const double& radiusS
92 , const int subdivisionsCount)
93 {
94 double p1cAngle = atan2(p1.GetY() - c.GetY(), p1.GetX() - c.GetX());
95 double p2cAngle = atan2(p2.GetY() - c.GetY(), p2.GetX() - c.GetX());
96 AddShortestArc(
97 chain, scene, c, radiusS, p1cAngle, p2cAngle, subdivisionsCount);
83 } 98 }
84 99
85 void GetPositionOnBisectingLine( 100 void GetPositionOnBisectingLine(
86 ScenePoint2D& result 101 ScenePoint2D& result
87 , const ScenePoint2D& p1 102 , const ScenePoint2D& p1
98 double posX = c.GetX() + d * unitVectorX; 113 double posX = c.GetX() + d * unitVectorX;
99 double posY = c.GetX() + d * unitVectorY; 114 double posY = c.GetX() + d * unitVectorY;
100 result = ScenePoint2D(posX, posY); 115 result = ScenePoint2D(posX, posY);
101 } 116 }
102 117
118
119 void AddShortestArc(
120 PolylineSceneLayer::Chain& chain
121 , const Scene2D& scene
122 , const ScenePoint2D& centerS
123 , const double& radiusS
124 , const double startAngleRad
125 , const double endAngleRad
126 , const int subdivisionsCount)
127 {
128 // this gives a signed difference between angle which
129 // is the smallest difference (in magnitude) between
130 // the angles
131 double delta = NormalizeAngle(endAngleRad-startAngleRad);
132
133 chain.clear();
134 chain.reserve(subdivisionsCount + 1);
135
136 double angleIncr = delta/static_cast<double>(subdivisionsCount);
137
138 double theta = startAngleRad;
139 for (int i = 0; i < subdivisionsCount + 1; ++i)
140 {
141 double offsetX = radiusS * cos(theta);
142 double offsetY = radiusS * sin(theta);
143 double pointX = centerS.GetX() + offsetX;
144 double pointY = centerS.GetY() + offsetY;
145 chain.push_back(ScenePoint2D(pointX, pointY));
146 theta += angleIncr;
147 }
148 }
149
150 #if 0
103 void AddArc( 151 void AddArc(
104 PolylineSceneLayer::Chain& chain 152 PolylineSceneLayer::Chain& chain
105 , const Scene2D& scene 153 , const Scene2D& scene
106 , const ScenePoint2D& centerS 154 , const ScenePoint2D& centerS
107 , const double& radiusS 155 , const double& radiusS
143 double pointY = centerS.GetY() + offsetY; 191 double pointY = centerS.GetY() + offsetY;
144 chain.push_back(ScenePoint2D(pointX, pointY)); 192 chain.push_back(ScenePoint2D(pointX, pointY));
145 theta += angleIncr; 193 theta += angleIncr;
146 } 194 }
147 } 195 }
196 #endif
148 197
149 void AddCircle(PolylineSceneLayer::Chain& chain, 198 void AddCircle(PolylineSceneLayer::Chain& chain,
150 const Scene2D& scene, 199 const Scene2D& scene,
151 const ScenePoint2D& centerS, 200 const ScenePoint2D& centerS,
152 const double& radiusS, 201 const double& radiusS,
177 } 226 }
178 227
179 double NormalizeAngle(double angle) 228 double NormalizeAngle(double angle)
180 { 229 {
181 double retAngle = angle; 230 double retAngle = angle;
182 while (retAngle < 0) 231 while (retAngle < -1.0*g_pi)
183 retAngle += 2 * g_pi; 232 retAngle += 2 * g_pi;
184 while (retAngle >= 2 * g_pi) 233 while (retAngle >= g_pi)
185 retAngle -= 2 * g_pi; 234 retAngle -= 2 * g_pi;
186 return retAngle; 235 return retAngle;
187 } 236 }
188 237
189 double MeasureAngle(const ScenePoint2D& p1, const ScenePoint2D& c, const ScenePoint2D& p2) 238 double MeasureAngle(const ScenePoint2D& p1, const ScenePoint2D& c, const ScenePoint2D& p2)