Contenuto principale

Generate Trajectory Live Editor Task for Flight Mission with No-Fly Zones

R2026b
Since R2026a

This example shows how to use the Generate Trajectory live task to create a trajectory for a flight mission with no-fly zones using waypoints.

Add Waypoints Using Generate Trajectory Live Task

On the Live Editor tab, select Insert > Task, then select Generate Trajectory.

Live Task

To see the generated code, select Show code.

Define No-Fly Zones

Define the bounding area for the no-fly zones. To compute convex hull indices, use the convhull function, and then plot the area and fill in the no-fly zones.

Outline the perimeter of the no-fly zone.

xlim = [0 50];
ylim = [0 50];

Define a consistent set of boundary waypoints inside the boundary area.

x = [10 20 35 40 30 15 5 12 28 22];
y = [10 40 45 30 20 5 25 15 38 18];

nfzBoundaryPoints = [x(:), y(:)];

Use the convhull function to compute the convex hull indices, and then plot the area and fill in the no-fly zones.

hullIdx = convhull(x, y);

% Plot the square area
figure;

hold on;
rectangle('Position',[xlim(1), ylim(1), xlim(2)-xlim(1), ylim(2)-ylim(1)], ...
    'EdgeColor','k','LineStyle','--');

% Plot the points
plot(x, y, 'bo', 'MarkerFaceColor', 'b');

% Plot the convex hull boundary
plot(x(hullIdx), y(hullIdx), 'r-', 'LineWidth', 2);

Fill the no-fly zone, and then define the axis settings.

% Fill the no-fly zone
fill(x(hullIdx), y(hullIdx), 'r', 'FaceAlpha', 0.2, 'EdgeColor', 'none');

% Axis settings
axis([xlim ylim]);
axis equal;
title('No-Fly Zone Boundary Using convhull');
xlabel('North');
ylabel('East');
legend('Points','No-Fly Zone Boundary','No-Fly Zone', 'Location', 'bestoutside');
hold off;

Figure contains an axes object. The axes object with title No-Fly Zone Boundary Using convhull, xlabel North, ylabel East contains 4 objects of type rectangle, line, patch. One or more of the lines displays its values using only markers These objects represent Points, No-Fly Zone Boundary, No-Fly Zone.

Get Suitable Path Avoiding No-Fly Zones

Compute the rerouted trajectory based on No-fly zone Boundary points.

reroutedTrajectory = Aero.trajectory.polylineTrajectory("PriorTrajectory", Vehicle1Traj, "SegmentDistance", 0.01, "AbsoluteBearing", 0, "Altitude", 0,...
    "NFZBoundaryPoints", nfzBoundaryPoints, "NFZAltitudeBound", 10, "Speed", 10);

xReroutedTrajectory = reroutedTrajectory.xNorth.Data;
yReroutedTrajectory = reroutedTrajectory.yEast.Data;

Plot Trajectory

Plot the original trajectory as a dotted black line, rerouted trajectory

figure;
hold on;
xTraj = Vehicle1Traj.xNorth.Data;
yTraj = Vehicle1Traj.yEast.Data;
plot(xTraj, yTraj, 'k:', 'LineWidth', 2); % Dotted black line

% Draw the plotting window rectangle (based on current axis limits)
rectangle('Position', [xlim(1), ylim(1), xlim(2)-xlim(1), ylim(2)-ylim(1)], ...
    'EdgeColor', 'k', 'LineStyle', '--');

% Plot the input points
plot(x, y, 'bo', 'MarkerFaceColor', 'b');

% Plot the convex hull boundary
plot(x(hullIdx), y(hullIdx), 'r-', 'LineWidth', 2);

% Fill the no-fly zone
fill(x(hullIdx), y(hullIdx), 'r', 'FaceAlpha', 0.2, 'EdgeColor', 'none');

% Axis settings
axis([xlim ylim]);
axis equal;
title('No-Fly Zone Boundary Using convhull');
xlabel('North');
ylabel('East');

% Plot rerouted trajectory and intersection points
plot(xReroutedTrajectory, yReroutedTrajectory, 'm-', 'LineWidth', 2);
plot(10, 10, 'ks', 'MarkerFaceColor', 'y', 'MarkerSize', 10); % Entry
plot(35.0541 , 45.0841, 'ks', 'MarkerFaceColor', 'c', 'MarkerSize', 10); % Exit
legend('Original Trajectory', 'Points', 'No-Fly Zone Boundary', 'No-Fly Zone', ...
       'Obstacle-free Trajectory', 'Entry', 'Exit', 'Location', 'bestoutside');
hold off;

Figure contains an axes object. The axes object with title No-Fly Zone Boundary Using convhull, xlabel North, ylabel East contains 8 objects of type line, rectangle, patch. One or more of the lines displays its values using only markers These objects represent Original Trajectory, Points, No-Fly Zone Boundary, No-Fly Zone, Obstacle-free Trajectory, Entry, Exit.

clearvars -except Vehicle1Traj reroutedTrajectory

See Also

Topics