<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/topological-tomfoolery-in-r-plotting-a-mobius-strip/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://r.prevos.net/plotting-mobius-strip/"> The Devil is in the Data</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>Topology is, according to <a rel="nofollow" href="http://www.pickover.com/" target="_blank">Clifford Pickover</a>, the “silly putty of mathematics”. This branch of maths studies the transformation of shapes, knots and other complex geometry problems.  One of the most famous topics in topology is the <a rel="nofollow" href="https://en.wikipedia.org/wiki/M%C3%B6bius_strip" target="_blank">Möbius strip</a>. This shape has some unusual properties which have inspired many artists, inventors, mathematicians and magicians.</p>
<p>You can make a Möbius strip by taking a strip of paper, giving it one twist and glue the ends together to form a loop. If you now cut this strip lengthwise in half, you don’t end-up with two separate strips, but with one long one.</p>
<p><iframe allowfullscreen="true" src="https://www.youtube.com/embed/wKV0GYvR2X8?version=3&rel=1&%23038;fs=1&%23038;autohide=2&%23038;showsearch=0&%23038;showinfo=1&%23038;iv_load_policy=1&%23038;wmode=transparent" width="450" type="text/html"></iframe></p>
<p>The Möbius strip can also be described with the following parametric equations (where <img alt="0 leq u leq 2pi" title="0 leq u leq 2pi" src="https://s0.wp.com/latex.php?latex=0+%5Cleq+u+%5Cleq+2%5Cpi&bg=ffffff&%23038;fg=000&%23038;s=0" class="latex">, <img alt="-1 leq v leq 1" title="-1 leq v leq 1" src="https://s0.wp.com/latex.php?latex=-1+%5Cleq+v+%5Cleq+1&bg=ffffff&%23038;fg=000&%23038;s=0" class="latex"> and <img alt="R" title="R" src="https://s0.wp.com/latex.php?latex=R&bg=ffffff&%23038;fg=000&%23038;s=0" class="latex"> is the radius of the loop):</p>
<p><img alt="x(u,v)= left(R+frac{v}{2} cos frac{u}{2}right)cos u" title="x(u,v)= left(R+frac{v}{2} cos frac{u}{2}right)cos u" src="https://s0.wp.com/latex.php?latex=x%28u%2Cv%29%3D+%5Cleft%28R%2B%5Cfrac%7Bv%7D%7B2%7D+%5Ccos+%5Cfrac%7Bu%7D%7B2%7D%5Cright%29%5Ccos+u&bg=ffffff&%23038;fg=000&%23038;s=0" class="latex"><br>
<img alt="y(u,v)= left(R+frac{v}{2} cosfrac{u}{2}right)sin u" title="y(u,v)= left(R+frac{v}{2} cosfrac{u}{2}right)sin u" src="https://s0.wp.com/latex.php?latex=y%28u%2Cv%29%3D+%5Cleft%28R%2B%5Cfrac%7Bv%7D%7B2%7D+%5Ccos%5Cfrac%7Bu%7D%7B2%7D%5Cright%29%5Csin+u&bg=ffffff&%23038;fg=000&%23038;s=0" class="latex"><br>
<img alt="z(u,v)= frac{v}{2}sin frac{u}{2}" title="z(u,v)= frac{v}{2}sin frac{u}{2}" src="https://s0.wp.com/latex.php?latex=z%28u%2Cv%29%3D+%5Cfrac%7Bv%7D%7B2%7D%5Csin+%5Cfrac%7Bu%7D%7B2%7D&bg=ffffff&%23038;fg=000&%23038;s=0" class="latex"></p>
<p>The <a rel="nofollow" href="https://math.stackexchange.com/questions/638225/understanding-the-equation-of-a-m%C3%B6bius-strip" target="_blank">mathematics of this set of parametric equations</a> is not as compex as it looks. <img alt="R " title="R " src="https://s0.wp.com/latex.php?latex=R+&bg=ffffff&%23038;fg=000&%23038;s=0" class="latex"> is the radius of the ring, <img alt="u" title="u" src="https://s0.wp.com/latex.php?latex=u&bg=ffffff&%23038;fg=000&%23038;s=0" class="latex"> is the polar angle of each point and <img alt="v" title="v" src="https://s0.wp.com/latex.php?latex=v&bg=ffffff&%23038;fg=000&%23038;s=0" class="latex"> indicates the width of the strip. The polar angle <img alt="u/2" title="u/2" src="https://s0.wp.com/latex.php?latex=u%2F2&bg=ffffff&%23038;fg=000&%23038;s=0" class="latex"> indicates the number of half twists. To make the ring twist twice, change the anlge to <img alt="u" title="u" src="https://s0.wp.com/latex.php?latex=u&bg=ffffff&%23038;fg=000&%23038;s=0" class="latex">.</p>
<p>For my data science day job, I have to visualise some three-dimensional spaces so I thought I best learn how to do this by visualising a Möbis strip, using these three equations.</p>
<h2>Plotting a Möbius Strip</h2>
<p>The <a rel="nofollow" href="https://cran.r-project.org/web/packages/rgl/vignettes/rgl.html" target="_blank">RGL package</a> provides the perfect functionality to play with virtual Möbius strips. This package produces interactive three-dimensional plots that you can zoom and rotate. This package has many options to change lighting, colours, shininess and so on. The code to create for plotting a Möbius strip is straightforward.</p>
<p>The first section defines the parameters and converts the <img alt="u " title="u " src="https://s0.wp.com/latex.php?latex=u+&bg=ffffff&%23038;fg=000&%23038;s=0" class="latex"> and <img alt="v " title="v " src="https://s0.wp.com/latex.php?latex=v+&bg=ffffff&%23038;fg=000&%23038;s=0" class="latex"> sequences to a mesh (from the <a rel="nofollow" href="https://cran.r-project.org/web/packages/plot3D/index.html" target="_blank">plot3D package</a>). This function creates two matrices with every possible combination of <img alt="u" title="u" src="https://s0.wp.com/latex.php?latex=u&bg=ffffff&%23038;fg=000&%23038;s=0" class="latex"> and <img alt="v " title="v " src="https://s0.wp.com/latex.php?latex=v+&bg=ffffff&%23038;fg=000&%23038;s=0" class="latex"> which are used to calculate the <img alt="x, y, z" title="x, y, z" src="https://s0.wp.com/latex.php?latex=x%2C+y%2C+z&bg=ffffff&%23038;fg=000&%23038;s=0" class="latex"> points.</p>
<p>The last three lines define a 3D window with a white background and plot the 3D surface in blue. You can explore the figure with your mouse by zooming and rotating it. Parametric equations can be a bit of fun, play with the formula to change the shape and see what happens.</p>
<pre>
# Moebius strip
library(rgl)
library(plot3D)

# Define Parameters
R &lt;- 5
u &lt;- seq(0, 2 * pi, length.out = 100)
v &lt;- seq(-1, 1, length.out = 100)
m &lt;- mesh(u, v)
u &lt;- m$x
v &lt;- m$y

# Móbius strip parametric equations
x &lt;- (R + v/2 * cos(u /2)) * cos(u)
y &lt;- (R + v/2 * cos(u /2)) * sin(u)
z &lt;- v/2 * sin(u / 2)  

# Visualise
bg3d(color = &quot;white&quot;)
surface3d(x, y, z, color= &quot;blue&quot;)
</pre>
<p>You can find the latest version of this code on <a rel="nofollow" href="https://github.com/pprevos/r.prevos.net/blob/master/Misc/moebius.R" target="_blank">GitHub</a>.</p>
<div class="wp-caption"><a rel="nofollow" href="https://r.prevos.net/?attachment_id=1138" target="_blank"><img data-orig-file="https://i2.wp.com/r.prevos.net/wp-content/uploads/sites/11/2018/02/moebiusrgl.png?fit=1253%2C508&amp;ssl=1" data-orig-size="1253,508" data-medium-file="https://i2.wp.com/r.prevos.net/wp-content/uploads/sites/11/2018/02/moebiusrgl.png?fit=300%2C122&amp;ssl=1" data-attachment-id="1138" data-image-meta="{" data-image-description="" src="https://i2.wp.com/r.prevos.net/wp-content/uploads/sites/11/2018/02/moebiusrgl.png?resize=584%2C237&ssl=1" data-permalink="https://r.prevos.net/plotting-mobius-strip/moebiusrgl/" data-large-file="https://i2.wp.com/r.prevos.net/wp-content/uploads/sites/11/2018/02/moebiusrgl.png?fit=584%2C237&amp;ssl=1" alt="Plotting a Möbius Strip" data-image-title="moebiusrgl" sizes="(max-width: 584px) 100vw, 584px" width="450" data-comments-opened="1" class="wp-image-1138" data-recalc-dims="1"></a>
<p class="wp-caption-text">Plotting a Möbius Strip: RGL output.</p>
</div>
<p>We can take it to the next level by plotting a three-dimensional Möbius strip, or a <a rel="nofollow" href="https://en.wikipedia.org/wiki/Klein_bottle" target="_blank">Klein Bottle</a>. The parametric equations for the bottle are mind boggling:</p>
<p><img alt="x(u,v) = -frac{2}{15} cos u (3 cos{v}-30 sin{u}+90 cos^4{u} sin{u} -60 cos^6{u} sin{u} +5 cos{u} cos{v} sin{u}) " title="x(u,v) = -frac{2}{15} cos u (3 cos{v}-30 sin{u}+90 cos^4{u} sin{u} -60 cos^6{u} sin{u} +5 cos{u} cos{v} sin{u}) " src="https://s0.wp.com/latex.php?latex=x%28u%2Cv%29+%3D+-%5Cfrac%7B2%7D%7B15%7D+%5Ccos+u+%283+%5Ccos%7Bv%7D-30+%5Csin%7Bu%7D%2B90+%5Ccos%5E4%7Bu%7D+%5Csin%7Bu%7D+-60+%5Ccos%5E6%7Bu%7D+%5Csin%7Bu%7D+%2B5+%5Ccos%7Bu%7D+%5Ccos%7Bv%7D+%5Csin%7Bu%7D%29+&bg=ffffff&%23038;fg=000&%23038;s=0" class="latex"></p>
<p><img alt="y(u,v) = -frac{1}{15} sin u (3 cos{v}-3 cos^2{u} cos{v}-48 cos^4{u} cos{v} + 48 cos^6{u} cos{v} - 60 sin{u}+5 cos{u} cos{v} sin{u}-5 cos^3{u} cos{v} sin{u}-80 cos^5{u} cos{v} sin{u}+80 cos^7{u} cos{v} sin{u}) " title="y(u,v) = -frac{1}{15} sin u (3 cos{v}-3 cos^2{u} cos{v}-48 cos^4{u} cos{v} + 48 cos^6{u} cos{v} - 60 sin{u}+5 cos{u} cos{v} sin{u}-5 cos^3{u} cos{v} sin{u}-80 cos^5{u} cos{v} sin{u}+80 cos^7{u} cos{v} sin{u}) " src="https://s0.wp.com/latex.php?latex=y%28u%2Cv%29+%3D+-%5Cfrac%7B1%7D%7B15%7D+%5Csin+u+%283+%5Ccos%7Bv%7D-3+%5Ccos%5E2%7Bu%7D+%5Ccos%7Bv%7D-48+%5Ccos%5E4%7Bu%7D+%5Ccos%7Bv%7D+%2B+48+%5Ccos%5E6%7Bu%7D+%5Ccos%7Bv%7D+-+60+%5Csin%7Bu%7D%2B5+%5Ccos%7Bu%7D+%5Ccos%7Bv%7D+%5Csin%7Bu%7D-5+%5Ccos%5E3%7Bu%7D+%5Ccos%7Bv%7D+%5Csin%7Bu%7D-80+%5Ccos%5E5%7Bu%7D+%5Ccos%7Bv%7D+%5Csin%7Bu%7D%2B80+%5Ccos%5E7%7Bu%7D+%5Ccos%7Bv%7D+%5Csin%7Bu%7D%29+&bg=ffffff&%23038;fg=000&%23038;s=0" class="latex"></p>
<p><img alt="z(u,v) = frac{2}{15} (3+5 cos{u} sin{u}) sin{v} " title="z(u,v) = frac{2}{15} (3+5 cos{u} sin{u}) sin{v} " src="https://s0.wp.com/latex.php?latex=z%28u%2Cv%29+%3D+%5Cfrac%7B2%7D%7B15%7D+%283%2B5+%5Ccos%7Bu%7D+%5Csin%7Bu%7D%29+%5Csin%7Bv%7D+&bg=ffffff&%23038;fg=000&%23038;s=0" class="latex"></p>
<p>Where: <img alt="0 leq u leq pi" title="0 leq u leq pi" src="https://s0.wp.com/latex.php?latex=0+%5Cleq+u+%5Cleq+%5Cpi&bg=ffffff&%23038;fg=000&%23038;s=0" class="latex"> and <img alt="0 leq v leq 2leq" title="0 leq v leq 2leq" src="https://s0.wp.com/latex.php?latex=0+%5Cleq+v+%5Cleq+2%5Cleq&bg=ffffff&%23038;fg=000&%23038;s=0" class="latex">.</p>
<p>The code to visualise this bottle is essentially the same, just more complex equations.</p>
<pre>
u &lt;- seq(0, pi, length.out = 100)
v &lt;- seq(0, 2 * pi, length.out = 100)
m &lt;- mesh(u, v)
u &lt;- m$x
v &lt;- m$y
x &lt;- (-2 / 15) * cos(u) * (3 * cos(v) - 30 * sin(u) + 90 * cos(u)^4 * sin(u) - 60 * cos(u)^6 * sin(u) + 5 * cos(u) * cos(v) * sin(u))
y &lt;- (-1 / 15) * sin(u) * (3 * cos(v) - 3 * cos(u)^2 * cos(v) - 48 * cos(u)^4 * cos(v) + 48 * cos(u)^6 * cos(v) - 60 * sin(u) + 5 * cos(u) * cos(v) * sin(u) - 5 * cos(u)^3 * cos(v) * sin(u) - 80 * cos(u)^5 * cos(v) * sin(u) + 80 * cos(u)^7 * cos(v) * sin(u))
z &lt;- (+2 / 15) * (3 + 5 * cos(u) * sin(u)) * sin(v)

bg3d(color = &quot;white&quot;)
surface3d(x, y, z, color= &quot;blue&quot;, alpha = 0.5)
</pre>
<div class="wp-caption"><a rel="nofollow" href="http://rpubs.com/pprevos/KleinBottle" target="_blank"><img data-orig-file="https://i2.wp.com/r.prevos.net/wp-content/uploads/sites/11/2018/03/KleinBottle.png?fit=908%2C676&amp;ssl=1" data-orig-size="908,676" data-medium-file="https://i2.wp.com/r.prevos.net/wp-content/uploads/sites/11/2018/03/KleinBottle.png?fit=300%2C223&amp;ssl=1" data-attachment-id="1172" data-image-meta="{" data-image-description="&lt;p&gt;Plotting a Klein Bottle in 3GL&lt;/p&gt;
" src="https://i2.wp.com/r.prevos.net/wp-content/uploads/sites/11/2018/03/KleinBottle.png?resize=584%2C435&ssl=1" data-permalink="https://r.prevos.net/plotting-mobius-strip/kleinbottle/" data-large-file="https://i2.wp.com/r.prevos.net/wp-content/uploads/sites/11/2018/03/KleinBottle.png?fit=584%2C435&amp;ssl=1" alt="Plotting a Klein Bottle in RGL" data-image-title="KleinBottle" sizes="(max-width: 584px) 100vw, 584px" width="450" data-comments-opened="1" class="wp-image-1172" data-recalc-dims="1"></a>
<p class="wp-caption-text">Plotting a Klein Bottle in RGL. Click to view RGL widget.</p>
</div>
<p>The RGL package has some excellent facilities to visualise three-dimensional objects, far beyond simple strips. I am still learning and am working toward using it to visualise bathymetric surveys of water reservoirs. Möbius strips are, however, a lot more fun.</p>
<h2>Creating Real Möbius Strips</h2>
<p>Even more fun than playing with virtual Möbius strips is to make some paper versions and start cutting, just like August Möbius did when he did his research. If you like to create a Möbius strip, you can recycle then purchase a <a rel="nofollow" href="http://amzn.to/2FIxFHE" target="_blank">large zipper</a> from your local haberdashery shop, add some hook-and-loop fasteners to the ends and start playing. If you like to know more about the mathematics of the topological curiosity, then I can highly recommend <a rel="nofollow" href="http://amzn.to/2EeXJgI" target="_blank">Clifford Pickover’s book on the topic</a>.</p>
<div class="wp-caption"><a rel="nofollow" href="https://r.prevos.net/?attachment_id=1130" target="_blank"><img data-orig-file="https://i1.wp.com/r.prevos.net/wp-content/uploads/sites/11/2018/02/AfghanZipper.jpg?fit=3424%2C2248&amp;ssl=1" data-orig-size="3424,2248" data-medium-file="https://i1.wp.com/r.prevos.net/wp-content/uploads/sites/11/2018/02/AfghanZipper.jpg?fit=300%2C197&amp;ssl=1" data-attachment-id="1130" data-image-meta="{" data-image-description="" src="https://i1.wp.com/r.prevos.net/wp-content/uploads/sites/11/2018/02/AfghanZipper.jpg?resize=584%2C383&ssl=1" data-permalink="https://r.prevos.net/plotting-mobius-strip/afghanzipper/" data-large-file="https://i1.wp.com/r.prevos.net/wp-content/uploads/sites/11/2018/02/AfghanZipper.jpg?fit=584%2C383&amp;ssl=1" alt="Möbius strip zipper" data-image-title="AfghanZipper" sizes="(max-width: 584px) 100vw, 584px" width="450" data-comments-opened="1" class="wp-image-1130" data-recalc-dims="1"></a>
<p class="wp-caption-text">Möbius strip zipper.</p>
</div>
<h2>The Möbius Strip in Magic</h2>
<p>In the first half of the twentieth century, many magicians used the Möbius strip as a magic trick. The great Harry Blackstone performed it regularly in his show.</p>
<p><iframe allowfullscreen="true" src="https://www.youtube.com/embed/J__QN5XTTv8?version=3&rel=1&%23038;fs=1&%23038;autohide=2&%23038;showsearch=0&%23038;showinfo=1&%23038;iv_load_policy=1&%23038;start=26&%23038;wmode=transparent" width="450" type="text/html"></iframe></p>
<p>If you are interested in magic tricks and Möbius strips, then you can read my ebook on the Afghan bands.</p>
<p><a rel="nofollow" href="https://magicperspectives.net/afghan-bands/" target="_blank"><img src="https://i1.wp.com/magicperspectives.net/wp-content/uploads/sites/3/2016/09/Afghan-Bands-3d.jpg?resize=281%2C353&ssl=1" alt="The Möbius Strip in Magic. A Treatise on the Afghan Bands" width="281" data-recalc-dims="1" height="353"></a></p>
<p>The post <a rel="nofollow" href="https://r.prevos.net/plotting-mobius-strip/" target="_blank">Topological Tomfoolery in R: Plotting a Möbius Strip</a> appeared first on <a rel="nofollow" href="https://r.prevos.net/" target="_blank">The Devil is in the Data</a>.</p>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://r.prevos.net/plotting-mobius-strip/"> The Devil is in the Data</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/rkk15x3UHyI" height="1"></a></div>