5
$\begingroup$

I have a plane curve $C$ described by parametric equations $x(t)$ and $y(t)$ and a function $f: \mathbb{R}^2 \rightarrow \mathbb{R}$. The line integral of $f$ along $C$ is the area of the "fence" whose path is governed by $C$ and height is governed by $f$.

enter image description here

How can I generate a picture of the "fence" in Mathematica?

For the sake of a concrete example, let's borrow from Stewart (since I already borrowed his picture). For $0 \leq t \leq \pi$, define $$ \begin{align*} x(t) &= \cos t\\ y(t) &= \sin t\\ f(x,y) &= 2 + x^2y \end{align*} $$ so that $$ \begin{align*} f(x(t),y(t)) &= 2 + \cos^2 t \sin t. \end{align*} $$

$\endgroup$
  • 1
    $\begingroup$ Check out ParametricPlot3D. $\endgroup$ – Rahul Nov 10 '14 at 4:18
6
$\begingroup$
 ListPointPlot3D[
                 Table[{Cos[t], Sin[t], 2 + Sin[t] Cos[t]^2} ,{t, 0, π, 0.01}] , 
                 Filling -> 0]

Mathematica graphics

$\endgroup$
  • $\begingroup$ Simple code and beautiful output. Thank you. $\endgroup$ – Austin Mohr Nov 10 '14 at 5:03
  • 1
    $\begingroup$ It should be Filling -> 0, though. $\endgroup$ – Rahul Nov 10 '14 at 5:08
  • $\begingroup$ Yes, corrected now. Thanks! $\endgroup$ – Sander Nov 10 '14 at 5:15
  • $\begingroup$ @belisarius Thanks for including the graph! $\endgroup$ – Sander Nov 10 '14 at 13:06
6
$\begingroup$
opts = {MeshFunctions -> (#4 &), 
        MeshShading ->   {{Opacity[#2], #1}, {Opacity[#2/2], #1}}, 
        BoxRatios ->     {1, 1, 1/2}, 
        BoundaryStyle -> Directive[Thin, Blue]} &; 
Show[
 ParametricPlot3D[{Cos[t], Sin[t], z (2 + Sin[t] Cos[t]^2)}, {t, 0, π/2}, {z, 0, 1}, 
                  Evaluate@opts[Green, .4]], 
 ParametricPlot3D[{Cos[t], z Sin[t], 0 }, {t, 0, π/2}, {z, 0, 1},
                  Evaluate@opts[Blue, .2]],
 ParametricPlot3D[{z Cos[t], Sin[t], 0 }, {t, 0, π/2}, {z, 0, 1}, 
                  Evaluate@opts[Blue, .2]]]

Mathematica graphics

$\endgroup$
5
$\begingroup$

I have not done the labeling but this is a start:

axes[n_] := 
  With[{uv = n IdentityMatrix[3]}, 
   Graphics3D[{Arrow[{{0, 0, 0}, #}] & /@ uv, 
     MapThread[
      Text[#1, 1.1 #2] &, {Style[#, 20] & /@ {"x", "y", "z"}, uv}]}, 
    Boxed -> False]];
p = ParametricPlot3D[{Cos[t], Sin[t], u (2 + Cos[t]^2 Sin[t])}, {t, 0,
     Pi/2}, {u, 0, 1}, MeshFunctions -> {#4 &, #5 &}, 
   Mesh -> {10, {0.99}}, 
   MeshStyle -> {Directive[Blue, Thick], 
     Directive[Red, Thickness[0.01]]}, Boxed -> False, 
   PlotStyle -> {LightBlue, Opacity[0.5]}, Axes -> False];
Show[axes[3], p]

enter image description here

$\endgroup$
5
$\begingroup$

This is just a small tweak of Belisarius' answer, using MeshFunctions to get the vertical lines and BoundaryStyle to get the "fence".

ParametricPlot3D[{Cos[t], Sin[t], z (2 + Sin[t] Cos[t]^2)}, {t, 
  0, \[Pi]/2}, {z, 0, 1}, MeshFunctions -> {#2 &}, MeshStyle -> {Red},
  BoundaryStyle -> Directive[Thick, Blue], BoxRatios -> {1, 1, 1/2}, 
 PlotStyle -> Opacity[.5]]

enter image description here

An alternative that gives more "even" vertical lines is to specify the mesh in terms of t and z.

ParametricPlot3D[{Cos[t], Sin[t], z (2 + Sin[t] Cos[t]^2)}, {t, 
  0, \[Pi]/2}, {z, 0, 1}, 
 Mesh -> {Range[0, 1, 0.1], Range[0, 2, 0.5], Range[0, 1, 0.1]}, 
 MeshStyle -> {Directive[Red, Thick], Directive[Green, Thick]}, 
 BoundaryStyle -> Directive[Blue, Thick], BoxRatios -> {1, 1, 1/2}, 
 PlotStyle -> Opacity[.5]]

enter image description here

And as Belisarius points out in comments (I'm going to have to CW this one!), MeshFunctions -> {#4 &} is even evener :)

ParametricPlot3D[{Cos[t], Sin[t], z (2 + Sin[t] Cos[t]^2)}, {t, 
  0, \[Pi]/2}, {z, 0, 1}, MeshFunctions -> {#4 &}, MeshStyle -> {Red},
  BoundaryStyle -> Directive[Thick, Blue], BoxRatios -> {1, 1, 1/2}, 
 PlotStyle -> Opacity[.5]]

enter image description here

$\endgroup$
  • $\begingroup$ @ubpdqn - I've added the other example. I probably should have included it in the first iteration (I'd already thought of it) but focused on BoundaryStyle as the value I was adding. $\endgroup$ – Verbeia Nov 10 '14 at 6:39
  • $\begingroup$ MeshFunctions -> {#4 &}? $\endgroup$ – Dr. belisarius Nov 10 '14 at 6:40
  • $\begingroup$ I thought the mesh should be able to do it, but it exceeded my skill. Thanks to you and belisaurius for getting this out of ParametricPlot3D. $\endgroup$ – Austin Mohr Nov 10 '14 at 16:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.