jbuckmccready / CavalierContours

2D polyline library for offsetting, combining, etc.
MIT License
406 stars 78 forks source link

How to make a contour with sharp corners instead of arcs? #44

Open lenochod opened 3 years ago

lenochod commented 3 years ago

Hello,

thanks for this highly useful library. Having used it to generate contours for a while to great satisfaction, we found that we need to avoid the rounded corners of contours in some special applications and need sharp angles instead. We are using the cavc::parallelOffset() function to generate contours.

Could you please advise us on where to start modifying the code? I started with case LineSeg2LineSeg2IntrType::False inside lineToLineJoin() which helped me a lot but I'm not sure if this is the right place and may be there are other places to check as well.

Thanks

capture_20210901_111103_001

jbuckmccready commented 3 years ago

Yes that is the case that needs to handled differently for what you want. I don't think anything else needs to change but I haven't given it much thought if that causes problems in other parts of the algorithm, let me know if you get it working. The other case would be when a line is joined to an arc or an arc is joined to a line it currently generates an arc rather than extending the tangent lines out.

timoria21 commented 1 year ago

Hello lenochod,

Did you succeed with the approach you suggested? Did you encounter some issues? We now need to do the same thing and it would be nice if you can share some code.

Thank you.

lenochod commented 1 year ago

Hi timoria21,

the business need for it ceased on our side so we did not continue. I don't have code to share and I don't remember much of the details after almost 2 years.

Best regards,

lenochod

timoria21 commented 1 year ago

Thanks lenochod,

I was able to implement a two-lines connector to cover this case.

Thanks again for answering.

Anruin commented 3 months ago

image

We can calculate the direction of the segment 1 using its v2 and v1 difference, then use the line segment intersection parameter t0 to extend the s1.v1 position in the direction of the segment. Don't normalize it as we will lose length and distance will be applied incorrectly.