From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Moving a straight line segment along the curve (Animation)
Date: Fri, 1 Apr 2011 21:03:04 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 26
Message-ID: <in5ei8$igt$>
References: <in5ad5$6np$>
Reply-To: <HIDDEN>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: 1301691784 18973 (1 Apr 2011 21:03:04 GMT)
NNTP-Posting-Date: Fri, 1 Apr 2011 21:03:04 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: comp.soft-sys.matlab:719590

"Liana" wrote in message <in5ad5$6np$>...
> Hello,
> I have a curve specified as follows:
> cubic_spline = cscvn(points); % Data interpolation with a cubic spline
> [curve,t]=fnplt(cubic_spline,'-r'); %"Natural" or periodic interpolating cubic spline curve
> path_length = curve_length(curve);
> fnplt(cubic_spline,'-r');
> Now I'd like to make a simple animation. I want a straight line segment to move along the 'curve'. So far I can only move a point. Well, further I will need to rotate the line while moving. However, for the beginning I need just to move it without any rotation. How can I do that?
> for i = 1:path_length
>     xlabel('x');
>     ylabel('y');
>     hold on  
>     plot(curve(1,i),curve(2,i),'o'); 
>     M(:,i) = getframe;
> end
> Thanks a lot for any help!
- - - - - - - - - -
  I presume when you say "rotate the line" you mean that you want the line segment to be tangent to the interpolated curve.  You could accomplish that by using the 'ppform', which is the output of 'cscvn', to directly calculate the derivative of the cubic polynomial within whatever cubic section of the spline-fit the point of tangency is located.  That establishes the slope desired for the line segment.  In your animation this would of course have to be repeated for each point of tangency along the curve.

  Yesterday in a different thread you inquired about curvature in connection with the use of 'cscvn'.  You can also use its 'ppform' output to directly calculate the curvature of cubic sections at any desired points within them.  The formula is well known in calculus: curvature is equal to the second derivative divided by the three-halves power of the quantity: one plus the square of the first derivative.  Cubic polynomials have very well-defined second, as well as first, derivatives.

Roger Stafford