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.
129 {
130
131 std::vector<geoops::Waypoint> vWaypoints;
132 double dStartingX = stCenterPoint.
GetUTMCoordinate().dEasting - (dWidth / 2);
133 double dStartingY = stCenterPoint.
GetUTMCoordinate().dNorthing - (dHeight / 2);
134 double dCurrentX = dStartingX;
135 double dCurrentY = dStartingY;
136 bool bZigNotZag = true;
137 double bCalcSpacing = dSpacing;
138
139
140 if (dWidth < 1 || dHeight < 1 || dSpacing < 1)
141 {
142
143 LOG_WARNING(logging::g_qSharedLogger, "Width or height or spacing is less than 1 meter. Cannot create zigzag pattern.");
144 return vWaypoints;
145 }
146
147
148 if (bCalcSpacing > dWidth / 2.0)
149 {
150
151 LOG_WARNING(logging::g_qSharedLogger, "Spacing is greater than width. Setting spacing to width / 2.");
152
153 bCalcSpacing = dWidth / 2.0 - 1.0;
154 }
155 if (bCalcSpacing > dHeight / 2.0)
156 {
157
158 LOG_WARNING(logging::g_qSharedLogger, "Spacing is greater than height. Setting spacing to height / 2.");
159
160 bCalcSpacing = dHeight / 2.0 - 1.0;
161 }
162
163
164 while ((bVertical && dCurrentY <= dStartingY + dHeight) || (!bVertical && dCurrentX <= dStartingX + dWidth))
165 {
166
167 if (bVertical)
168 {
169
170 if (bZigNotZag)
171 {
172
173 dCurrentX = dStartingX + bCalcSpacing;
174 }
175 else
176 {
177
178 dCurrentX = dStartingX - bCalcSpacing;
179 }
180 }
181 else
182 {
183
184 if (bZigNotZag)
185 {
186
187 dCurrentY = dStartingY + bCalcSpacing;
188 }
189 else
190 {
191
192 dCurrentY = dStartingY - bCalcSpacing;
193 }
194 }
195
196
197 while ((bZigNotZag && bVertical && dCurrentX <= dStartingX + dWidth) || (!bZigNotZag && bVertical && dCurrentX >= dStartingX) ||
198 (bZigNotZag && !bVertical && dCurrentY <= dStartingY + dHeight) || (!bZigNotZag && !bVertical && dCurrentY >= dStartingY))
199 {
200
202 stCurrentCoordinate.dEasting = dCurrentX;
203 stCurrentCoordinate.dNorthing = dCurrentY;
204 geoops::Waypoint stCurrentWaypoint(stCurrentCoordinate, geoops::WaypointType::eNavigationWaypoint);
205
206 vWaypoints.push_back(stCurrentWaypoint);
207
208
209 if (bVertical)
210 {
211
212 dCurrentX += bZigNotZag ? bCalcSpacing : -bCalcSpacing;
213 }
214 else
215 {
216
217 dCurrentY += bZigNotZag ? bCalcSpacing : -bCalcSpacing;
218 }
219 }
220
221
222 if (bVertical)
223 {
224 dCurrentY += bCalcSpacing;
225 }
226 else
227 {
228 dCurrentX += bCalcSpacing;
229 }
230
231
232 bZigNotZag = !bZigNotZag;
233 }
234
235
236
237
238
239
240
241
242 std::vector<geoops::Waypoint> vFilterWaypoints;
243
244 vFilterWaypoints.push_back(vWaypoints[0]);
245
246 for (size_t i = 0; i < vWaypoints.size() - 1; ++i)
247 {
248
250 if (stGeoMeasurement.dDistanceMeters > bCalcSpacing * 1.5)
251 {
252
253 vFilterWaypoints.push_back(vWaypoints[i]);
254 vFilterWaypoints.push_back(vWaypoints[i + 1]);
255 }
256 }
257
258
259 std::string szSearchPatternPoints = "Search Pattern Points (Spiral): ";
261 {
262 szSearchPatternPoints +=
263 "(" + std::to_string(stWaypoint.GetGPSCoordinate().dLatitude) + ", " + std::to_string(stWaypoint.GetGPSCoordinate().dLongitude) + "), ";
264 }
265
266 LOG_DEBUG(logging::g_qSharedLogger, "{}", szSearchPatternPoints);
267
268
269 return vFilterWaypoints;
270 }
This struct is used to store the distance, arc length, and relative bearing for a calculated geodesic...
Definition GeospatialOperations.hpp:82