This time, I will draw a knot in Plotly on a three-dimensional space. I hope it will help you in your studies.
You can do something like ↓.
See the Pen dyoyxKW by Sota Misawa (@mitawaut) on CodePen.
I will do the minimum necessary review to illustrate the knot.
A ** knot ** (knot) is a $ S ^ 1 $ piecewise embedded in $ S ^ 3 $. Since $ S ^ 3 $ can be regarded as $ \ mathbb {R} ^ 3 \ cup \ {\ infinty \} $, if the embedded $ S ^ 1 $ does not include $ \ infinty $, then $ \ You can think of it as $ S ^ 1 $ embedded in mathbb {R} ^ 3 $.
A well-known method of expressing knots is a knot along the two-dimensional torus surface $ \ mathbb {T} ^ 2
Using a pair of integers $ (n, \ m) $ on a closed curve on $ \ mathbb {T} ^ 2 $ (extending the domain of $ \ mathbb {T} ^ 2 $ appropriately),
Consider what is represented as. You can think of this as a knot. The following theorems are known in this regard.
** Theorem. ** For any non-trivial knot $ K $ contained in $ \ mathbb {T} ^ 2 $, there exists a relatively prime integer pair $ (n, \ m) $ for $ K. $ Is equivalent to $ T (n, \ m) $.
From this theorem, we try to illustrate $ T (n, \ m) $ as a knot expression. Below is a diagram of $ T (2, \ 3) $.
This is the beginning of cooking for 5 minutes. Since ipywidgets is used, jupyter notebook is recommended.
requirements.txt[Excerpt]
ipython==7.12.0
numpy==1.18.1
plotly==4.4.1
The goal is to be able to manipulate $ n, \ m $ with ipywidgets. First, import what you need.
# import modules
import plotly.offline as offline
import plotly.graph_objs as go
import numpy as np
from ipywidgets import interactive, VBox, widgets
from IPython.display import display
offline.init_notebook_mode(connected=True)
Then define $ \ mathbb {T} ^ 2 $ and $ T (n, \ m) $. Again, this just implements the above discussion as is.
# functions
def torus(p, t):
x = np.cos(p) * (3 + np.cos(t))
y = np.sin(p) * (3 + np.cos(t))
z = -np.sin(t)
return (x, y, z)
def knot(n, m):
theta = np.linspace(-np.pi, np.pi, 1000)
p, t = n*theta, m*theta
return torus(p, t)
All you have to do is plot. The initial value is $ (m, \ m) = (2, \ 3) $, and the slide bar range is $ n $: -10 ~ 10, $ m $: 0 ~ 10.
fig = go.FigureWidget()
scatt = fig.add_scatter3d()
def update(n=2, m=3):
with fig.batch_update():
(cx, cy, cz) = knot(n, m)
scatt.data[0].x=cx
scatt.data[0].y=cy
scatt.data[0].z=cz
scatt.data[0].mode='lines'
scatt.data[0].line=dict(
width=10,
color='green')
vb = VBox((fig, interactive(update, n=(-10, 11, 1), m=(0, 10, 1))))
display(vb)
If the following is displayed and the knot changes at the same time as you play with the slide bar, you are successful.
If you don't see it, check the version around ipython. ~~ I thought it was awkward for the first post to be of a few minutes quality, so I created an extra section called review ~~
Recommended Posts