home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / e / e032 / 3.ddi / FILES / PROGRAMM.PAK / PARAMETR.M < prev    next >
Encoding:
Text File  |  1992-07-29  |  4.7 KB  |  139 lines

  1.  
  2. (*:Version: Mathematica 2.0 *)
  3.  
  4. (*:Name: Graphics`ParametricPlot3D *)
  5.  
  6. (*:Title: Parametric Plots of 3D Objects *)
  7.  
  8. (*:Author:
  9.     Roman E. Maeder
  10. *)
  11.  
  12. (*:Keywords:
  13.     Parametric, Spherical, Cylindrical Plot, 3D
  14. *)
  15.  
  16. (*:Requirements: none. *)
  17.  
  18. (*:Warnings: none. *)
  19.  
  20. (*:Sources:
  21.     Roman E. Maeder: Programming in Mathematica, 2nd Ed.,
  22.     Addison-Wesley, 1991.
  23. *)
  24.  
  25. (*:Summary:
  26. *)
  27.  
  28.  
  29. BeginPackage["Graphics`ParametricPlot3D`"]
  30.  
  31. ParametricPlot3D::usage = StringJoin[ ParametricPlot3D::usage, 
  32.     " ParametricPlot3D[{x,y,z,(style)}, {u,u0,u1,du}, ({v,v0,v1,dv})]
  33.     uses increments du and dv instead of the PlotPoints option." ]
  34.  
  35. PointParametricPlot3D::usage =
  36.     "PointParametricPlot3D[{x,y,z}, {u,u0,u1,(du)}, (options..)]
  37.     plots a one-parameter set of points in space.
  38.     PointParametricPlot3D[{x,y,z}, {u,u0,u1,(du)}, {v,v0,v1,(dv)}, (options..)]
  39.     plots a two-parameter set of points in space. Options are passed to Show[]."
  40.  
  41. SphericalPlot3D::usage = "SphericalPlot3D[r, {theta-range}, {phi-range}, (options...)]
  42.     plots r as a function of the angles theta and phi.
  43.     SphericalPlot3D[{r, style}, ...] uses style to render each surface patch"
  44.  
  45. CylindricalPlot3D::usage = "CylindricalPlot3D[z, {r-range}, {phi-range}, (options...)]
  46.     plots z as a function of r and phi.
  47.     CylindricalPlot3D[{z, style},  ...] uses style to render each surface patch"
  48.  
  49. Begin["`Private`"]
  50.  
  51. protected = Unprotect[ParametricPlot3D]
  52.  
  53. FilterOptions[ command_Symbol, opts___ ] :=
  54.     Module[{keywords = First /@ Options[command]},
  55.         Sequence @@ Select[ {opts}, MemberQ[keywords, First[#]]& ]
  56.     ]
  57.  
  58. (* overload ParametricPlot3D to allow increments in iterators *)
  59.  
  60. ParametricPlot3D[ fun_,
  61.     {u_, u0_, u1_, du_:Automatic}, {v_, v0_, v1_, dv_:Automatic}, opts___ ] :=
  62.     Module[{plotpoints},
  63.         plotpoints = PlotPoints /. {opts} /. Options[ParametricPlot3D];
  64.         If[ Head[plotpoints] =!= List, plotpoints = {plotpoints, plotpoints} ];
  65.         If[ du =!= Automatic, plotpoints[[1]] = Round[N[(u1-u0)/du]] + 1 ];
  66.         If[ dv =!= Automatic, plotpoints[[2]] = Round[N[(v1-v0)/dv]] + 1 ];
  67.         ParametricPlot3D[ fun, {u, u0, u1}, {v, v0, v1},
  68.             PlotPoints -> plotpoints, opts]
  69.     ]  /; du =!= Automatic || dv =!= Automatic
  70.  
  71. ParametricPlot3D[ fun_, {u_, u0_, u1_, du_}, opts___ ] :=
  72.     ParametricPlot3D[ fun, {u, u0, u1}, PlotPoints -> Round[N[(u1-u0)/du]] + 1, opts]
  73.  
  74.  
  75. Attributes[PointParametricPlot3D] = {HoldFirst}
  76.  
  77. PointParametricPlot3D[ fun_,
  78.         {u_, u0_, u1_, du_:Automatic}, {v_, v0_, v1_, dv_:Automatic}, opts___ ] :=
  79.     Module[{plotpoints, ndu = N[du], ndv = N[dv]},
  80.         plotpoints = PlotPoints /. {opts} /. Options[ParametricPlot3D];
  81.         If[ plotpoints === Automatic, plotpoints = 15];
  82.         If[ Head[plotpoints] =!= List, plotpoints = {plotpoints, plotpoints} ];
  83.         If[ du === Automatic, ndu = N[(u1-u0)/(plotpoints[[1]]-1)] ];
  84.         If[ dv === Automatic, ndv = N[(v1-v0)/(plotpoints[[2]]-1)] ];
  85.         Show[ Graphics3D[Table[ Point[N[fun]], {u, u0, u1, ndu}, {v, v0, v1, ndv} ]],
  86.               FilterOptions[Graphics3D, opts] ]
  87.     ]  /; NumberQ[N[u0]] && NumberQ[N[u1]] && NumberQ[N[v0]] && NumberQ[N[v1]]
  88.  
  89.  
  90. (* point space curve *)
  91.  
  92. PointParametricPlot3D[ fun_, ul:{_, u0_, u1_, du_}, opts___ ] :=
  93.     Show[ Graphics3D[Table[ Point[N[fun]], ul ]], FilterOptions[Graphics3D, opts] ] /;
  94.             NumberQ[N[u0]] && NumberQ[N[u1]] && NumberQ[N[du]]
  95.  
  96. PointParametricPlot3D[ fun_, {u_, u0_, u1_}, opts___ ] :=
  97.     Module[{plotpoints},
  98.         plotpoints = PlotPoints /. {opts} /. Options[ParametricPlot3D];
  99.         If[ Head[plotpoints] == List, plotpoints = plotpoints[[1]] ];
  100.     PointSpaceCurve[ fun, {u, u0, u1, (u1-u0)/(plotpoints-1)}, opts ]
  101.     ]
  102.  
  103.  
  104. Attributes[SphericalPlot3D] = {HoldFirst}
  105.  
  106. SphericalPlot3D[ {r_, style_}, tlist:{theta_, __}, plist:{phi_, __}, opts___ ] :=
  107.     Module[{rs},
  108.         ParametricPlot3D[ {(rs = r) Sin[theta] Cos[phi],
  109.                            rs Sin[theta] Sin[phi],
  110.                            rs Cos[theta],
  111.                            style},
  112.                           tlist, plist, opts ]
  113.     ]
  114.  
  115. SphericalPlot3D[ r_, tlist:{theta_, __}, plist:{phi_, __}, opts___ ] :=
  116.       ParametricPlot3D[ r{Sin[theta] Cos[phi],
  117.                           Sin[theta] Sin[phi],
  118.                           Cos[theta]},
  119.                         tlist, plist, opts ]
  120.  
  121.  
  122. Attributes[CylindricalPlot3D] = {HoldFirst}
  123.  
  124. CylindricalPlot3D[ {z_, style_}, rlist:{r_, __}, plist:{phi_, __}, opts___ ] :=
  125.     ParametricPlot3D[{r Cos[phi], r Sin[phi], z, style}, rlist, plist, opts]
  126.  
  127. CylindricalPlot3D[ z_, rlist:{r_, __}, plist:{phi_, __}, opts___ ] :=
  128.     ParametricPlot3D[{r Cos[phi], r Sin[phi], z}, rlist, plist, opts]
  129.  
  130. Protect[ Evaluate[protected] ]
  131.  
  132. End[]   (* Graphics`ParametricPlot3D`Private` *)
  133.  
  134. Protect[PointParametricPlot3D, SphericalPlot3D, CylindricalPlot3D]
  135.  
  136. EndPackage[]   (* Graphics`ParametricPlot3D` *)
  137.  
  138. (*:Limitations: none known. *)
  139.