Path: news.mathworks.com!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!news2.google.com!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post01.iad.highwinds-media.com!newsfe22.iad.POSTED!7564ea0f!not-for-mail
From: Doug Schwarz <see@sig.for.address.edu>
Newsgroups: comp.soft-sys.matlab
Subject: Re: equally spaced data points over a curve
References: <gf9fl8$4kh$1@fred.mathworks.com> <see-AE3628.11371810112008@news.frontiernet.net> <gf9sur$r89$1@fred.mathworks.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
User-Agent: MT-NewsWatcher/3.5.2 (Intel Mac OS X)
Message-ID: <see-1B4CC7.13383010112008@news.frontiernet.net>
Lines: 94
X-Complaints-To: abuse-news@frontiernet.net
NNTP-Posting-Date: Mon, 10 Nov 2008 18:38:27 UTC
Organization: Frontier
Date: Mon, 10 Nov 2008 13:38:30 -0500
Xref: news.mathworks.com comp.soft-sys.matlab:500040


[top posting repaired]

In article <gf9sur$r89$1@fred.mathworks.com>,
 "Dave Brackett" <davebrackett@hotmail.com> wrote:

> Doug Schwarz <see@sig.for.address.edu> wrote in message 
> <see-AE3628.11371810112008@news.frontiernet.net>...
> > In article <gf9fl8$4kh$1@fred.mathworks.com>,
> >  "Dave Brackett" <davebrackett@hotmail.com> wrote:
> > 
> > > Hi, 
> > > 
> > > I have plotted a curve which connects up some data points. The curve is 
> > > not a 
> > > straight line.
> > > 
> > > I would like to compute a new set of data points from the plotted curve, 
> > > but 
> > > equally spaced over the length of the curve. The number of points would 
> > > be 
> > > specified which would control the resolution. 
> > > 
> > > Does anyone know how I could do this? If you need any more information 
> > > please 
> > > ask. Thanks.
> > 
> > Here's something I plan on contributing to the FEX when I get a chance 
> > to clean it up and document it.  It's not especially fast, but if you 
> > already have x and y in functional form it could be faster.
> > 
> > 
> > ----------------- linspacearc.m ---------------------------
> > function [x2,y2] = linspacearc(x,y,n)
> > m = length(x);
> > t = linspace(0,1,m);
> > ppx = spline(t,x);
> > ppy = spline(t,y);
> >  
> > dppx = pp_deriv(ppx);
> > dppy = pp_deriv(ppy);
> > integrand = @(tt) sqrt(ppval(dppx,tt).^2 + ppval(dppy,tt).^2);
> > arc_length = quadgk(integrand,0,1);
> > s = linspace(0,arc_length,n);
> >  
> > inv_arc_len = @(arc,est) fzero(@(u)(quadgk(integrand,0,u)) - arc,est);
> >  
> > t2 = zeros(1,n);
> > t2(1) = inv_arc_len(s(1),0);
> > for i = 2:n
> >     t2(i) = inv_arc_len(s(i),t2(i-1));
> > end
> >  
> > x2 = ppval(ppx,t2);
> > y2 = ppval(ppy,t2);
> >  
> >  
> > function dpp = pp_deriv(pp)
> > % pp_deriv: derivative of piecewise polynomial (pp)
> >  
> > dpp = pp;
> > n = pp.order;
> > dpp.coefs = bsxfun(@times,n-1:-1:1,pp.coefs(:,1:n-1));
> > dpp.order = n - 1;
> > -------------------------------------------------------------
> > 
> > 
> > Simply pass in your x and y vectors and the number of desired output 
> > points and get back your new x and y vectors.
>
>
> Thanks for your code Doug, however, it doesn't do what I want. Your code 
> computes points over the curve equally spaced along the x axis. What I want 
> is to compute points over the curve equally spaced along the curve.
> 
> My curve has regions of zero gradient and regions of much steeper gradient. I 
> want the distance between each set of two points to be the same over the 
> length of the curve.
> 
> Do you know how your code could be edited to enable this? Thanks for your 
> help so far.


No, it does exactly what you asked for, but it is possible that your 
specific data tricks it up somehow or makes this not obvious.  In 
particular, it is quite easy to be fooled if you are judging this 
visually and you haven't set the axes to have equal scaling in the X and 
Y directions (use "axis equal").  If you can't seem to get it to work 
please post or send me as small an example as possible and I would be 
glad to take a look at it.

-- 
Doug Schwarz
dmschwarz&ieee,org
Make obvious changes to get real email address.