Main Content

pcdistance

Compute distance between two point clouds

Since R2026a

Description

Point-to-Point Distance

dists = pcdistance(targetPtCloud,referencePtCloud) returns Euclidean distances between each point in the target point cloud targetPtCloud and its closest point in the reference point cloud referencePtCloud.

example

[dists,indices] = pcdistance(targetPtCloud,referencePtCloud) additionally returns the linear indices of the closest points in the reference point cloud for each point in the target point cloud.

Point-to-Plane Distance

[dists,indices] = pcdistance(targetPtCloud,referencePtCloud,"pointToPlane") returns distances between each point in the target point cloud and corresponding plane estimated from the reference point cloud. For each point in the target point cloud, the function first finds the closest point in the reference point cloud using Euclidean distance. It then finds six nearest neighbors of this closest point to estimate a corresponding plane. Finally, the function computes the perpendicular distance from the target point to the estimated plane.

The function also returns the linear indices of the closest points in the reference point cloud for each point in the target point cloud.

[dists,indices] = pcdistance(targetPtCloud,referencePtCloud,"pointToPlane",NumNeighbors=numNeighbors) specifies the number of nearest neighbors in the reference point cloud to use to fit a plane.

Note

  • The function expects that the target and reference point clouds are aligned with each other.

  • The distance output values are not symmetric. You must carefully define input point clouds as the target and reference point clouds.

Examples

collapse all

Read two point clouds into the workspace.

load("aerialLidarData")
referencePointCloud = aerialLidarData{1};
targetPointCloud = aerialLidarData{2};

Visualize both point clouds. Notice that the target point cloud includes an additional house that is missing from the reference point cloud.

figure
pcshow(referencePointCloud)
xlabel("X")
ylabel("Y")
zlabel("Z")
title("Reference Point Cloud")

Figure contains an axes object. The axes object with title Reference Point Cloud, xlabel X, ylabel Y contains an object of type scatter.

figure
pcshow(targetPointCloud)
xlabel("X")
ylabel("Y")
zlabel("Z")
title("Target Point Cloud")

Figure contains an axes object. The axes object with title Target Point Cloud, xlabel X, ylabel Y contains an object of type scatter.

Compute the distance between the two point clouds.

dists = pcdistance(targetPointCloud,referencePointCloud);

Visualize the differences between the two point clouds as a heatmap. Notice that the heatmap highlights the change, an additional house in the target point cloud.

figure
pcheatmap(targetPointCloud,dists)
xlabel("X")
ylabel("Y")
zlabel("Z")
title("Heatmap of Differences Between Two Point Clouds")

Figure contains an axes object. The axes object with title Heatmap of Differences Between Two Point Clouds, xlabel X, ylabel Y contains an object of type scatter.

Input Arguments

collapse all

Target point cloud, specified as a pointCloud object.

Reference point cloud, specified as a pointCloud object.

Number of neighbors for plane fitting, specified as a positive integer greater than or equal to 3. The function uses this many nearest neighbors in the reference point cloud when fitting a plane.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Output Arguments

collapse all

Distances between the target and reference point clouds, returned as one of these options:

  • M-by-1 vector if the target point cloud is an unorganized point cloud. M is the number of points in the target point cloud.

  • M-by-N matrix if the target point cloud is an organized point cloud. M×N is the total number of points in the target point cloud.

For point-to-point distance computation, the function returns the distance between each point in the target point cloud and its closest point in the reference point cloud. For point-to-plane distance computation, the function returns the distance from each point in the target point cloud to a corresponding plane, which is estimated using the nearest neighbors of the closest point in the reference point cloud.

Linear indices of the closest points in the reference point cloud to each point in the target point cloud, returned as one of these options:

  • M-by-1 vector if the target point cloud is an unorganized point cloud. M is the number of points in the target point cloud.

  • M-by-N matrix if the target point cloud is an organized point cloud. M×N is the total number of points in the target point cloud.

Version History

Introduced in R2026a