[Numpy-discussion] Fwd: Re: Creating parallel curves
Mon Feb 13 16:32:28 CST 2012
---------- Forwarded message ----------
From: "Andrea Gavana" <email@example.com>
Date: Feb 13, 2012 11:31 PM
Subject: Re: [Numpy-discussion] Creating parallel curves
To: "Jonathan Hilmer" <firstname.lastname@example.org>
Thank you Jonathan for this, it's exactly what I was looking for. I' ll try
it tomorrow on the 768 well trajectories I have and I'll let you know if I
stumble upon any issue.
If someone could shed some light on my problem number 2 (how to adjust the
scaling/distance) so that the curves look parallel on a matplotlib graph
even though the axes scales are different, I'd be more than grateful.
Thank you in advance.
On Feb 13, 2012 4:32 AM, "Jonathan Hilmer" <email@example.com> wrote:
> This is playing some tricks with 2D array expansion to make a tradeoff
> in memory for speed. Given two sets of matching vectors (one
> reference, given first, and a newly-expanded one, given second), it
> removes all points from the expanded vectors that aren't needed to
> describe the new contour.
> def filter_expansion(x, y, x_expan, y_expan, distance_target, tol=1e-6):
> target_xx, expansion_xx = scipy.meshgrid(x, x_expan)
> target_yy, expansion_yy = scipy.meshgrid(y, y_expan)
> distance = scipy.sqrt((expansion_yy - target_yy)**2 + (expansion_xx
> valid = distance.min(axis=1) > distance_target*(1.-tol)
> return x_expan.compress(valid), y_expan.compress(valid)
> On Sun, Feb 12, 2012 at 2:31 PM, Robert Kern <firstname.lastname@example.org>
> > On Sun, Feb 12, 2012 at 20:26, Andrea Gavana <email@example.com>
> >> 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
> > reference curve).
> > 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.
> > --
> > Robert Kern
> > "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
> > _______________________________________________
> > NumPy-Discussion mailing list
> > NumPy-Discussion@scipy.org
> > http://mail.scipy.org/mailman/listinfo/numpy-discussion
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the NumPy-Discussion