Path: news.mathworks.com!not-for-mail 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$1@fred.mathworks.com> References: <in5ad5$6np$1@fred.mathworks.com> Reply-To: <HIDDEN> NNTP-Posting-Host: www-01-blr.mathworks.com Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: fred.mathworks.com 1301691784 18973 172.30.248.46 (1 Apr 2011 21:03:04 GMT) X-Complaints-To: news@mathworks.com NNTP-Posting-Date: Fri, 1 Apr 2011 21:03:04 +0000 (UTC) X-Newsreader: MATLAB Central Newsreader 1187260 Xref: news.mathworks.com comp.soft-sys.matlab:719590 "Liana" wrote in message <in5ad5$6np$1@fred.mathworks.com>... > 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