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$>
References: <jio009$84g$>
Reply-To: <HIDDEN>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: 1330634292 29891 (1 Mar 2012 20:38:12 GMT)
NNTP-Posting-Date: Thu, 1 Mar 2012 20:38:12 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: comp.soft-sys.matlab:759512

"Edward Tan" <> wrote in message <jio009$84g$>...
> 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);

  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