1

My question is hard for me to explain, so have mercy. It's about creating an AutoCAD .pat hatch pattern from a line segment within a rectangle with the coordinates [0,0] and[1,1], that sould form a seamless hatch pattern. In AutoCAD, a line segment will continue with a spaceing in the line direction and then it repeats.

For the AutoCAD pattern, I need the "shift" and "offet" values. Here's a LISP code that does what I want, but it's way over my head: https://autocadtips1.com/2011/10/11/autolisp-make-and-save-custom-hatch-pattern/

Assume a grid of N x M fields (yellow in the picture). I have a pattern that describes a shape in field [0,0]. That pattern (red square) repeats at each field [N,M]. Now, in order to also fill the fields from [0,0] to [N,M], I have to repeat the pattern, by adding a copy at a given position [U,V]. This pattern, again is moved by [U,V] and so on. Now, Uand V should be calculated, so the area[0,0] to [N,M] is 1) completely filled and 2) no duplicates are drawn.

Grid image

Here's some examples that I found out by trial & error:

N,M =  4,1; U,V =  1,0
N,M =  9,4; U,V =  2,1
N,M = 18,5; U,V = 11,3
KungPhoo
  • 516
  • 4
  • 18

1 Answers1

0

so you have all as bitmaps no vectors (after rasterisaition) in such case you can exploit modular arithmetics ...

So you want to fill any point x,y as a copy from some hatch image of size xs,ys so you just compute the coordinates x',y' in that hatch image and copy pixel:

x' = (x-x0)%xs
y' = (y-y0)%ys

Where x0,y0 is some start point of your target image (for example starting vertex of the filled polygon) or can be also ignored (use x0=0,y0=0) depending on what you want to achieve (if the pattern moves with polygon or not).

In case the hatch image resolution is power of 2 then you can use bit masking instead:

1<<shx = xs
1<<shy = ys

x' = (x-x0)&(xs-1)
y' = (y-y0)&(ys-1)

for more info see this:

I used 17 shading patterns for filled polygons its the same as your hatching

Spektre
  • 49,595
  • 11
  • 110
  • 380