My problem statement:
I have a polyline, and I want to do variable width offset along the points, in just one direction. How can I do it? For the polyline, I just need to support straight lines, no need to support curves or arcs.
The polyline can be closed or open, and the offset is in only one direction-- for the sake of argument, let's just say that it's in the Left Hand Side direction.
The above image almost encapsulates what I want to do; the only thing is, it is uniform offset throughout the polylines, whereby I want variable offset.
The problem is a lot more trickier than it first seems. There are a few libraries that not quite do. Let's go through them one by one.
Clipper
Clipper can handle polygon buffer, which means that the offsetting lines are created in both directions and finally a polygon is form around the line. So it's not suiting my needs. Furthermore it doesn't handle variable buffering.
There were some discussions on this on the forum involving the Clippers developers, but unfortunately nothing came out.
NetTopologySuite
NetTopologySuite has a VariableBuffer class, which can handle variable offset. But unfortunately NetTopologySuite can only handle polygon buffering ( whereby you convert a line into a polygon enclousing the line), and not polyline offsetting ( where by the polyline is offset in a single direction).
Also, it seems that with the above method NetTopologySuite will "blow up" the polygon in both direction, and one needs to set the BufferParameters.IsSingleSided=true in order to have a single sided polygon offset, but it's quite unclear how to use this in conjunction with VariableBuffer.
Cavalier contours
Cavalier countours, unlike the majority of the library out there, can do polyline offsetting ( which is what I want) in one direction only so that no polygon is formed. This is what I want, but unfortunately, it can't do variable width offsetting.
What about adapting current libraries to suit my needs?
There seems to be no trivial way of doing just this. Any ideas how this can be done?
Any solutions built on top of libraries in C#, C++ or C are welcomed.
Indeed, the problem is more complicated with a variable offset. In the case with a single offset, the distance of a point p to the polyline is defined as the distance of the closest point of the polyline to p (see for example pointValidForOffset in https://github.com/jbuckmccready/CavalierContours/blob/master/include/cavc/polylineoffset.hpp )
The generalization to variable offset is not obvious.
A simple solution, in case of a simple polyline (no curves) is : Let F be the initial polyline.
To draw G, the polyline far from the variable offset : This code works if you put the code in http://paperjs.org/ "Sketch" Here is the result :