Geometry library for matlab. Performs geometric computations on points, lines, circles, polygons...
Updated 26 Sep 2019

View License

Editor's Note: This file was selected as MATLAB Central Pick of the Week

Geometry library to handle and visualize geometric primitives such as points, lines, circles and ellipses, polylines and polygons...
The goal is to provide a low-level library for manipulating geometrical primitives, making easier the development of more complex geometric algorithms.
The library proposes functions to:
* create various shapes (points, circles, lines, ellipses, polylines, polygons) using an intuitive syntax. Ex: createCircle(p1, p2, p3) to create a circle through 3 points, create parallel and perpendicular lines
* compute intersections between 2 lines, between a line and a circle
* work on polylines and polygons: compute centroid and area, expand, clip with half-plane...
* measure distances (between points, a point and a line, a point and a group of points), angle (of a line, between 3 points), or test geometry (point on a line, on a circle).
* manipulate planar transformations. Ex: P2 = transformPoint(P1, createRotation(CENTER, THETA));
* draw shapes easily. Ex: drawCircle([50 50], 25), drawLine([X0 Y0 DX DY]). Some clipping is performed for infinite shapes such as lines or rays.
Additional help is provided in geom/Contents.m file, as well as summary files like 'points2d.m' or 'lines2d.m'.
Note: the project has merged with the geom3d library (FeX 24484), and is now hosted on GitHub:

Cite As

David Legland (2024). geom2d (, MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2019a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!










Version Published Release Notes

renamed inertiaEllipse into equivalentEllipse, added principalAxes, various bug fixes.


new functions for polygons: polygonInertiaEllipse.m, polygonSecondAreaMoments.m, boxToPolygon ; also improves numerical precision of some functions.
add new functions for polygons

update project link

* added new functions: randomPointInPolygon, resamplePolygonByLength, polygonEdges
* improved precision of computation for several functions (eg isPointOnEdge, isParallel/isPerpendicular...)
* updated intersectLineCircle, minDistancePoints

various updates in header docs

remove license statements

add missing utility directory, update description

update computation of polygon/polyline self-intersections, add registerICP for Iterative Closest Point registration, add some functions (polygonSymmetryAxis, signatureToPolygon).
Some deprecated functions were removed.

update medialAxisConvex, add smoothPolygon, smoothPolyline, findClosestPoint functions

fix several bugs (clipEdge, removeMultipleVertices...), various doc update, add some demos for polynomial curves

various code cleanup and doc updates

lot of code cleanup, new functions for working with polygons, clean up drawing functions

fixed bugs in intersectLineCircle, added minimumCaliperDiameter and averagePointSet of a set of points. Now uses degrees for representing shapes

split library in several packages, add several functions (circle and circle-line intersections, computation of inertia ellipse)

fix bugs (intersectLines, isPointOnEdge), remove obsolete licence considerations

bug fixes (isPointOnEdge, intersectPolylines), remove obsolete licence info