12
$\begingroup$

How to get roughly evenly distributed mesh points along boundary?

We can see marked by red circles, that some points are too close to each other while others are too apart from each other.

Show[#, Graphics@
    Point@(Join @@ (PolygonCoordinates /@ #["BoundaryPolygons"]))] &@
 BoundaryDiscretizeGraphics[
  Text[Style["b", FontFamily -> "Cambria"]], _Text, 
  MaxCellMeasure -> {"Length" -> 1}]

enter image description here

Another strange thing is that setting MaxCellMeasure -> {"Length" -> 0.1} leaves ranges in the boundary with no point at all.

enter image description here

$\endgroup$

2 Answers 2

13
$\begingroup$

Edit

For the original code,we can subdivide the line to add some points.

polys = #["BoundaryPolygons"] &@
   BoundaryDiscretizeGraphics[
    Text[Style["b", FontFamily -> "Cambria"]], _Text, 
    MaxCellMeasure -> {"Length" -> 1}];
δ = 1/4;
lines = MeshPrimitives[#, 1] & /@ polys;
Flatten[Map[
    Subdivide[Sequence @@ First@#, Ceiling[ArcLength@#/δ]] &, 
    lines, {2}], 1] // Map@Point // Graphics

enter image description here

Clear[fonts, fillcurves];
fonts = 
 ImportString[
  ExportString[Text[Style["qH", FontFamily -> "Cambria"]], 
   "PDF"], {"PDF", "PageGraphics"}, "TextOutlines" -> True];
fillcurves = Cases[fonts, _FilledCurve, -1];
HighlightMesh[BoundaryDiscretizeGraphics[#, MaxCellMeasure -> .1], 
    0] & /@ fillcurves // Show

enter image description here

Clear["Global`*"];
lines = MeshPrimitives[
   BoundaryDiscretizeGraphics[
    ImportString[
      ExportString[Text[Style["b", FontFamily -> "Cambria"]], 
       "PDF"], {"PDF", "PageGraphics"}, "TextOutlines" -> True][[1]], 
    MaxCellMeasure -> .1], 1, "Multicells" -> True];
δ = .5;
MapThread[
  ListLinePlot[#1 /. Line -> Apply@Join, 
    MeshFunctions -> {0 &, "ArcLength"}, Mesh -> {#2}, 
    MeshStyle -> Red, AspectRatio -> Automatic, 
    Axes -> False] &, {lines, 
   Subdivide /@ Floor /@ (ArcLength /@ lines/δ)}] // Show

enter image description here

$\endgroup$
2
  • $\begingroup$ It is better many times... but still there is discrepancy at the same spots... look at small red circles in my OP, there are two pairs of points too close to each other... same spots here at upper left part of b. Why? $\endgroup$ Commented Nov 10, 2023 at 15:09
  • $\begingroup$ And also it is not clear to me why we have to use PDF in the process... and it does not work with all letters, for example letters q or H have some double points in their mesh. $\endgroup$ Commented Nov 10, 2023 at 17:57
5
$\begingroup$

Resample discrete points using LineScaledCoordinate.

Clear["`*"]; Needs["GraphUtilities`"]; num = 80;
reg = BoundaryDiscretizeRegion[
   BoundaryDiscretizeGraphics[
    Text[Style["b", Bold, FontFamily -> "Times"]], _Text, 
    MaxCellMeasure -> {"Length" -> 1}]];
pts1 = Map[Apply[Join], 
   Cases[MeshPrimitives[reg, 1, Multicells -> True], 
    Line[pts_, ___] :> pts, Infinity]];
ptlen = pts1 // Length;
Table[rept[i] = 
   Table[LineScaledCoordinate[pts1[[i]], j], {j, 0, 1, 1./num}], {i, 
   1, ptlen, 1}];
{Graphics[{RandomColor[], Point@#}] & /@ Array[rept, ptlen], 
 Graphics[{RandomColor[], Point /@ Array[rept, ptlen]}]}

b

$\endgroup$
1
  • 2
    $\begingroup$ Interesting (+1). It's funny that though the document claims all the functionality of the GraphUtilities package is built-in now, the page Compatibility/tutorial/GraphUtilities simply ignores this LineScaledCoordinate. $\endgroup$
    – xzczd
    Commented Apr 13 at 4:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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