8
$\begingroup$

I would like to know how to generate a mesh inside an area, and be able to find the original curve outline inside the area from the mesh.

For example: There is a rectangle inside which there is a curve with an implicit expression such as a segmented arc or a spline.

enter image description here

I mean let the red area generate a mesh and keep the shape of the inner curve.

What is the solution?

Thanks

$\endgroup$
2
  • 1
    $\begingroup$ Do you want the mesh elements to follow a curve, or does the curve have a 'thickness' that you want to remove or mesh separately? $\endgroup$
    – user21
    Apr 14 at 8:29
  • $\begingroup$ @user21 In fact, what I want is a curve without thickness $\endgroup$
    – OlW
    Apr 14 at 8:50

3 Answers 3

9
$\begingroup$

Here is one way:

Needs["NDSolve`FEM`"]
pts = {{1, 1}, {2, 3}, {3, -1}, {4, 1}, {5, 0}};
f = BSplineFunction[pts]; bm1 = 
 ToBoundaryMesh[DiscretizeGraphics[ParametricPlot[f[t], {t, 0, 1}]]];
bm2 = ToBoundaryMesh[Rectangle[{0, -1/2}, {6, 2}]];
(* ResourceFunction["FEMAddOnsInstall"][] *)
Needs["FEMAddOns`"]
bm = BoundaryElementMeshJoin[bm1, bm2];
ToElementMesh[bm]["Wireframe"]

enter image description here

Another approach can be seen in the documentation here:

enter image description here

Stealing from @kgl's answer:

img = Import["https://i.stack.imgur.com/Hp0Z3.png"];
bmr = ImageMesh@img;
ToElementMesh[bmr]["Wireframe"]
ToElementMesh[bmr, "RegionHoles" -> None]["Wireframe"]

The point I am trying to make is that you can decide if the inner region is to be excluded or not; in other words if it's a material region of an outside or just a curve the mesh should follow, because you need measurements along that curve.

enter image description here

$\endgroup$
3
  • $\begingroup$ The first answer is very good, but the fly in the ointment is that the mesh around the curve is too dense, the second answer looks a lot more reasonable, but this causes the limit of the generated mesh to become a closed area (whether hollow or non-hollow) $\endgroup$
    – OlW
    Apr 14 at 8:56
  • $\begingroup$ @OIW, unfortunately, I do not understand your comment. Can you reword this? $\endgroup$
    – user21
    Apr 14 at 9:21
  • $\begingroup$ What I mean is that this curve has no thickness, it doesn't look thick in the picture (ie wireless thin) $\endgroup$
    – OlW
    Apr 14 at 10:46
5
$\begingroup$
img = Import["https://i.stack.imgur.com/Hp0Z3.png"];


ImageMesh @ img

enter image description here

DiscretizeRegion @ ImageMesh @ img

enter image description here

ImageMesh @ DeleteBorderComponents[ColorNegate @ Binarize @ img]

enter image description here

DiscretizeRegion[
 ImageMesh @ DeleteBorderComponents[ColorNegate @ Binarize @ img], 
 MaxCellMeasure -> {"Area" -> 10}]

enter image description here

SeedRandom[1];
f = BSplineFunction[RandomReal[1, {15, 2}], SplineClosed -> True];
pp = ParametricPlot[f[u], {u, 0, 1}, Frame -> True, 
  FrameTicks -> False, ImagePadding -> 0, 
  PlotStyle -> Directive[Black, AbsoluteThickness[3]], 
  FrameStyle -> AbsoluteThickness[10], Background -> Red]

enter image description here

ImageMesh @ Image @ pp

enter image description here

DiscretizeRegion @ ImageMesh @ Image @ pp

enter image description here

$\endgroup$
1
  • $\begingroup$ This looks great, but I want the curve to have no thickness, which means a non-closed curve (the pic I uploaded the curve has thickness lol) $\endgroup$
    – OlW
    Apr 14 at 8:52
0
$\begingroup$

Something like e.g.:

pts = {{1, 1}, {2, 3}, {3, -1}, {4, 1}, {5, 0}};
f = BSplineFunction[pts]; Show[
 ParametricPlot[f[t], {t, 0, 1}, PlotTheme -> "Business"], 
 Graphics[{Red, Opacity[0.1], Rectangle[{0, -.2}, {5.5, 2}]}]]

enter image description here

$\endgroup$
1
  • 2
    $\begingroup$ I have some problems with my instructions, the mesh refers to triangular elements such as the mesh generated by the method ToElementMesh. $\endgroup$
    – OlW
    Apr 14 at 7:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.