CreativeInquiry / PEmbroider

Embroidery Library for Processing
Other
442 stars 28 forks source link

hatchMode(AUTO) #48

Closed golanlevin closed 4 years ago

golanlevin commented 4 years ago

The orientation of parallel or satin strokes should be perpendicular to major axis of an arbitrary polygon, using hatchMode(AUTO).

LingDong- commented 4 years ago

Added: 30b8a65ea232aace30edcd0945e17b552de2bb53

hatchAngle(AUTO);
hatchAngleDeg(AUTO);

@golanlevin I'm using your rotated bounding box Processing code. However it seems that the code produces all NaN's when the input shape is symetric. For example, a simple rect centered in the middle causes matrix2x2[0][1] to be zero, and thus triggering zero division in calcEigenvector making everybody NaN's. My current hack is to add a tiny random offset to every vertex before running the algorithm, which seems to be working fine.

golanlevin commented 4 years ago

My current hack is to add a tiny random offset to every vertex

Yikes 😬 Well, if it works.... Even so, maybe put in a check for NaNs?

golanlevin commented 4 years ago

Hi @LingDong- , currently, the AUTO orientation is incorrect — it should be perpendicular to the major axis, not parallel. Here is a test shape:

Screen Shot 2020-06-26 at 5 52 14 PM

E.beginShape(); E.vertex(100, 100); E.vertex(160, 110); E.vertex(250, 170); E.vertex(300, 250); E.vertex(330, 290); E.vertex(280, 290); E.vertex(150, 180); E.endShape(CLOSE);

LingDong- commented 4 years ago

@golanlevin

hmm that could be a problem with the orientation calculation code you gave me.

My test:

E.ellipse(100,100,mouseX-100,mouseY-100);

which produces the correct result.

Screen Shot 2020-06-26 at 6 20 40 PM

Looks like the number returned is either correct, or at 90° with the correct answer. Wonder what hack I should apply.

golanlevin commented 4 years ago

Ugly hack: compute the orientation; fit the oriented bounding box; take the max of width & height ?

LingDong- commented 4 years ago
Screen Shot 2020-06-29 at 5 30 28 PM

@golanlevin you're right, this is fixed by fixing #74 :)

Sorry about that. Glad that I haven't wasted time on making a hack

I also added a hatchAngle(AUTO) example: 37017ec10c149c83506b1cd9a8c67d51e9384fd5

golanlevin commented 4 years ago

Awesome.