MathGroup Archive 1999

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Tube Plot

  • To: mathgroup at smc.vnet.net
  • Subject: [mg17725] Re: [mg17684] Tube Plot
  • From: Daniel Lichtblau <danl>
  • Date: Tue, 25 May 1999 02:15:12 -0400
  • References: <199905220359.XAA15906@smc.vnet.net.>
  • Sender: owner-wri-mathgroup at wolfram.com

Joseph & Donna Post wrote:
> 
>     I've been looking for a routine that does "tube plots" in
> Mathematica, i.e., 3D plots showing cylindrical tubes, possibly of
> variable radius, constructed around parametrically described space
> curves.   One routine that I looked at in Mathsource, as well as others
> that I've seen, are based on the construction of a three-D coordinate
> system at every point in the curve, with the three unit vectors being
> the normalized versions of: (a) tangent vector to the curve, (b) a
> second vector based on the derivative of the tangent vector (which is
> perpendicular to the tangent vector and follows the "twist" of the
> curve), and (c) a third vector equal to the cross product of the first
> two.  Once this coordinate system is defined for each point on the
> curve, points on the tube surface are defined as (Sin[theta] * tube
> radius * second coordinate vector) + (Cos[theta] * tube radius * third
> coordinate vector).  The tube surface is draw by ParametricPlot3D, with
> the two parameters being theta (which varies from 0 to 2Pi), and the
> single parameter defining the curve.  Well and good.
> 
>     The problem comes when trying to draw a tube around a straight
> line.  Although plotting a cylinder might seem like too trivial a
> problem to use a Tube Plot routine for, tube plotting is in fact a very
> easy way to plot surfaces that can be described by a tube of variable
> radius tube around a straight line.  I solved this problem by writing a
> separate routine for tubes around straight lines, and then using that
> routine or the original one depending upon whether the derivative of the
> tangent vector with respect to the space curve parameter was or was not
> identically zero.  That works fine, mostly.
> 
>     This still leaves a problem, however, where the derivative of the
> tangent vector with respect to the space curve parameter is zero not
> identically, but at a point.  An example is the space curve {t, Sin[t],
> 0}, a simple sine wave.  The tube plotting routine squeezes the tube to
> a point at the inflection points of the curve (i.e., where it crosses
> the x axis), because the derivative of the tangent vector (and therefore
> the second coordinate vector) become zero vectors at that point.  There
> are also a number of error messages generated that result from
> divide-by-zero's during the normalization process.
> 
>     Any suggestions for how to deal with this problem?
> 
>     Thanks.
> 
>                      -- Joseph



You can get the normal vectors to the curve by finding the null space to
the matrix formed by the tangent vector and then orthonormalizing it.
The code below does this (my last version found perps to the position
vectors for the curve rather than to the tangent vectors).

<<LinearAlgebra`Orthogonalization`
tubeplot[curve_List, range_List, radius_] := Module[
	{perps, var=First[range], theta},
	perps = GramSchmidt[NullSpace[{D[curve,var]}]];
	ParametricPlot3D[Evaluate[curve +
	  radius*Transpose[perps].{Sin[theta],Cos[theta]}],
	  Evaluate[range], {theta,0,2*Pi}, PlotPoints->50];
	]

Here is the example from the original post.

curve1= {t,Sin[t],0};
tubeplot[curve1,{t,-5,5},1]


Here are two examples that have tangents that vanish at a point in the
parameter interval. This is noticeable in the plot but not easily
avoided (and also it is not disasterous to the picture). One can make
the "pinched" regions small by upping the PlotPoints but this tends to
make the process rather slow.

curve2 = {t+1-Exp[t],Sin[t],0};
tubeplot[curve2,{t,-2,2},.3]
curve3 = {t-1-Log[t],Cos[t*Pi/2],0};
tubeplot[curve3,{t,.1,4},.2]


Daniel Lichtblau
Wolfram Research


  • References:
    • Tube Plot
      • From: Joseph & Donna Post <jpost@panix.com>
  • Prev by Date: HELP: Bad GrayLevel
  • Next by Date: Multiple 3D Plots
  • Previous by thread: Tube Plot
  • Next by thread: Re: Tube Plot