项目作者: mattools

项目描述 :
Matlab geometry toolbox for 2D/3D geometric computing
高级语言: MATLAB
项目地址: git://github.com/mattools/matGeom.git
创建时间: 2015-04-27T11:35:25Z
项目社区:https://github.com/mattools/matGeom

开源协议:BSD 2-Clause "Simplified" License

下载


MatGeom

MATLAB geometry processing library in 2D/3D.

View matGeom on File Exchange
DOI

MatGeom is a library for geometry processing / geometric computing with MATLAB in 2D and 3D.
MatGeom is a “function-based” library: it contains several hundreds of functions for the creation,
manipulation and display of 2D and 3D shapes such as point sets, lines, ellipses, polygons,
3D polygonal meshes, …
The official homepage for the project is http://github.com/mattools/matGeom.

A user manual
containing a large number of illustrations and examples is available.
Starting from February 2022, the HTML pages of the functions (obtained with m2html) are available
here.

The MatGeom library corresponds to the concatenation of the
geom2d
and
geom3d
libraries that were distributed on the FileExchange. Distribution as a single library greatly
facilitates the interoperability of the functions.

If you use matGeom for your research, please be kind enough to cite the following article:

Package organization

The library is organized into several modules:

  • geom2d - General functions in Euclidean plane
  • polygons2d - Functions operating on polygons and polylines represented as list of vertices
  • graphs - Manipulation of geometric graphs
  • geom3d - General functions in 3D Euclidean space
  • meshes3d - Manipulation of 3D polygonal meshes (trimesh, quadmesh, or more generic meshes)

Quick overview

Fit geometries to point data

Basic functionalities comprise creation of simple geometries such as points, lines, ellipses…
A simple example is provided with the following script.

  1. % load data
  2. iris = load('fisheriris');
  3. pts = iris.meas(:, [3 1]);
  4. % display
  5. figure; axis equal; hold on; axis([0 8 3 9]);
  6. drawPoint(pts, 'bx');
  7. % Fit line
  8. line = fitLine(pts);
  9. drawLine(line, 'color', 'k', 'linewidth', 2);
  10. % Draw oriented box of whole data set
  11. obox = orientedBox(pts);
  12. drawOrientedBox(obox, 'color', 'k', 'linewidth', 1);
  13. % identifiy species index
  14. [labels, ~, inds]= unique(iris.species);
  15. % for ech species, compute equivalent ellipse and display with axes
  16. colors = [1 0 0; 0 0.8 0; 0 0 1];
  17. for i = 1:3
  18. pts_i = pts(inds == i, :);
  19. drawPoint(pts_i, 'marker', 'x', 'color', colors(i,:), 'linewidth', 2);
  20. elli = equivalentEllipse(pts_i);
  21. drawEllipse(elli, 'color', colors(i,:), 'linewidth', 2)
  22. drawEllipseAxes(elli, 'color', colors(i,:), 'linewidth', 2)
  23. end

Computation of equivalent ellipses, oriented box, and fitting line from set of points

Polygon data processing

It is possible to work with more complex shapes such as polygonal lines (“polylines”) or polygons.
Common operations comprise smoothing, simplification (retaining only a selection of vertices),
computation of convex hull or of intersections with other geometric primitives.
A summary of typical operations in presented in the following script.

  1. % read polygon data as a numeric N-by-2 array
  2. poly = load('leaf_poly.txt');
  3. % display the polygon using basic color option
  4. figure; axis equal; hold on; axis([0 600 0 400]);
  5. drawPolygon(poly, 'k');
  6. % Bounding box of the polygon
  7. poly_bnd = boundingBox(poly);
  8. drawBox(poly_bnd, 'k');
  9. % computes convex hull of polygon vertices
  10. poly_hull = convexHull(poly);
  11. drawPolygon(poly_hull, 'LineWidth', 2, 'Color', 'k');
  12. % applies smoothing to the original polygon.
  13. poly_smooth = smoothPolygon(poly, 51);
  14. drawPolygon(poly_smooth, 'color', 'b', 'linewidth', 2);
  15. % Computes a simplified version of the polygon
  16. poly_simpl = simplifyPolygon(poly, 20);
  17. drawPolygon(poly_simpl, 'color', 'r', 'linewidth', 2);
  18. drawVertices(poly_simpl, 'Color', 'k', 'Marker', 's', 'MarkerFaceColor', 'w');
  19. % compute intersections with an arbitrary line
  20. line = createLine([0 250], [600 350]);
  21. drawLine(line, 'k');
  22. inters = intersectLinePolygon(line, poly_simpl);
  23. drawPoint(inters, 'Color', 'r', 'Marker', 'o', 'MarkerFaceColor', 'w', 'linewidth', 2);

Summary of polygon processing operations: smoothing, simplification, convex hull, intersection with lines.

Polygon mesh processing

The MatGeom library also provides features for polygon mesh processing.
Mesh data can be retrieved from common mesh file formats,
or generated from simple data,
and various operations can be performed: intersections (with lines or planes), clipping by plane,
distance to point…
Several measurements on meshes are also provided: main curvatures, surface area, bounding box…

Summary of polygon mesh processing operations: smoothing, simplification, convex hull, intersection with lines.