2D Geometry Libraries for JavaScript

Here is a collection of javascript programming libraries that focus on 2D plane geometry. The collection aims to map the most successful of such libraries and thus the collection is not complete and exhaustive in any way. Each library is associated with a link to the project homepage and my brief comments. Libraries that focus only on some aspect of 2D geometry are listed separately below, as also are the libraries with focus on geospatial (spherical) geometry. Libraries with focus on 3D or above are skipped altogether.

General-purpose 2D geometry libraries

The following libraries provide a wide set of basic geometric shapes and tools to manipulate them but may lack advanced features such as spatial indexing.

  • Flatten-js – Good supply of basic geometric shapes such as point, vector, circle, and affine transformation matrix. Nicely separates the concepts of point and vector. Object-oriented design. Almost 200 stars at GitHub (June 2021). First commit in 2017.
  • Geometric – Minimalistic. Focus on points, line segments, and polygons. Object-oriented design. Over 600 stars at GitHub (June 2021). First commit in 2018.
  • Euclid.ts – Basic geometric shapes such as point, rectangle, ellipse, line, and polygon. Only light treatment of affine geometry and transformations. Immutable, object-oriented design. Written in TypeScript. First commit in 2020.
  • ts-2d-geometry – Basic geometric shapes and math objects, such as point, vector, 3×3 matrix, and affine transformation. Immutable, object-oriented design. Written in TypeScript. First commit in 2020.

Libraries that focus on some aspect of 2D geometry

The list below consists of JavaScript libraries with a specific focus on some aspects of 2D geometry and intentionally lack a full suite of basic geometric shapes.

Collision detection:

  • detect-collisions – Detect collisions between points, circles, polygons
  • SAT.js – Detect collisions between convex shapes

Spatial indexing:

Transformations:

  • nudged – Estimate affine transformations between point sets
  • projection-3d-2d – Perspective transformation between 3D and 2D
  • transformation-matrix – Create and manipulate affine transformation matrices
  • affineplane – Projections between affine 2D planes for various geometries

Other:

Libraries that focus on geospatial geometry

Geometry libraries that focus on spherical surfaces instead of pure 2D planes. We only list them here for reference.

Physics engines

In addition to physical simulation capabilities in 2D, these libraries have a good suite of geometric shapes and collision detection tools.

Other libraries worth to mention

These libraries are not focused only to pure 2D geometry but have 2D tools worth to mention.

  • Paper.js – Object model for Canvas with a suite of 2D geometry objects
  • Tapspace – Zoomable UI library with a suite of 2D geometries and transformations

Conclusion

There are lots of 2D geometry libraries out there. Some provide a wide set of basic geometric shapes such as points, vectors, and circles while others are dedicated to certain algorithm-heavy features, such as spatial indexing. Common to all is the fact that every lib has its unique approach to geometry.

I will update the lists as new promising libraries reach my attention.

Akseli Palén
Hi! I am a creative full-stack web developer and entrepreneur with strong focus on building open source packages for JavaScript community and helping people at StackOverflow. I studied information technology at Tampere University and graduated with distinction in 2016. I wish to make it easier for people to communicate because it is the only thing that makes us one.

1 Comment

Leave a Comment

Your email address will not be published.