Main Content

closestPoint

Find closest point on reference path to global point

Since R2020b

Description

example

pathPoints= closestPoint(refPath,points)finds the closest point on the reference path to each of the specified (x,y)-positionspoints.

[pathPoints,inWindow] = closestPoint(refPath,points)optionally returns a logical vectorinWindow, specifying whether each point for the correspondingxycoordinate inpointsis projected within the search window..

[_] = closestPoint(refPath,points,searchWindow)optionally accepts a nondecreasing row vectorsearchWindow, which defines the interval of the path to use to find the closest points.

Examples

collapse all

Generate a reference path from a set of waypoints.

waypoints = [0 0; 50 20; 100 0; 150 10]; refPath = referencePathFrenet(waypoints);

创建一个trajectoryGeneratorFrenetobject from the reference path.

connector = trajectoryGeneratorFrenet(refPath);

生成一个五秒钟的轨迹之间的路径origin and a point 30 meters down the path as Frenet states.

initCartState = refPath.SegmentParameters(1,:); initFrenetState = global2frenet(refPath,initCartState); termFrenetState = initFrenetState + [30 zeros(1,5)]; frenetTraj = connect(connector,initFrenetState,termFrenetState,5);

Convert the trajectory to the global states.

globalTraj = frenet2global(refPath,frenetTraj.Trajectory);

Display the reference path and the trajectory.

show(refPath); axisequalholdonplot(globalTraj(:,1),globalTraj(:,2),'b')

Specify global points and find the closest points on reference path.

globalPoints = waypoints(2:end,:) + [20 -50]; nearestPathPoint = closestPoint(refPath,globalPoints);

Display the global points and the closest points on reference path.

plot(globalPoints(:,1),globalPoints(:,2),'r*','MarkerSize',10) plot(nearestPathPoint(:,1),nearestPathPoint(:,2),'b*','MarkerSize',10)

Interpolate between the arc lengths of the first two closest points along the reference path.

arclengths = linspace(nearestPathPoint(1,6),nearestPathPoint(2,6),10); pathStates = interpolate(refPath,arclengths);

Display the interpolated path points.

plot(pathStates(:,1),pathStates(:,2),'g') legend(["Waypoints","Reference Path","Trajectory to 30m",..."Global Points","Closest Points","Interpolated Path Points"])

Figure contains an axes object. The axes object contains 6 objects of type line. One or more of the lines displays its values using only markers These objects represent Waypoints, Reference Path, Trajectory to 30m, Global Points, Closest Points, Interpolated Path Points.

Input Arguments

collapse all

Reference path, specified as areferencePathFrenetobject.

Global points, specified as aP-by-2 numeric matrix with rows of the form[x y].Pis the number of points. Positions are in meters.

Search window on path to determine closest points, specified as an two-element row vector.

Output Arguments

collapse all

Closest points on the reference path , returned as anN-by-6 numeric matrix with rows of form[xythetakappadkappas], where:

  • xyandtheta— SE(2) state expressed in global coordinates, withxandyin meters andthetain radians

  • kappa— Curvature, or inverse of the radius, inm-1

  • dkappa— Derivative of curvature with respect to arc length inm-2

  • s— Arc length, or distance along path from path origin, in meters

Nis the number of points sampled along the reference path.

Indication whether each point nearest to the correspondingxycoordinate inpoints, is projected within the search window, returned as anN-element logical column vector, whereNis the number of points inpoints. Points being projected within the search window aretrue, orfalseif they lie at the end of a window.

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

版本History

Introduced in R2020b