npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

icp2d

v0.0.3

Published

Iterative Closest Point (ICP) on 2D points

Downloads

7

Readme

Iterative Closest Point (ICP) for 2D Points Library

A simple TypeScript library for performing the Iterative Closest Point (ICP) algorithm on 2D point clouds, with zero dependencies. This library works both in the browser and in Node.js and is compatible with JavaScript and TypeScript.

Table of Contents

Installation

npm install icp2d

Usage

To use the ICP algorithm for aligning 2D point clouds, you can call the icp function, which calculates the transformation between two sets of 2D points (source and target).

import { icp, Point } from 'icp2d';

// Define your source and target point clouds (arrays of 2D Cartesian coordinates)
const source: Point[] = [
  [0, 0],
  [1, 0],
  [0, 1]
];

const target: Point[] = [
  [1, 1],
  [2, 1],
  [1, 2]
];

// Perform the ICP algorithm to align the source point cloud to the target
const res = icp(source, target);
console.log(res.sourceTransformed);
console.log(res.translation);
console.log(res.rotationMatrix)

Output

The output includes the rotation matrix (R), translation vector (t), transformed points, and the rotation in degrees. Example:

import { Result } from 'icp2d';

const res: Result = {
  sourceTransformed: Point[]; // Transformed points
  translation: Point; // t - Translation vector
  rotation: number; // Rotation in degrees
  rotationMatrix: Matrix2x2; // R - Rotation matrix
  err: number; // Error calculated using RMS
};

Available options

import { Options } from 'icp2d';

const options: Options = {
  tolerance: 10e6, // Convergence tolerance
  maxIterations: 500, // Maximum number of iterations
  verbose: true, // Outputs additional logs
  filterOutliers: {
    strategy: 'none' | 'maxDistance' | 'std'; // Strategy options for detecting outliers
    maxDistance: 500; // Optional, used for the max distance strategy
    threshold: 2; // Optional, used for the standard deviation strategy
  }
};

Improving Results by Filtering Noise

Filtering noise can significantly enhance the accuracy of the ICP algorithm. You can see its effects in different examples in test.ipynb. Here are different strategies to filter noise:

  • Max Distance Strategy: Removes points that are further than a defined maximum distance from their closest neighbor in the target set.
const options = {
  filterOutliers: {
    strategy: 'maxDistance',
    maxDistance: 500
  }
};
  • Standard Deviation Strategy: Excludes points that deviate too much from the mean error using a threshold based on standard deviation.
const options = {
  filterOutliers: {
    strategy: 'std',
    threshold: 2
  }
};
  • None: Retains all points, without filtering.
const options = {
  filterOutliers: {
    strategy: 'none'
  }
};

Using these strategies helps to remove outliers that can distort transformation calculations, leading to more stable and accurate results.

Examples

You can find real-world test cases in test.ipynb. verify-transforms.ipynb verifies that the computed transformations are correct.

Ideas

  • Add DBSCAN for identifying outliers.