Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Plotting circle tangent to a curve in 3d
Date: Thu, 1 Mar 2012 20:38:12 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 20
Message-ID: <jiomnj$t63$1@newscl01ah.mathworks.com>
References: <jio009$84g$1@newscl01ah.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: www-05-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1330634292 29891 172.30.248.37 (1 Mar 2012 20:38:12 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 1 Mar 2012 20:38:12 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: news.mathworks.com comp.soft-sys.matlab:759512

"Edward Tan" <octrs@hotmail.com> wrote in message <jio009$84g$1@newscl01ah.mathworks.com>...
> Hi,
>     I have a question which requires advice from the community. I have a curve in 3D plot and I want to plot circles with its center coincide with the points on the curve. In additional, i would like the circles oriented such that its radius and theta plane is normal to the tangent of the curve. Can someone help advise on this? Thank you very much for your time.
> 
> Thanks
> Edward
- - - - - - - -
  Suppose that P0 is the point about which a circle is to be drawn with radius R and with the plane of the circle orthogonal to the tangent direction of the curve at P0.  Let P1 be the previous point on the curve to P0 and P2 the following point.  Let all three points be represented by 1 by 3 row vectors of cartesian coordinates.  Then do this:

 P10 = P1-P0;
 P20 = P2-P0;
 N = dot(P10,P10)*P20-dot(P20,P20)*P10; % <-- Approx. tangent direction
 T = null(N).'; % Get two orthogonal unit vectors which are orthog. to N
 theta = linspace(0,2*pi).';
 V = bsxfun(@plus,R*(cos(theta)*T(1,:)+sin(theta)*T(2,:)),P0);
 plot3(V(:,1),V(:,2),V(:,3))

  The vector N approximates the curve tangent direction at P0 in terms of the two neighboring points P1 and P2.  As theta advances from 0 to 2*pi, the array V traces out the desired circle with P0 at the center and plane orthogonal to N.

Roger Stafford