Calculate waypoints for a zigzag pattern. This function generates waypoints for a zigzag pattern starting from a given point with configurable width, height, and spacing. The direction of the zigzag pattern (vertical or horizontal) can be specified.
148 {
149
150 std::vector<geoops::Waypoint> vWaypoints;
151 double dStartingX = stCenterPoint.
GetUTMCoordinate().dEasting - (dWidth / 2);
152 double dStartingY = stCenterPoint.
GetUTMCoordinate().dNorthing - (dHeight / 2);
153 double dCurrentX = dStartingX;
154 double dCurrentY = dStartingY;
155 bool bZigNotZag = true;
156 double bCalcSpacing = dSpacing;
157
158
159 if (dWidth < 1 || dHeight < 1 || dSpacing < 1)
160 {
161
162 LOG_WARNING(logging::g_qSharedLogger, "Width or height or spacing is less than 1 meter. Cannot create zigzag pattern.");
163 return vWaypoints;
164 }
165
166
167 if (bCalcSpacing > dWidth / 2.0)
168 {
169
170 LOG_WARNING(logging::g_qSharedLogger, "Spacing is greater than width. Setting spacing to width / 2.");
171
172 bCalcSpacing = dWidth / 2.0 - 1.0;
173 }
174 if (bCalcSpacing > dHeight / 2.0)
175 {
176
177 LOG_WARNING(logging::g_qSharedLogger, "Spacing is greater than height. Setting spacing to height / 2.");
178
179 bCalcSpacing = dHeight / 2.0 - 1.0;
180 }
181
182
183 while ((bVertical && dCurrentY <= dStartingY + dHeight) || (!bVertical && dCurrentX <= dStartingX + dWidth))
184 {
185
186 if (bVertical)
187 {
188
189 if (bZigNotZag)
190 {
191
192 dCurrentX = dStartingX + bCalcSpacing;
193 }
194 else
195 {
196
197 dCurrentX = dStartingX - bCalcSpacing;
198 }
199 }
200 else
201 {
202
203 if (bZigNotZag)
204 {
205
206 dCurrentY = dStartingY + bCalcSpacing;
207 }
208 else
209 {
210
211 dCurrentY = dStartingY - bCalcSpacing;
212 }
213 }
214
215
216 while ((bZigNotZag && bVertical && dCurrentX <= dStartingX + dWidth) || (!bZigNotZag && bVertical && dCurrentX >= dStartingX) ||
217 (bZigNotZag && !bVertical && dCurrentY <= dStartingY + dHeight) || (!bZigNotZag && !bVertical && dCurrentY >= dStartingY))
218 {
219
221 stCurrentCoordinate.dEasting = dCurrentX;
222 stCurrentCoordinate.dNorthing = dCurrentY;
223 geoops::Waypoint stCurrentWaypoint(stCurrentCoordinate, geoops::WaypointType::eNavigationWaypoint);
224
225 vWaypoints.push_back(stCurrentWaypoint);
226
227
228 if (bVertical)
229 {
230
231 dCurrentX += bZigNotZag ? bCalcSpacing : -bCalcSpacing;
232 }
233 else
234 {
235
236 dCurrentY += bZigNotZag ? bCalcSpacing : -bCalcSpacing;
237 }
238 }
239
240
241 if (bVertical)
242 {
243 dCurrentY += bCalcSpacing;
244 }
245 else
246 {
247 dCurrentX += bCalcSpacing;
248 }
249
250
251 bZigNotZag = !bZigNotZag;
252 }
253
254
255
256
257
258
259
260
261 std::vector<geoops::Waypoint> vFilterWaypoints;
262
263 vFilterWaypoints.push_back(vWaypoints[0]);
264
265 for (size_t i = 0; i < vWaypoints.size() - 1; ++i)
266 {
267
269 if (stGeoMeasurement.dDistanceMeters > bCalcSpacing * 1.5)
270 {
271
272 vFilterWaypoints.push_back(vWaypoints[i]);
273 vFilterWaypoints.push_back(vWaypoints[i + 1]);
274 }
275 }
276
277
278 std::string szSearchPatternPoints = "Search Pattern Points (Spiral): ";
280 {
281 szSearchPatternPoints +=
282 "(" + std::to_string(stWaypoint.GetGPSCoordinate().dLatitude) + ", " + std::to_string(stWaypoint.GetGPSCoordinate().dLongitude) + "), ";
283 }
284
285 LOG_DEBUG(logging::g_qSharedLogger, "{}", szSearchPatternPoints);
286
287
288 return vFilterWaypoints;
289 }
This struct is used to store the distance, arc length, and relative bearing for a calculated geodesic...
Definition GeospatialOperations.hpp:83