主要内容

trajectoryPlotter

R2026b

Trajectory plotter for theater plot

Description

A TrajectoryPlotter object defines a trajectory plotter belonging to a theaterPlot object. Use the plotTrajectory function to plot trajectories using the TrajectoryPlotter object.

Creation

Description

trajPlotter = trajectoryPlotter(tp) creates a TrajectoryPlotter object for use with the theater plot tp.

trajPlotter = trajectoryPlotter(tp,Name,Value) creates a TrajectoryPlotter object with additional options specified by one or more name-value arguments. Specify optional properties using name-value arguments.

example

Input Arguments

expand all

Theater plot, specified as a theaterPlot object.

Properties

expand all

Plot name to display in legend, specified as a character vector or string scalar. If you do not specify this property, no entry is shown in the legend.

Trajectory color, specified as a character vector, a string scalar, an RGB triplet, or a hexadecimal color code.

Line style used to plot the trajectory, specified as one of these values.

ValueDescription
':'

Dotted line (default)

'-'

Solid line

'--'

Dashed line

'-.'

Dash-dotted line

Line width of the trajectory in points, specified as a positive scalar.

Tag associated with the plotter, specified as a character vector or string scalar. The default value is 'PlotterN', where N is an integer that corresponds to the Nth plotter associated with the theaterPlot. You can use the findPlotter function to identify plotters based on their tag.

Object Functions

plotTrajectoryPlot set of trajectories in trajectory plotter
clearDataClear data from specific plotter of theater plot
clearPlotterDataClear plotter data from theater plot

Examples

collapse all

Define the coordinates for three trajectories.

coordinates1 = [(1:10)' (2:11)' (11:-1:2)'];
coordinates2 = coordinates1 + 1;
coordinates3 = coordinates1 + 2;

Create a theaterPlot object, set the view angles, and create a trajectoryPlotter object.

tp = theaterPlot;
view(14,50)
trajPlotter = trajectoryPlotter(tp,DisplayName="Trajectories");

Plot the three trajectories.

plotTrajectory(trajPlotter,{coordinates1,coordinates2,coordinates3})

Figure contains an axes object. The axes object with xlabel X (m), ylabel Y (m) contains an object of type line. This object represents Trajectories.

This example shows how to create an animation of a platform moving on a trajectory.

First, create a trackingScenario and add waypoints for a trajectory.

ts = trackingScenario;
height = 100;
d = 1;
wayPoints = [ ...
    -30   -25   height;
    -30    25-d height;
    -30+d  25   height;
    -10-d  25   height;
    -10    25-d height;
    -10   -25+d height;
    -10+d -25   height;
    10-d -25   height;
    10   -25+d height;
    10    25-d height;
    10+d  25   height;
    30-d  25   height;
    30    25-d height;
    30   -25+d height;
    30   -25   height];

Specify a time for each waypoint.

elapsedTime = linspace(0,10,size(wayPoints,1));

Next, create a platform in the tracking scenario and add trajectory information using the trajectory method.

target = platform(ts);
traj = waypointTrajectory('Waypoints',wayPoints,'TimeOfArrival',elapsedTime);
target.Trajectory = traj;

Record the tracking scenario to retrieve the platform's trajectory.

r = record(ts);
pposes = [r(:).Poses];
pposition = vertcat(pposes.Position);

Create a theater plot to display the recorded trajectory.

tp = theaterPlot('XLim',[-40 40],'YLim',[-40 40]);
trajPlotter = trajectoryPlotter(tp,'DisplayName','Trajectory');
plotTrajectory(trajPlotter,{pposition})

Figure contains an axes object. The axes object with xlabel X (m), ylabel Y (m) contains an object of type line. This object represents Trajectory.

Animate using the platformPlotter.

restart(ts);
trajPlotter = platformPlotter(tp,'DisplayName','Platform');

while advance(ts)
    p = pose(target,'true');
    plotPlatform(trajPlotter, p.Position);
    pause(0.1)
    
end

Figure contains an axes object. The axes object with xlabel X (m), ylabel Y (m) contains 2 objects of type line. One or more of the lines displays its values using only markers These objects represent Trajectory, Platform.

This animation loops through all the generated plots.

Version History

Introduced in R2018b