[Numpy-discussion] Creating parallel curves

Andrea Gavana andrea.gavana at gmail.com
Sun Feb 12 06:47:24 EST 2012


HI Chris and All,

On 10 February 2012 17:53, Chris Barker wrote:
> Andrea,
>
>> Basically I have a set of x, y data (around 1,000 elements each) and I
>> want to create 2 parallel "curves" (offset curves) to the original
>> one; "parallel" means curves which are displaced from the base curve
>> by a constant offset, either positive or negative, in the direction of
>> the curve's normal. Something like this:
>>
>> http://pyx.sourceforge.net/examples/drawing2/parallel.html
>
> THis is called "buffering" in GIS parlance -- there are functions
> available to do it in GIS an computational geometry libraries: you
> might look in the shapely package:
>
> https://github.com/sgillies/shapely

Thanks, I hoped this one would prove itself useful, but unfortunately
to me it looks like one of the most impenetrable Python code I have
ever seen. Or maybe my Python is just too weak. The end result is the
same.

I have surfed quite a lot and found many reference to Bezier curves,
with a lot of mathematical acrobatics but little of practical value
(i.e., code :-) ). In the end I stumbled upon a nice function in the
matplotlib library (obviously) which can give me the normal line to
every point in the curve, and I almost got there.

I still have 2 problems (attached sample), picture at
http://img689.imageshack.us/img689/7246/exampleplot.png

1) If you run the attached sample, you'll see a plot of a cubic
polynomial with two "almost" parallel lines to it on the first
subplot. I say "almost" because at the inflection points of the cubic
something funny happens (see suplot number 2);

2) You can see in subplot 3 that the 3 lines are nicely shown as
"almost" parallel (except the problem at point 1), as the X and Y axes
have the same scale. Unfortunately I can't keep the same scales in my
real plot and I can't use axis=square in matplotlib either. How do I
"normalize" the get_normal_points method to get the same visual
appearance of parallelism on X and Y having different X and Y scales
(i.e., the same X and Y scales as in subplot 1)?

>> But by plotting these thing out with matplotlib it seems to me they
>> don't really look very parallel nor very constant-distance.
>
> as we say on the wxPython list -- post a fully functional example, so
> we can check it out.

Attached as promised.

Thank you in advance for any suggestion.

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.alice.it/infinity77/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sample_buffer.py
Type: application/octet-stream
Size: 2250 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20120212/aa14fa33/attachment.obj>


More information about the NumPy-Discussion mailing list