Skip to main content
Solved

How to fill a polygon with lines

  • November 12, 2022
  • 2 replies
  • 67 views

I have a 2d polygon and I wanna fill it with as many parallel lines as possible given the distance between the lines and the angle.

 

I have some problems to create the lines I need.

 

In the image ignore the points.

Input:

Input+ the angle (i.e. 80°)

Result (ignore points)

results

Best answer by caracadrian

You need to create the line and iterate through an Offsetter until you fill your polygon.

I created a Custom Transformer that generates 10 lines for a polygon. You can increase that or make it dependent on the polygon dimensions.

Fill polygon with linesI use a BoundingBoxReplacer to get the 2D Oriented Bounding Box and put the Length, Wide, and Angle in attributes, Replace the BBOX with it's centerline via CenterlineReplacer, extent it via LineExtender with health it's length (Length/2 attribute from BoundingBoxReplacer). Then iterate through two Offsetters set to Polar Coordinates, one with Width/10 and Angle+90 and the other with Width/10 and Angle-90. Stop the iteration via Tester when your conditions are met.

Fill polygon with lines InspectorEventually buffer the original polygon with some value and clip the output with it.

I attached a sample workspace to get you started.

View original
Did this help you find an answer to your question?

2 replies

caracadrian
Contributor
Forum|alt.badge.img+23
  • Contributor
  • Best Answer
  • November 14, 2022

You need to create the line and iterate through an Offsetter until you fill your polygon.

I created a Custom Transformer that generates 10 lines for a polygon. You can increase that or make it dependent on the polygon dimensions.

Fill polygon with linesI use a BoundingBoxReplacer to get the 2D Oriented Bounding Box and put the Length, Wide, and Angle in attributes, Replace the BBOX with it's centerline via CenterlineReplacer, extent it via LineExtender with health it's length (Length/2 attribute from BoundingBoxReplacer). Then iterate through two Offsetters set to Polar Coordinates, one with Width/10 and Angle+90 and the other with Width/10 and Angle-90. Stop the iteration via Tester when your conditions are met.

Fill polygon with lines InspectorEventually buffer the original polygon with some value and clip the output with it.

I attached a sample workspace to get you started.


  • Author
  • November 15, 2022

Majestic Solution.

I need to study loop so hard.

 

Thank you.

 


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings