Main Content

distance

Compute total traveled distance of trajectory data

Since R2024b

Description

traveledDistance = distance(trajectory) returns the total traveled distance traveledDistance of the input trajectory data. Units are in meters.

Note

This function requires the Scenario Builder for Automated Driving Toolbox™ support package. You can install the Scenario Builder for Automated Driving Toolbox support package from the Add-On Explorer. For more information about installing add-ons, see Get and Manage Add-Ons.

example

Examples

collapse all

Load recorded GPS data into the workspace.

load("recordedGPSData.mat","X","Y","Z","timestamps")

Create a trajectory object by using the loaded timestamps and xyz-coordinates.

traj = scenariobuilder.Trajectory(timestamps,X,Y,Z)
traj = 
  Trajectory with properties:

               Name: ''

         NumSamples: 392
           Duration: 19.5498
         SampleRate: 20.0513
         SampleTime: 0.0500
         Timestamps: [392×1 double]

           Position: [392×3 double]
        Orientation: [392×3 double]
           Velocity: [392×3 double]
             Course: [392×1 double]
        GroundSpeed: [392×1 double]
       Acceleration: [392×3 double]
    AngularVelocity: [392×3 double]

        LocalOrigin: [0 0 0]
         TimeOrigin: 0

         Attributes: []

Plot the trajectory object.

plot(traj)

Compute the total traveled distance of the trajectory in the trajectory object. Units are in meters.

traveledDistance = distance(traj)
traveledDistance = 
364.0738

Input Arguments

collapse all

Trajectory with timestamps and waypoints, specified as a Trajectory object.

Output Arguments

collapse all

Total traveled distance of the trajectory the input trajectory, returned as a scalar. The returned traveledDistance is the sum of the piecewise Euclidean distances between the xy-coordinates of each consecutive pair of waypoints. Units are in meters.

Data Types: single

Version History

Introduced in R2024b