# Creating a mesh around an 1-D line to form a 2-D object

Given the following code, how can I perform a mesh generation around the line, to make a 2D form in GMSH API? Extrude or Mirror functions? I want to add a mesh around the line, for example, 1cm to left and 1cm to right.

#include <gmsh.h>

int main(int argc, char **argv)
{

gmsh::option::setNumber("General.Terminal", 1);

double lc = 1e-2;

gmsh::model::geo::synchronize();

gmsh::model::mesh::generate(2);

gmsh::write("t1.msh");

gmsh::finalize();
return 0;
}


You have several options.

Option A. Go for the gmsh::model::geo::extrude

GMSH_API void extrude(const gmsh::vectorpair & dimTags,
const double dx,
const double dy,
const double dz,
gmsh::vectorpair & outDimTags,
const std::vector<int> & numElements = std::vector<int>(),
const std::vector<double> & heights = std::vector<double>(),
const bool recombine = false);


therefore, in your case, it is much easier if you are drawing not a central line of the planned surface, but a left/right border.

std::vector<std::pair<int, int>> line; // this will store a pair {dimension, line_id}
line.first = 1; // line is a 1-D entity
line.second = 1; // and as per your code the line to extrude has ID1
std::vector<std::pair<int, int>> surface; //this will store the result of the extrusion {dimension, surface_id}
gmsh::model::geo::extrude(line, 0, 0.02, 0, surface);


The code above assumes that your line with ID 1 is a border, not a center line going along the X-axis, and you intend to have a width along the Y-axis.

The second GMSH tutorial (available in GEO and C++ API versions) is helpful here.

Option B. Draw the surface yourself

Sometimes, it is just easier to draw the surface yourself without using any extrusions if it is simple enough. I think the code for your case is relatively straightforward.

Useful, since Rectangles are available in GMSH with OpenCASCADE kernel.