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.
205 {
206
207 std::vector<geoops::Waypoint> vWaypoints;
208 double dStartingX = stCenterPoint.dEasting - (dWidth / 2);
209 double dStartingY = stCenterPoint.dNorthing - (dHeight / 2);
210 double dCurrentX = dStartingX;
211 double dCurrentY = dStartingY;
212 bool bZigNotZag = true;
213 double bCalcSpacing = dSpacing;
214
215
216 if (dWidth < 1 || dHeight < 1 || dSpacing < 1)
217 {
218
219 LOG_WARNING(logging::g_qSharedLogger, "Width or height or spacing is less than 1 meter. Cannot create zigzag pattern.");
220 return vWaypoints;
221 }
222
223
224 if (bCalcSpacing > dWidth / 2.0)
225 {
226
227 LOG_WARNING(logging::g_qSharedLogger, "Spacing is greater than width. Setting spacing to width / 2.");
228
229 bCalcSpacing = dWidth / 2.0 - 1.0;
230 }
231 if (bCalcSpacing > dHeight / 2.0)
232 {
233
234 LOG_WARNING(logging::g_qSharedLogger, "Spacing is greater than height. Setting spacing to height / 2.");
235
236 bCalcSpacing = dHeight / 2.0 - 1.0;
237 }
238
239
240 while ((bVertical && dCurrentY <= dStartingY + dHeight) || (!bVertical && dCurrentX <= dStartingX + dWidth))
241 {
242
243 if (bVertical)
244 {
245
246 if (bZigNotZag)
247 {
248
249 dCurrentX = dStartingX + (dWidth / 2);
250 }
251 else
252 {
253
254 dCurrentX = dStartingX - (dWidth / 2);
255 }
256 }
257 else
258 {
259
260 if (bZigNotZag)
261 {
262
263 dCurrentY = dStartingY + (dHeight / 2);
264 }
265 else
266 {
267
268 dCurrentY = dStartingY - (dHeight / 2);
269 }
270 }
271
272
273 while ((bZigNotZag && bVertical && dCurrentX <= dStartingX + dWidth) || (!bZigNotZag && bVertical && dCurrentX >= dStartingX) ||
274 (bZigNotZag && !bVertical && dCurrentY <= dStartingY + dHeight) || (!bZigNotZag && !bVertical && dCurrentY >= dStartingY))
275 {
276
278 stCurrentCoordinate.dEasting = dCurrentX;
279 stCurrentCoordinate.dNorthing = dCurrentY;
280 geoops::Waypoint stCurrentWaypoint(stCurrentCoordinate, geoops::WaypointType::eNavigationWaypoint);
281
282 vWaypoints.push_back(stCurrentWaypoint);
283
284
285 if (bVertical)
286 {
287
288 dCurrentX += bZigNotZag ? bCalcSpacing : -bCalcSpacing;
289 }
290 else
291 {
292
293 dCurrentY += bZigNotZag ? bCalcSpacing : -bCalcSpacing;
294 }
295 }
296
297
298 if (bVertical)
299 {
300 dCurrentY += bCalcSpacing;
301 }
302 else
303 {
304 dCurrentX += bCalcSpacing;
305 }
306
307
308 bZigNotZag = !bZigNotZag;
309 }
310
311
312
313
314
315
316
317
318 std::vector<geoops::Waypoint> vFilterWaypoints;
319
320 vFilterWaypoints.push_back(vWaypoints[0]);
321
322 for (size_t i = 0; i < vWaypoints.size() - 1; ++i)
323 {
324
326 if (stGeoMeasurement.dDistanceMeters > bCalcSpacing * 1.5)
327 {
328
329 vFilterWaypoints.push_back(vWaypoints[i]);
330 vFilterWaypoints.push_back(vWaypoints[i + 1]);
331 }
332 }
333
334
335 std::string szSearchPatternPoints = "Search Pattern Points (Spiral): ";
337 {
338 szSearchPatternPoints +=
339 "(" + std::to_string(stWaypoint.GetGPSCoordinate().dLatitude) + ", " + std::to_string(stWaypoint.GetGPSCoordinate().dLongitude) + "), ";
340 }
341
342 LOG_DEBUG(logging::g_qSharedLogger, "{}", szSearchPatternPoints);
343
344
345 return vFilterWaypoints;
346 }
This struct is used to store the distance, arc length, and relative bearing for a calculated geodesic...
Definition GeospatialOperations.hpp:82