Phase portrait on a cylinder - Mathematica Stack Exchange most recent 30 from mathematica.stackexchange.com 2019-09-19T20:26:19Z https://mathematica.stackexchange.com/feeds/question/64407 https://creativecommons.org/licenses/by-sa/4.0/rdf https://mathematica.stackexchange.com/q/64407 24 Phase portrait on a cylinder Artem https://mathematica.stackexchange.com/users/1179 2014-10-29T14:23:22Z 2016-12-04T21:24:46Z <p>It is very nice and very easy to make a sketch of a <a href="http://mathworld.wolfram.com/PhasePortrait.html" rel="nofollow noreferrer">phase portrait</a> with <code>StreamPlot</code>. For example, for the classical pendulum, defined by</p> <p>\begin{eqnarray*} \dot x&amp;=&amp;y,\\ \dot y&amp;=&amp;-\sin x, \end{eqnarray*}</p> <p>The code </p> <pre><code>StreamPlot[{y, -Sin[x]}, {x, -5, 5}, {y, -3, 3}, Frame -&gt; None, StreamPoints -&gt; Fine, AspectRatio -&gt; 0.8, Epilog -&gt; {PointSize -&gt; Large, Point[{{0, 0}, {\[Pi], 0}, {-\[Pi], 0}}]}] </code></pre> <p>produces</p> <p><img src="https://i.stack.imgur.com/CDuJG.jpg" alt="enter image description here"></p> <p>Now to the question. The actual phase space for the pendulum is not the plane $\mathbf R^2$, but the cylinder $\mathbf S^1\times \mathbf R$, and the pendulum of course has only two equilibria, one at $(0,0)$ and another one at $(\pi,0)$. Actually two points in the graph, the left and the right ones, are the same equilibrium.</p> <p>Question: How in <em>Mathematica</em> I can efficiently plot my phase portrait on a cylinder, such that I have only two equilibria, and I could see through the whole cylinder (I found examples on the site how to put a texture on a cylinder, but cannot figure out how to make it transparent).</p> https://mathematica.stackexchange.com/questions/64407/-/64409#64409 29 Answer by Kuba for Phase portrait on a cylinder Kuba https://mathematica.stackexchange.com/users/5478 2014-10-29T15:07:50Z 2014-10-29T17:32:10Z <pre><code>plot = StreamPlot[{y, -Sin[x]}, {x, -Pi, Pi}, {y, -3, 3}, Frame -&gt; None, Epilog -&gt; {PointSize -&gt; Large, Point[{{0, 0}, {π, 0}, {-π, 0}}]}, StreamPoints -&gt; Fine, AspectRatio -&gt; 0.8] </code></pre> <p>Try this:</p> <pre><code>First[Normal@plot] /. a_Arrow :&gt; ( a /. {x_Real, y_Real} :&gt; {Cos[x], Sin[x], y} ) // Graphics3D </code></pre> <p><img src="https://i.stack.imgur.com/JZzVC.png" alt="enter image description here"></p> <p>You can add <code>Cylinder</code> if you want:</p> <pre><code>Show[ %, Graphics3D@{Opacity@.7, LightBlue, Cylinder[{{0, 0, -3}, {0, 0, 3}}]} ] </code></pre> <p><img src="https://i.stack.imgur.com/0H5fN.png" alt="enter image description here"></p> https://mathematica.stackexchange.com/questions/64407/-/64411#64411 17 Answer by Jens for Phase portrait on a cylinder Jens https://mathematica.stackexchange.com/users/245 2014-10-29T15:30:04Z 2014-10-29T17:55:19Z <p>You could use an image representation of the plot and map it onto the modified cylinder that I defined in <a href="https://mathematica.stackexchange.com/a/52336/245">the answer linked here</a>. </p> <p>Just copy the definition of <code>cyl</code> from that answer, which includes the ability to add textures as follows:</p> <pre><code>img = Image@StreamPlot[{y, -Sin[x]}, {x, -5, 5}, {y, -3, 3}, Frame -&gt; None, PlotRange -&gt; {{-5, 5}, {-3, 3}}, Epilog -&gt; {PointSize -&gt; Large, Point[{{0, 0}, {Pi, 0}, {-Pi, 0}}]}, StreamPoints -&gt; Fine, AspectRatio -&gt; 0.8, PlotRangePadding -&gt; 0, ImageMargins -&gt; 0, ImageSize -&gt; 800]; Graphics3D[{Texture[img], EdgeForm[], cyl[{{0, 0, 0}, {0, 0, 2 Pi}}, 1]}, Boxed -&gt; False] </code></pre> <p><img src="https://i.stack.imgur.com/vZMdM.png" alt="cyl"></p> <p>The resolution is controlled by the options of <code>Image</code> or by the <code>ImageSize</code> options in <code>StreamPlot</code>.</p> <p>I also added the <code>PlotRange</code> to the original plot to suppress the plot range padding. </p> <p><strong>Edit</strong></p> <p>To make the whole thing transparent, you can use the same approach provided that the image has an alpha channel with transparent background:</p> <pre><code>img = Rasterize[ StreamPlot[{y, -Sin[x]}, {x, -5, 5}, {y, -3, 3}, Frame -&gt; None, PlotRange -&gt; {{-5, 5}, {-3, 3}}, Epilog -&gt; {PointSize -&gt; Large, Point[{{0, 0}, {Pi, 0}, {-Pi, 0}}]}, StreamPoints -&gt; Fine, AspectRatio -&gt; 0.8, PlotRangePadding -&gt; 0, ImageMargins -&gt; 0, ImageSize -&gt; 500], Background -&gt; None, ImageResolution -&gt; 300 ]; Graphics3D[{Texture[ImageData@img], EdgeForm[], cyl[{{0, 0, 0}, {0, 0, 2 Pi}}, 1]}, Boxed -&gt; False, Lighting -&gt; "Neutral"] </code></pre> <p><img src="https://i.stack.imgur.com/AfRnA.png" alt="trasnp"></p> <p>Here I used <code>Rasterize</code> because it permits a <code>Background -&gt; None</code> option. Also, I used <code>ImageResolution</code> in combination with the <code>ImageSize</code> specification of the <code>StreamPlot</code> to make sure that the <code>Point</code>s from the <code>Epilog</code> in the original plot are properly visible. </p> <p>To combine transparency with a cylinder "backbone" for better visibility, you could do it like this:</p> <pre><code>Graphics3D[{Texture[ImageData@img], EdgeForm[], cyl[{{0, 0, 0}, {0, 0, 2 Pi}}, 1], FaceForm[Directive[Opacity[.5], Orange]], Cylinder[{{0, 0, -.01}, {0, 0, 2 Pi + .01}}, .99]}, Boxed -&gt; False, Lighting -&gt; "Neutral"] </code></pre> <p><img src="https://i.stack.imgur.com/LJKSP.png" alt="backbone"></p>