Two scans of a room
The code simulates a 2D LIDAR with 180 beams and 1 cm range noise in a 10 m by 6 m room with a box and a partition. The reference scan is taken at m with heading 0. The new scan is taken 1.2 m away and turned by 20°. Each scan is returned in the frame of the sensor that took it. A person stands in the room for the new scan only; the code leaves it out until the part on outliers.The fit for known pairs
Suppose the pairs were known: point of the new scan is the same surface point as of the reference, for . The rotation and translation that align them minimize The minimum has a closed form (Arun, Huang and Blostein, 1987). Setting the derivative with respect to to zero gives , where and are the centroids of the two point sets. The best translation moves the rotated centroid of one set onto the centroid of the other. Substituting it back, with centered points and , leaves because a rotation does not change lengths. Minimizing is the same as maximizing where is the cross-covariance of the centered pairs. Write its singular value decomposition . Then . The matrix is orthogonal, so its diagonal entries are at most 1, and the trace is largest when : If the points are nearly collinear or very noisy, can come out as a reflection, with determinant . The rotation closest to it is obtained by flipping the sign of the last column of . The code applies the fit to the new scan with the true pairs, which the simulation knows because both scans can be cast from the same beams. It recovers the pose up to the noise.Iterating over guessed pairs
In practice the pairs are unknown, and the two scans do not even hit the walls at the same points. ICP replaces the true pairs with a guess and refines the guess:- Transform the new scan with the current estimate of .
- Pair each transformed point with its nearest point in the reference.
- Fit to these pairs with the closed form above.
- Repeat until the estimate stops changing.
ICP as least squares
The closed form works only for the squared distance between paired points. Other errors need a general method. Parameterize the pose by and stack the residuals They are linear in and nonlinear in . Gauss-Newton linearizes them around the current estimate. The Jacobian of with respect to is and the update solves the normal equations with a weight matrix for each pair, the identity for now. For point pairs, one Gauss-Newton step per iteration reaches the same pose as the closed form, here in the same 16 iterations. Its advantage is that any residual with a Jacobian fits the same loop, and the weights can differ from pair to pair. The next two parts use both.Point-to-line error
The two scans sample a wall at different points. Even at the true pose a point of the new scan lies between two reference points, a few centimeters from either, so the point-to-point error never reaches zero, and it pulls the scan along the wall toward the sampled points. The error that matters is the distance across the wall. Chen and Medioni (1992) measured it from each point to the plane through its partner; in 2D the plane is a line. With the unit normal of the reference scan at , the residual becomes a scalar, A point can slide along the wall without cost, and only its distance from the wall counts. The normals come from the reference scan: for each point, fit a line to it and its four nearest neighbors, and take the direction of least spread as the normal.Outliers
Not every point of the new scan has a partner in the reference. A person who walked in between the scans, a door that moved, or a part of the room that only one scan sees all produce points whose nearest neighbor lies on a different surface. Least squares gives each of them a weight that grows with the square of its residual, so a few of them can pull the whole alignment. A robust error replaces the square with a function that grows more slowly for large residuals. In the Gauss-Newton loop this only changes the weights: each pair gets a weight computed from its current residual , and the weighted problem is solved as before. The Huber weight with threshold is which keeps the square for small residuals and makes the cost linear beyond . A cruder alternative drops every pair with a residual above a threshold. The code repeats the point-to-line run with a new scan that also sees the person, standing between the two poses, once with plain least squares and once with Huber weights and cm.ICP in practice
Real implementations add a few things that the code above leaves out. They find nearest neighbors with a k-d tree or a voxel grid instead of comparing every pair of points. They subsample dense scans, often to one point per voxel. They reject pairs farther apart than a threshold that shrinks as the alignment improves, which combines the trimming above with the robust weights. And they check the result: a large final residual, or a Hessian that is nearly singular, as in a long featureless corridor where the scan can slide along the walls, marks an alignment that should not be trusted. KISS-ICP (Vizzo et al., 2023) is a recent LIDAR odometry system built almost entirely from these parts: point-to-point ICP on a voxel map, a motion prediction from the previous scans as the starting estimate, and a robust kernel whose threshold adapts to how well recent scans have aligned. Not every 2D SLAM system uses ICP. slam_toolbox, the default SLAM package of Nav2, matches scans with a correlative matcher that evaluates a grid of candidate poses against a likelihood map, which does not depend on a good starting estimate in the same way.References
- Arun, K. S., Huang, T. S., and Blostein, S. D. (1987). Least-squares fitting of two 3-D point sets. IEEE Transactions on Pattern Analysis and Machine Intelligence.
- Besl, P. J., and McKay, N. D. (1992). A method for registration of 3-D shapes. IEEE Transactions on Pattern Analysis and Machine Intelligence.
- Chen, Y., and Medioni, G. (1992). Object modelling by registration of multiple range images. Image and Vision Computing.
- Vizzo, I., Guadagnino, T., Mersch, B., Wiesmann, L., Behley, J., and Stachniss, C. (2023). KISS-ICP: In defense of point-to-point ICP, simple, accurate, and robust registration if done the right way. IEEE Robotics and Automation Letters.
Found an error on this page? Report an issue.

