[Numpy-discussion] Creating parallel curves
Sun Feb 12 15:31:33 CST 2012
On Sun, Feb 12, 2012 at 20:26, Andrea Gavana <firstname.lastname@example.org> wrote:
> I know, my definition of "parallel" was probably not orthodox enough.
> What I am looking for is to generate 2 curves that look "graphically
> parallel enough" to the original one, and not "parallel" in the true
> mathematical sense.
There is a rigorous way to define the curve that you are looking for,
and fortunately it gives some hints for implementation. For each point
(x,y) in space, associate with it the nearest distance D from that
point to the reference curve. The "parallel" curves are just two sides
of the level set where D(x,y) is equal to the specified distance
(possibly removing the circular caps that surround the ends of the
If performance is not a constraint, then you could just evaluate that
D(x,y) function on a fine-enough grid and do marching squares to find
the level set. matplotlib's contour plotting routines can help here.
There is a hint in the PyX page that you linked to that you should
consider. Angles in the reference curve become circular arcs in the
"parallel" curves. So if your reference curve is just a bunch of line
segments, then what you can do is take each line segment, and make
parallel copies the same length to either side. Now you just need to
connect up these parallel segments with each other. You do this by
using circular arcs centered on the vertices of the reference curve.
Do this on both sides. On the "outer" side, the arcs will go "forward"
while on the "inner" side, the arcs will go "backwards" just like the
cusps that you saw in your attempt. Now let's take care of that. You
will have two self-intersecting curves consisting of alternating line
segments and circular arcs. Parts of these curves will be too close to
the reference curve. You will have to go through these curves to find
the locations of self-intersection and remove the parts of the
segments and arcs that are too close to the reference curve. This is
tricky to do, but the formulae for segment-segment, segment-arc, and
arc-arc intersection can be found online.
"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
-- Umberto Eco
More information about the NumPy-Discussion