Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ 2D tessellation library?

I've got some convex polygons stored as an STL vector of points (more or less). I want to tessellate them really quickly, preferably into fairly evenly sized pieces, and with no "slivers".

I'm going to use it to explode some objects into little pieces. Does anyone know of a nice library to tessellate polygons (partition them into a mesh of smaller convex polygons or triangles)?

I've looked at a few I've found online already, but I can't even get them to compile. These academic type don't give much regard for ease of use.

like image 810
mpen Avatar asked Sep 13 '09 21:09

mpen


People also ask

What is 2D tessellation?

Two-dimensional (2D) tessellation involves the tiling of a plane using one or more closed shapes without the formation of overlaps or gaps.

What is CAD tessellation?

Tessellation is the process of converting a patch-based CAD file to a polygonal mesh. It is the first and most important step in preparing an object for use in realtime graphics.

What is tessellation with example?

A tessellation is a tiling over a plane with one or more figures such that the figures fill the plane with no overlaps and no gaps. You have probably seen tessellations before. Examples of a tessellation are: a tile floor, a brick or block wall, a checker or chess board, and a fabric pattern.


1 Answers

CGAL has packages to solve this problem. The best would be probably to use the 2D Polygon Partitioning package. For example you could generate y-monotone partition of a polygon (works for non-convex polygons, as well) and you would get something like this:

y-monoyone-partitioning y-monoyone-partitioning

The runnning time is O(n log n).

In terms of ease of use this is a small example code generating a random polygon and partitioning it (based on this manual example):

typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Partition_traits_2<K>                         Traits;
typedef Traits::Point_2                                     Point_2;
typedef Traits::Polygon_2                                   Polygon_2;
typedef std::list<Polygon_2>                                Polygon_list;
typedef CGAL::Creator_uniform_2<int, Point_2>               Creator;
typedef CGAL::Random_points_in_square_2<Point_2, Creator>   Point_generator;   


int main( )
{
   Polygon_2    polygon;
   Polygon_list partition_polys;

   CGAL::random_polygon_2(50, std::back_inserter(polygon),
                      Point_generator(100));

   CGAL::y_monotone_partition_2(polygon.vertices_begin(),
                                polygon.vertices_end(),
                                std::back_inserter(partition_polys));

   // at this point partition_polys contains the partition of the input polygons
   return 0;
}

To install cgal, if you are on windows you can use the installer to get the precompiled library, and there are installations guides for every platform on this page. It might not be the simplest to install but you get the most used and robust computational geometry library there is out there, and the cgal mailing list is very helpful to answer questions...

like image 115
balint.miklos Avatar answered Oct 29 '22 03:10

balint.miklos