41 const bool atXy = std::hypot(target.
x - current.
x, target.
y - current.
y) <= p.
tolerance;
42 if (atXy && std::fabs(current.
z - target.
z) <= p.
tolerance)
48 return {start, target};
54 const float cx = pick(p.
centerX, current.
x);
55 const float cy = pick(p.
centerY, current.
y);
57 const float r = std::max(p.
radius, 0.5f);
69 const int count = p.
count;
73 const float dx = current.
x - cx;
74 const float dy = current.
y - cy;
76 std::hypot(dx, dy) > 0.1f ? std::atan2(dy, dx) : (std::isnan(current.
yaw) ? 0.0f : current.
yaw);
78 std::vector<NedPoint> path;
79 path.reserve(
static_cast<size_t>(count) *
static_cast<size_t>(n) + 1);
80 for (
int k = 0; k <= count * n; ++k)
82 const float theta = theta0 + sign * 2.0f *
static_cast<float>(M_PI) *
static_cast<float>(k) /
83 static_cast<float>(n);
85 v.
x = cx + r * std::cos(theta);
86 v.
y = cy + r * std::sin(theta);
99 float ux = 0.0f, uy = 0.0f;
106 const float dx = endX - start.
x;
107 const float dy = endY - start.
y;
108 leg.
length = std::hypot(dx, dy);
122 const float cx = pick(p.
centerX, current.
x);
123 const float cy = pick(p.
centerY, current.
y);
125 const float a = std::max(p.
size, 0.5f);
138 const float heading =
140 const float ch = std::cos(heading);
141 const float sh = std::sin(heading);
144 std::vector<NedPoint> loop;
145 loop.reserve(
static_cast<size_t>(n));
146 for (
int k = 0; k < n; ++k)
149 sign * 2.0f *
static_cast<float>(M_PI) *
static_cast<float>(k) /
static_cast<float>(n);
150 const float st = std::sin(t);
151 const float ct = std::cos(t);
152 const float denom = 1.0f + st * st;
153 const float lx = a * ct / denom;
154 const float ly = a * st * ct / denom;
156 v.
x = cx + lx * ch - ly * sh;
157 v.
y = cy + lx * sh + ly * ch;
165 float best = std::numeric_limits<float>::infinity();
166 for (
int k = 0; k < n; ++k)
168 const float d = std::hypot(loop[k].x - current.
x, loop[k].y - current.
y);
176 std::vector<NedPoint> path;
177 path.reserve(
static_cast<size_t>(p.
count) *
static_cast<size_t>(n) + 1);
178 for (
int k = 0; k <= p.
count * n; ++k)
180 path.push_back(loop[
static_cast<size_t>((start + k) % n)]);
188 return 5.2441f * std::max(p.
size, 0.5f) *
static_cast<float>(std::max(p.
count, 0));
194 const float endX = pick(p.
endX, current.
x);
195 const float endY = pick(p.
endY, current.
y);
197 const float lambda = std::max(p.
wavelength, 0.1f);
199 const Leg leg = legFrom(current, endX, endY);
201 std::vector<NedPoint> path;
202 if (leg.length <= 1e-3f)
204 path.push_back(
NedPoint{endX, endY, zBase, kNaN});
208 const int n =
static_cast<int>(std::floor(leg.length / spacing));
209 path.reserve(
static_cast<size_t>(n) + 2);
210 for (
int k = 0; k < n; ++k)
212 const float s =
static_cast<float>(k) * spacing;
214 v.
x = current.
x + s * leg.ux;
215 v.
y = current.
y + s * leg.uy;
216 v.
z = zBase - p.
amplitude * std::sin(2.0f *
static_cast<float>(M_PI) * s / lambda);
219 path.push_back(
NedPoint{endX, endY, zBase, kNaN});
226 const float endX = pick(p.
endX, current.
x);
227 const float endY = pick(p.
endY, current.
y);
229 const float lambda = std::max(p.
wavelength, 0.1f);
231 const Leg leg = legFrom(current, endX, endY);
233 std::vector<NedPoint> path;
234 if (leg.length <= 1e-3f)
236 path.push_back(
NedPoint{endX, endY, z, kNaN});
241 const float nx = leg.uy;
242 const float ny = -leg.ux;
244 const int n =
static_cast<int>(std::floor(leg.length / spacing));
245 path.reserve(
static_cast<size_t>(n) + 2);
246 for (
int k = 0; k < n; ++k)
248 const float s =
static_cast<float>(k) * spacing;
249 const float offset = p.
amplitude * std::sin(2.0f *
static_cast<float>(M_PI) * s / lambda);
251 v.
x = current.
x + s * leg.ux + offset * nx;
252 v.
y = current.
y + s * leg.uy + offset * ny;
256 path.push_back(
NedPoint{endX, endY, z, kNaN});
263 const float ox = pick(p.
originX, current.
x);
264 const float oy = pick(p.
originY, current.
y);
266 const float spacing = std::max(p.
spacing, 0.5f);
270 std::vector<NedPoint> path;
271 path.reserve(
static_cast<size_t>(std::max(p.
numLegs, 0)) + 1);
278 for (
int i = 0; i < p.
numLegs; ++i)
280 const float len = spacing *
static_cast<float>(i / 2 + 1);
285 v.
x += len * std::cos(heading);
286 v.
y += len * std::sin(heading);
288 heading += sign *
static_cast<float>(M_PI) / 2.0f;
295 const float spacing = std::max(p.
spacing, 0.5f);
297 for (
int i = 0; i < p.
numLegs; ++i)
299 const float len = spacing *
static_cast<float>(i / 2 + 1);
312 const float cx = pick(p.
centerX, current.
x);
313 const float cy = pick(p.
centerY, current.
y);
315 const float spacing = std::max(p.
spacing, 0.5f);
316 const float a = spacing / (2.0f *
static_cast<float>(M_PI));
317 const float rStart = std::max(p.
startRadius, 0.0f);
318 const float rEnd = std::max(p.
endRadius, rStart);
323 const float dx = current.
x - cx;
324 const float dy = current.
y - cy;
326 std::hypot(dx, dy) > 0.1f ? std::atan2(dy, dx) : (std::isnan(current.
yaw) ? 0.0f : current.
yaw);
328 const float thetaStart = rStart / a;
329 const float thetaEnd = rEnd / a;
331 std::vector<NedPoint> path;
332 float theta = thetaStart;
333 while (theta < thetaEnd)
335 const float r = a * theta;
337 v.
x = cx + r * std::cos(theta0 + sign * theta);
338 v.
y = cy + r * std::sin(theta0 + sign * theta);
341 theta += ds / std::max(r, a);
344 last.
x = cx + rEnd * std::cos(theta0 + sign * thetaEnd);
345 last.
y = cy + rEnd * std::sin(theta0 + sign * thetaEnd);
347 path.push_back(last);
351 std::reverse(path.begin(), path.end());
359 const float rStart = std::max(p.
startRadius, 0.0f);
360 const float rEnd = std::max(p.
endRadius, rStart);
361 const float spacing = std::max(p.
spacing, 0.5f);
362 return static_cast<float>(M_PI) * (rEnd * rEnd - rStart * rStart) / spacing;
367 const float spacing = std::max(p.
laneSpacing, 0.5f);
368 return std::max(1,
static_cast<int>(std::floor(std::max(p.
width, 0.0f) / spacing + 1e-3f)) + 1);
374 return static_cast<float>(lanes) * std::max(p.
laneLength, 0.0f) +
375 static_cast<float>(lanes - 1) * std::max(p.
laneSpacing, 0.5f);
382 const float heading = pick(p.
laneHeading, std::isnan(current.
yaw) ? 0.0f : current.
yaw);
383 const float ux = std::cos(heading);
384 const float uy = std::sin(heading);
387 const float nx = -uy * side;
388 const float ny = ux * side;
391 const float spacing = std::max(p.
laneSpacing, 0.5f);
392 const float length = std::max(p.
laneLength, 0.0f);
393 const float coveredWidth =
static_cast<float>(lanes - 1) * spacing;
395 float ox = pick(p.
originX, current.
x);
396 float oy = pick(p.
originY, current.
y);
399 ox -= 0.5f * length * ux + 0.5f * coveredWidth * nx;
400 oy -= 0.5f * length * uy + 0.5f * coveredWidth * ny;
403 std::vector<NedPoint> path;
404 path.reserve(2 *
static_cast<size_t>(lanes));
405 for (
int i = 0; i < lanes; ++i)
408 a.
x = ox +
static_cast<float>(i) * spacing * nx;
409 a.
y = oy +
static_cast<float>(i) * spacing * ny;
412 b.
x = a.
x + length * ux;
413 b.
y = a.
y + length * uy;
456 const NedPoint & joint = path.back();
457 std::vector<NedPoint> best;
458 float bestDist = std::numeric_limits<float>::max();
459 for (
int variant = 0; variant < 4; ++variant)
465 first.
laneHeading + ((variant & 1) ? -1.0f : 1.0f) *
static_cast<float>(M_PI) / 2.0f;
468 if (candidate.empty())
472 const float d =
nedDistance(joint, candidate.front());
476 best = std::move(candidate);
479 path.insert(path.end(), best.begin(), best.end());
485 return 9.0f * std::max(p.
radius, 1.0f) *
static_cast<float>(std::max(p.
cycles, 1));
491 const float dx = pick(p.
datumX, current.
x);
492 const float dy = pick(p.
datumY, current.
y);
494 const float r = std::max(p.
radius, 1.0f);
497 const int cycles = std::max(p.
cycles, 1);
501 static const int kSteps[9] = {0, 1, 2, 2, 0, 1, 1, 2, 0};
502 const float third = 2.0f *
static_cast<float>(M_PI) / 3.0f;
504 std::vector<NedPoint> path;
505 path.reserve(9 *
static_cast<size_t>(cycles) + 1);
512 for (
int c = 0; c < cycles; ++c)
514 const float base = h0 + sign * p.
reorientation *
static_cast<float>(c);
515 for (
int leg = 0; leg < 9; ++leg)
517 const float heading = base + sign * third *
static_cast<float>(kSteps[leg]);
518 v.
x += r * std::cos(heading);
519 v.
y += r * std::sin(heading);
Leg legFrom(const NedPoint &start, float endX, float endY)
float altitudeToZ(float altitudeAgl, float currentZ)
float pick(float param, float fallback)
std::vector< NedPoint > generateFlightPatternSpiral(const FlightPatternSpiralParams &p, const NedPoint ¤t)
std::vector< NedPoint > generateFlightPatternFigureEight(const FlightPatternFigureEightParams &p, const NedPoint ¤t)
std::vector< NedPoint > generateFlightPatternSineWaveVertical(const FlightPatternSineWaveVerticalParams &p, const NedPoint ¤t)
std::vector< NedPoint > generateFlightPatternVSSearch(const FlightPatternVSSearchParams &p, const NedPoint ¤t)
std::vector< NedPoint > generateFlightPatternSquareSpiral(const FlightPatternSquareSpiralParams &p, const NedPoint ¤t)
std::vector< NedPoint > generateFlightPatternLoiter(const FlightPatternLoiterParams &p, const NedPoint ¤t)
float flightPatternSquareSpiralLength(const FlightPatternSquareSpiralParams &p)
float nedDistance(const NedPoint &a, const NedPoint &b)
std::vector< NedPoint > generateFlightPatternSineWaveHorizontal(const FlightPatternSineWaveHorizontalParams &p, const NedPoint ¤t)
float flightPatternGridPatternLength(const FlightPatternGridPatternParams &p)
float flightPatternFigureEightLength(const FlightPatternFigureEightParams &p)
std::vector< NedPoint > generateFlightPatternLawnmower(const FlightPatternLawnmowerParams &p, const NedPoint ¤t)
int flightPatternLawnmowerLaneCount(const FlightPatternLawnmowerParams &p)
float flightPatternVSSearchLength(const FlightPatternVSSearchParams &p)
std::vector< NedPoint > generateFlightPatternGridPattern(const FlightPatternGridPatternParams &p, const NedPoint ¤t)
float flightPatternSpiralLength(const FlightPatternSpiralParams &p)
float flightPatternLawnmowerLength(const FlightPatternLawnmowerParams &p)
std::vector< NedPoint > generateFlightPatternAscend(const FlightPatternAscendParams &p, const NedPoint ¤t)
FlightPatternLawnmowerParams base