1
$\begingroup$

there is a specific shape (like triangle) area, i am trying to develop an program to draw a successive polyline inside the triangle to fill the triangle, one line 3 layers

ing

this post demonstrates some algorithms to solve this category of problems.

none of them is suitable for this task, any ideas?

$\endgroup$
3
  • $\begingroup$ Why is this post tagged [machine-learning] and [deep-learning]? The problem can be solved using just [algorithms]. $\endgroup$ – Jasper May 24 '19 at 20:02
  • $\begingroup$ CNC milling machines are programmed to execute solutions to this exact problem, but I do not know whether the machinist has to manually enter code to do the "hogging out", or if any of the programming languages have "meta" instructions to generate the needed low-level instructions. $\endgroup$ – Jasper May 24 '19 at 20:06
  • $\begingroup$ 3-D printing software does have instructions to compile a 3-D shape file down to a series of low-level instructions to fill this kind of shape. Typically, the instructions generate parallel raster scan-lines, rather than modified triangles. $\endgroup$ – Jasper May 24 '19 at 20:09
3
$\begingroup$

Would not it be easier to simply apply geometric computation to your triangle to get smaller triangles whose vertices can be used for the polyline.?

With Wolfram Language

You have a triangle.

shp = Triangle[];
Graphics[{LightGray, shp}]

Mathematica graphics

A ScalingTransform about the RegionCentroid can be performed with TransformedRegion to get smaller inner triangles. Below, shp is scaled by factors 0.8, 0.6, and 0.4 for the inner triangles.

scaledShps =
  TransformedRegion[shp,
     ScalingTransform[{#, #},
      RegionCentroid@shp]] & /@ Range[.8, .4, -.2];
SeedRandom[456]
Graphics[{LightGray, shp, Riffle[Hue /@ RandomReal[1, Length@scaledShps], scaledShps]}]

Mathematica graphics

Each of scaledShps has the vertices as the first argument. Map (/@) First to collect these and Flatten them into a single Line.

Graphics[{
  LightGray, shp,
  Orange, Thick, Line@Flatten[First /@ scaledShps, 1]
  }]

Mathematica graphics

Get more layers by increasing the number of scaling factors. For example, from .95 to .05 in steps of -.05

scaledShps =
  TransformedRegion[shp,
     ScalingTransform[{#, #},
      RegionCentroid@shp]] & /@ Range[.95, .05, -.05];
Graphics[{
  LightGray, shp,
  Orange, Thick, Line@Flatten[First /@ scaledShps, 1]
  }]

Mathematica graphics

Wolfram recently released a free Wolfram Engine that can be called from many languages (Python, C, ...) so you can use the above code directly in your project.

Hope this helps.

$\endgroup$
1
  • $\begingroup$ This algorithm is best-suited to convex shapes, such as triangles. If the shape is concave or contains holes, the shrunken shapes may cover areas that were not in the original shape. $\endgroup$ – Jasper May 24 '19 at 20:00

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.