Understanding hatches algorithm

Understanding hatches algorithm

NikhilPundir
Enthusiast Enthusiast
1,364 Views
4 Replies
Message 1 of 5

Understanding hatches algorithm

NikhilPundir
Enthusiast
Enthusiast

I am implementing a dxf viewer for hatches and to do that I am trying to understand the algorithm used by AutoCAD for island and boundary detection. I am able to load the data correctly from dxf code.

My research showed me that Autocad uses ray casting, island detection and flood fill method to create hatch boundaries.

 

There are 3 different type of hatches

 

1. Simple hatches which only contain single close boundary. These are simple to implement but becomes complex if the boundary self intersect

 

2. Hatches formed by intersection of multiple entities and use a seed point & flood fill method to find the close boundary.

 

3. Open hatches created by selecting entities instead of seed point. I am guessing AutoCad uses flood fill for this too.

 

Is this info correct? Can someone provide more information and specific algorithm names that is used by AutoCad ?

It will be really helpful for me. Thanks!!

0 Likes
Accepted solutions (1)
1,365 Views
4 Replies
Replies (4)
Message 2 of 5

TheCADnoob
Mentor
Mentor

Are you asking if anyone here has access to Autodesk intellectual property and is willing to give it away?

 

Instead of reinventing the wheel, have you thought about using the platform services APIs?

https://aps.autodesk.com/

 

CADnoob

EESignature

0 Likes
Message 3 of 5

Simon_Weel
Advisor
Advisor
0 Likes
Message 4 of 5

leeminardi
Mentor
Mentor
Accepted solution

There are two stages in the algorithm for generating a cross hatch pattern for a shape. The first stage is to determine closed geometry with no dangling edges. The geometry may have internal islands. The second stage is to consider a ray passing through the geometry in the direction of a hatch line and determining its intersections. For geometry without dangling edges, a hatch line is drawn from the first to the second intersection, and if present, from the 3rd to the 4th intersection, and the 5th to the 6th, etc. If there are an odd number of intersections for a ray, the hatch line is drawn from the first intersection to the last.


Creating a hatch when using the select object option bypasses the first stage and can handle open geometry as well as geometry with dangling edges but often with undesirable results as seen below.

leeminardi_1-1710439003291.png


The internal point option for the hatch command calculates closed boundaries for the overall outline of the shape as well as any islands. The result is the same you would get from using the boundary command. Invalid hatching does not occur for trimmed boundaries. The boundary command projects the specified internal point onto a line that can be reached without crossing another line. From there, the routine walks around the lines from intersection to intersection. Next step is to determine if islands are present and then calculate the boundaries for them. The hatch pattern offset is determined by the location of the active UCS.

lee.minardi
0 Likes
Message 5 of 5

NikhilPundir
Enthusiast
Enthusiast

Thanks a lot. Your answer filled the knowledge gaps in my understanding of hatches.

0 Likes