PIXELBANKv9.1.0
Menu

ICP Nearest Neighbor

Implement a function to find the closest point in a target point cloud for each source point, a crucial step in the Iterative Closest Point (ICP) algorithm. This process is essential in 3D scanning and reconstruction to align two point clouds by establishing correspondences between them.

The ICP algorithm relies on the concept of Euclidean distance to measure the proximity between points in 3D space, calculated as d(p,q)=(px−qx)2+(py−qy)2+(pz−qz)2d(p, q) = \sqrt{(p_x - q_x)^2 + (p_y - q_y)^2 + (p_z - q_z)^2}. To find the closest point, one must iterate through all target points and determine which point yields the minimum distance for each source point.

Here are the general steps involved:

  1. Iterate over each source point
  2. For each source point, calculate the distance to all target points
  3. Identify the target point with the minimum distance for each source point
d(p,q)=(px−qx)2+(py−qy)2+(pz−qz)2d(p, q) = \sqrt{(p_x - q_x)^2 + (p_y - q_y)^2 + (p_z - q_z)^2}

This technique is widely used in computer vision and robotics for 3D reconstruction and object recognition.

Example:

Input:
find_closest([[0, 0, 0], [1, 0, 0]], [[0.1, 0, 0], [0.9, 0, 0], [5, 5, 5]])
Output:
[0, 1]
Reasoning:

Finding closest targets for 2 source points: Source [0,0,0]: to [0.1,0,0]: d = 0.1 to [0.9,0,0]: d = 0.9 to [5,5,5]: d = 8.66

  • → closest is index 0

Source [1,0,0]: to [0.1,0,0]: d = 0.9 to [0.9,0,0]: d = 0.1 ← closest to [5,5,5]: d = 7.81

  • → closest is index 1

Constraints:

  • source_points: list of [x, y, z] points
  • target_points: list of [x, y, z] points
  • Return list of indices of closest target points
🔒

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test Results

0/0
Run code to see test results.
ICP Nearest Neighbor - Medium | PixelBank