[Numpy-discussion] Creating parallel curves

Andrea Gavana andrea.gavana@gmail....
Fri Feb 10 10:38:00 CST 2012

Hi All,

    my apologies for my deep ignorance about math stuff; I guess I
should be able to find this out but I keep getting impossible results.

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:


The point in the x variable are monotonically increasing.

For every point in the curve, I also have the angle this point creates
to the vertical (y) direction, so I naively thought of doing this:

    angles = numpy.deg2rad(angles)

    x_low = x - DISTANCE*numpy.cos(angles)
    y_low = y + DISTANCE*numpy.sin(angles)

    x_high = x + DISTANCE*numpy.cos(angles)
    y_high = y - DISTANCE*numpy.sin(angles)

But by plotting these thing out with matplotlib it seems to me they
don't really look very parallel nor very constant-distance. I admit
the matplotlib axis scales can play a significant role here, but I was
wondering if some of you could spot my dumb mistake (and maybe provide
a way to nicely take into account the different scales of the
matplotlib axes so that the curves really look parallel...).

Thank you in advance for any suggestion.


"Imagination Is The Only Weapon In The War Against Reality."

More information about the NumPy-Discussion mailing list