[Numpy-discussion] Creating parallel curves

Andrea Gavana andrea.gavana@gmail....
Sun Feb 12 14:21:52 CST 2012


On 12 February 2012 20:53, Jonathan Hilmer wrote:
> Andrea,
> Here is how to do it with splines.  I would be more standard to return
> an array of normals, rather than two arrays of x and y components, but
> it actually requires less housekeeping this way.  As an aside, I would
> prefer to work with rotations via matrices, but it looks like there's
> no support for that built in to Numpy or Scipy?
>        def normal_vectors(x, y, scalar=1.0):
>                tck = scipy.interpolate.splrep(x, y)
>                y_deriv = scipy.interpolate.splev(x, tck, der=1)
>                normals_rad = np.arctan(y_deriv)+np.pi/2.
>                return np.cos(normals_rad)*scalar, np.sin(normals_rad)*scalar

Thank you for this, I'll give it a go in a few minutes (hopefully I
will also be able to correctly understand what you did). One thing
though, at first glance, it appears to me that your approach is very
similar to mine (meaning it will give "parallel" curves that cross
themselves as in the example I posted). But maybe I am wrong, my
apologies if I missed something.

Thank you so much for your answer.


More information about the NumPy-Discussion mailing list