Hello! I met problems when I use clipper. I want to offset the polylines inwards at a distance of d and offset the polylines generated at a distance of 0.5 d again.
Based on the fact that clipper would generate contour and holes at the same time, the final results look like the figure below.There are too many incorrect holes which should be replaced by a single polyline. What should I do?
I use C# to offset each polyline instead of offseting all the polylines at the same time. Inefficient but work at least. I am trying to find the way to generate toolpath for 3d concrete printing, any suggestions and discussions would be appreciated.
Hello
Many things are needed. You must provide all the polylines which are ONE border and THE holes. Then you have to take all clippers results and look if they are inside the shape. … some complementary tools must be done in order to do the job.
See these discussions
Well … this is not the way to cut any mustard (i.e. offset inwards/outwards any shape closed and planar Polyline). Study the help “items” (blue, white), understand what they serve/do and try to write a C# that follows this kind of thinking.
Mastermind a 100% correct way to get a bisector Vector (say: offVector) inwards or outwards (on a per 3 poly pts (prev - current, next - current) basis) depending on the mode on duty.
Get the corresponding offset pt (i.e. current pt + offVector) and sample it into a List (say: polyOffPts).
For each index i in polyPts get:
p0 = polyPts[i]; p1 = polyPts[(i+1) % polyPts.Count],
p0a = polyOffPts[i]; p1a = polyOffPts[(i+1) % polyPts.Count].
If (p0 - p1) is parallel to (p0a - p1a) get a Polyline from the 4 pts and sample it (as Curve) to some List (say: workCrvs).
If (p0 - p1) is anti-parallel to (p0a - p1a) get the ccxPt (in the X from Lines (p0, p0a) and (p1, p1a)), get a Polyline from p0, p1, ccx Pt and sample it (as Curve) to workCrvs.
Now: you are that close (or that far) from the Holly Grail … you’ll need just 2 lines of code (in fact: several for a pro level speedy solution … but let’s stick to code basics) more to solve the inwards/outwards puzzle.
BTW: for eveything you do …some correct result means nothing (even kids can do it - if they try hard). All what matters is speed. For instance this (Poly Contains Pt) is seriously faster than the Curve Contains Pt RC Method:
@PeterFotiadis, while getting the direction of this offset vector is trivial, how do you determine its length? I can think of moving the original line segment by its normal vector and finding intersection points with the offset vectors but that seems like a heavy way to - as you say - cut the mustard.
Of course you can get the Vector vPrev, vNext half angle (in the correct way I do hope - that’s the big thing) and then (after Unitize()) … Point3d offPt = p0 + bisector * D / Math.Sin(angle).
Warning: this offset puzzle if full of mental traps.
One out of many: Let’s say that someone has a “bright” idea: IF the offsetPoly has the same orientation with the Polyline and if this (and that) happens (see code below) … can we skip the “expensive” proper way to solve it and speed things?