CreativeInquiry / PEmbroider

Embroidery Library for Processing
Other
442 stars 28 forks source link

Staggering stitches in thick Parallel strokes #27

Closed golanlevin closed 4 years ago

golanlevin commented 4 years ago

@LingDong- , per Tatyana's suggestion, could you give some thought to how we could implement offsets for staggering stitches in thick strokes that are rendered in PARALLEL mode? See her illustration below.

84611077-bd210880-ae8a-11ea-8cde-b68ce74dfe7d

LingDong- commented 4 years ago

Hi @golanlevin

🤔. One way I can think of is to use take the midpoint of each segment of every other polyline and connect them. The downside is that the strokes will no longer be concentric and will have intersections and there will be problems at sharper corners. But judging from the "fluffy" look in the photo, seems like people won't be able to tell :P

IMG_0922

I think main reason the stitches in the photograph look very aligned is that the stitch length is long compared to the length of the segment in the polyline. If we draw a larger shape with smaller stitch length, only the ones at end points of segments will be aligned, and all the other points that come from resampling will be randomized and not aligned.

From issue #17, looks like we'll drastically increase the size of everything? Perhaps by increasing the ratio of unit per pixel? Wondering if that would solve this issue automatically?

golanlevin commented 4 years ago

Hi @LingDong- , I'd rather use a proper geometric solution than rely on getting lucky with scaling effects. Why can't we just slide the "start point" of even-numbered contours forward by half a stitch length, and then resample the contour from there? (While possibly retaining points of very high curvature.)

LingDong- commented 4 years ago

Hi @golanlevin , that's what I was trying to describe in the first paragraph (and the illustration). However I was saying half segment length instead of half stitch length to maximize the offset (like we did with the parallel stitch resampling)


It's not "getting lucky with scaling" though. It's simply the resolution of the polyline is higher than that of the stitches, which will be definitely solved by increasing the scale.

IMG_0923

LingDong- commented 4 years ago
Screen Shot 2020-06-15 at 7 23 39 PM

corner-aware half-segment-length staggering added in a2df2769d343ec8299a7681a52c3b662dd0d4790

golanlevin commented 4 years ago

Magnificent — thank you, Lingdong. @tatyanade , please test?

tatyanade commented 4 years ago

Hi @LingDong- I'm confused as to how to call this, I see the edits to the strokePolyTangentRaster but am not sure how to call it so it uses the staggering

LingDong- commented 4 years ago

Hi @tatyanade , there's no need to call it, theoretically it is already turned on for all strokes in TANGENT mode (not for CONCENTRIC fill yet, because the implementation is a bit different)

See the heart in PEmbroider_bitmap_image_1 example

tatyanade commented 4 years ago

Tested with spacings of 1,2,3,4,5

tangent_spacing_1_bmpheartimage

PEmbroider_bitmap_heart_tangent_spacing2 2020-06-16_16h57_07

Had some weird issues with spacing of 3; you can see in the png render there are a lot of stitches in the center of the crack, which piles up in real life.

PEmbroider_bitmap_heart_tangent_spacing3 image image

PEmbroider_bitmap_heart_tangent_spacing4 image

tangent_spacing_5_bmpheart 2020-06-16_16h58_57

Did the same test with a different heart & it gets a bit crowded in the center of the crack near sharper corners but not as much as spacing3 on the original image does image difheart image

golanlevin commented 4 years ago

@tatyanade , those long straight stitches on the left side of the heart — I assume you're aware that you can adjust those with the setStitch() function, any reason you made them so long?

In general, do you think the staggered stitches for TANGENT strokes are working well?

The pile-up on my broken heart could reasonably be considered a fault of my design — or do you disagree with that?

LingDong- commented 4 years ago

@tatyanade @golanlevin oops, the really long stitches is likely due to my enabling of toggleResample(false) in PEmbroider_bitmap_image_1 to test/showcase the new staggering algorithm

LingDong- commented 4 years ago

Hi @golanlevin

Now concentric fill is also given the staggering. I noticed your muybridge demo's concentric fill looks very aligned so I added that :)

There's now an option called CONCENTRIC_ANTIALIGN. When set to 0, no staggering will be done. When set to a positive float, it will be treated as angle in radians (θ in image below), turnings that are steeper than this will be kept. Default is 0.6 ≈ 35°

            C
           /
          /
         / θ
A-------B. . . . . . . . . . . . . . . . 
tatyanade commented 4 years ago

Hi @LingDong- Staggering gets eliminated at some point when two shapes are culled - visable in lower part of circles on the left - both are parallel hatch with hatch spacing of 2 and second one is sapcing of 4 2020-06-23_00h55_19 2020-06-23_00h55_00