## [Libmesh-users] Delaunay Triangulation in LibMesh

 [Libmesh-users] Delaunay Triangulation in LibMesh From: John Peterson - 2006-12-15 21:53:49 ```Hi, It's possible to triangulate arbitrary 2D domains with or without holes in LibMesh using the Triangle library. Attached is a sample code for creating a delaunay triangulation of an L-shaped domain. #include "libmesh.h" #include "mesh_triangle_support.h" #include "mesh.h" int main (int argc, char** argv) { // Use typedefs for slightly less typing. typedef TriangleInterface::Hole Hole; typedef TriangleInterface::PolygonHole PolygonHole; typedef TriangleInterface::ArbitraryHole ArbitraryHole; libMesh::init (argc, argv); { // Flag to turn on/off holes in the mesh const bool with_hole=true; // Libmesh mesh that will eventually be created. Mesh mesh(2); // The points which make up the L-shape: mesh.add_point(Point( 0. , 0.)); mesh.add_point(Point( 0. , -1.)); mesh.add_point(Point(-1. , -1.)); mesh.add_point(Point(-1. , 1.)); mesh.add_point(Point( 1. , 1.)); mesh.add_point(Point( 1. , 0.)); // Declare the TriangleInterface, to be used later TriangleInterface t(mesh); // Customize the variables for the triangulation t.desired_area() = .01; t.triangulation_type() = TriangleInterface::PSLG; // Define holes PolygonHole hole_1(Point(-0.5, 0.5), // center 0.25, // radius 50); // n. points PolygonHole hole_2(Point(0.5, 0.5), // center 0.1, // radius 3); // n. points // The third hole is an ellipse Point ellipse_center(-0.5, -0.5); const unsigned int n_ellipse_points=100; std::vector ellipse_points(n_ellipse_points); const Real dtheta = 2*libMesh::pi / static_cast(n_ellipse_points), a = .1, b = .2; for (unsigned int i=0; i holes; holes.push_back(&hole_1); holes.push_back(&hole_2); holes.push_back(&hole_3); if (with_hole) { // Attach the list of holes to the triangulator object t.attach_hole_list(&holes); } else { // Add extra points (for more randomness) t.insert_extra_points() = true; } // Triangulate! t.triangulate(); // Print result as GMV if (with_hole) mesh.write("delaunay_l_shaped_hole.gmv"); else mesh.write("delaunay_l_shaped.gmv"); } return libMesh::close(); } ```

 [Libmesh-users] Delaunay Triangulation in LibMesh From: John Peterson - 2006-12-15 21:53:49 ```Hi, It's possible to triangulate arbitrary 2D domains with or without holes in LibMesh using the Triangle library. Attached is a sample code for creating a delaunay triangulation of an L-shaped domain. #include "libmesh.h" #include "mesh_triangle_support.h" #include "mesh.h" int main (int argc, char** argv) { // Use typedefs for slightly less typing. typedef TriangleInterface::Hole Hole; typedef TriangleInterface::PolygonHole PolygonHole; typedef TriangleInterface::ArbitraryHole ArbitraryHole; libMesh::init (argc, argv); { // Flag to turn on/off holes in the mesh const bool with_hole=true; // Libmesh mesh that will eventually be created. Mesh mesh(2); // The points which make up the L-shape: mesh.add_point(Point( 0. , 0.)); mesh.add_point(Point( 0. , -1.)); mesh.add_point(Point(-1. , -1.)); mesh.add_point(Point(-1. , 1.)); mesh.add_point(Point( 1. , 1.)); mesh.add_point(Point( 1. , 0.)); // Declare the TriangleInterface, to be used later TriangleInterface t(mesh); // Customize the variables for the triangulation t.desired_area() = .01; t.triangulation_type() = TriangleInterface::PSLG; // Define holes PolygonHole hole_1(Point(-0.5, 0.5), // center 0.25, // radius 50); // n. points PolygonHole hole_2(Point(0.5, 0.5), // center 0.1, // radius 3); // n. points // The third hole is an ellipse Point ellipse_center(-0.5, -0.5); const unsigned int n_ellipse_points=100; std::vector ellipse_points(n_ellipse_points); const Real dtheta = 2*libMesh::pi / static_cast(n_ellipse_points), a = .1, b = .2; for (unsigned int i=0; i holes; holes.push_back(&hole_1); holes.push_back(&hole_2); holes.push_back(&hole_3); if (with_hole) { // Attach the list of holes to the triangulator object t.attach_hole_list(&holes); } else { // Add extra points (for more randomness) t.insert_extra_points() = true; } // Triangulate! t.triangulate(); // Print result as GMV if (with_hole) mesh.write("delaunay_l_shaped_hole.gmv"); else mesh.write("delaunay_l_shaped.gmv"); } return libMesh::close(); } ```