Message Boards Message Boards

0
|
1324 Views
|
0 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Arbitrary shape to triangles to rectangle packing

Posted 1 year ago

I'm working on a program that takes any arbitrary shape (I'm using clothing patterns) and turns it into a rectangle of the same area by cutting the shapes into triangles with a triangulation mesh then packing them into a rectangle of, ideally, the same area. I've posted on Mathematica.stackexchange and I've seen a post about packing arbitrary shapes, however, I've reached a roadblock in packing the triangles tighter and, preferably, without gaps.

The triangles are made from the following code

Input image:

enter image description here

img = https://i.stack.imgur.com/zM2Hd.png ;
mesh = TriangulateMesh[ImageMesh[ColorNegate[img]], 
MeshQualityGoal -> 0.001,
MaxCellMeasure -> \[Infinity],
MeshCellLabel -> {2 -> "Index"}]

Output image:

enter image description here

meshes = MeshPrimitives[mesh, 2];
triangles = Map[Graphics[#] &, meshes]

n = 20;

BlockRandom[glyphs = RandomChoice[meshes[[1 ;; 20]], n];
 scales = RandomReal[5, n], RandomSeeding -> 1234]
wc = WordCloud[AssociationThread[glyphs, scales], WordSpacings -> 0, 
  WordOrientation -> "Random", RandomSeeding -> 1234]
insetToReg[mr_, c_, p_, s_] := 
 BoundaryMeshRegion[
    TransformedRegion[#, 
     TranslationTransform[c - RegionCentroid[BoundingRegion[#]]]], 
    MeshCellStyle -> {1 -> Black, 2 -> RandomColor[Hue[_]]}] &@
  RegionResize[mr[[1]], s]

enter image description here

POSTED BY: Jonathan Vardy
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract