# Plotting a Torus    

To plot a surface in 3D do you first need to find the 
parametrization of the surface you wish to plot. 

For a Torus the parametrization looks like this:
\begin{align}
x &= [c + a  \cos v] \cos u \\
y &= [c + a  \cos v] \sin u \\
z &= a \sin v
\end{align}


where $a$ represents the radius of the tube and $c$ is the radius of the 
center hole of the torus tube. See https://mathworld.wolfram.com/Torus.html for further information.



Begin by activating matplotlib notebook and importing numpy and 
matplotlib


```python
%matplotlib notebook 
# This enables you to drag and rotate the figure

from mpl_toolkits.mplot3d import Axes3D # needed to do the 3D Plots
import numpy as np
import matplotlib.pyplot as plt
```


```python
fig = plt.figure()
ax = fig.gca(projection='3d')

u = np.linspace(0, 2*np.pi, 100)
v = np.linspace(0, 2*np.pi, 100)
u, v = np.meshgrid(u, v) # Make coordinate matrices from coordinate vectors.
a, c = 0.2, 1.0 # Set a and c from the torus parametrization

# Paramatrization
x = (c + a*np.cos(v))*np.cos(u)
y = (c + a*np.cos(v))*np.sin(u)
z = a*np.sin(v)


ax.plot_surface(x, y, z)

ax.set_xlim3d(-1, 1)
ax.set_ylim3d(-1, 1)
ax.set_zlim3d(-1, 1)
plt.show()
```

# Make a surface plot of a sphere

Plot a sphere the parametrization is:

\begin{align}
x &= r \cos \theta \sin \phi  \\
y &= r \sin \theta \sin \phi  \\
z &= r \cos \phi 
\end{align}

where $\theta$ is the loggitude coorinate running from $0$ to $2\pi$, 
$\phi$ is the colatitude coordinate running from $0$ to $\pi$ and $r$ is the radius.


```python
fig = plt.figure()
ax = fig.gca(projection='3d')

# Fill inn the rest
```

# Make a surface plot of a Mobius strip

The parametrization is:
\begin{align}
x &= \left(1 + \frac{v}{2}\cos \frac{u}{2} \right)\cos u  \\
y &= \left(1 + \frac{v}{2}\cos v \right)\sin u  \\
z &= \frac{v}{2}\sin \frac{u}{2} 
\end{align}

where $u$ is running from $0$ to $2\pi$ and $v$ is running from $-1$ to $1$.


```python
fig = plt.figure()
ax = fig.gca(projection='3d')

# Fill inn the rest

```


```python

```

3a3607ace5a95e7e7d1446c13857f2a4f8fd92a7
ipynb
Jupyter Notebook
problem_candidates/Plotting surfacees.ipynb
KJE2001/seminars
b42c5c0a945795f6f625db35cafefa6662e5ce7e
MIT
2017-02-04T01:34:33.000Z
2021-06-12T12:27:37.000Z
problem_candidates/Plotting surfacees.ipynb
KJE2001/seminars
b42c5c0a945795f6f625db35cafefa6662e5ce7e
MIT
2020-03-30T11:00:35.000Z
2020-05-12T05:42:24.000Z
problem_candidates/Plotting surfacees.ipynb
KJE2001/seminars
b42c5c0a945795f6f625db35cafefa6662e5ce7e
MIT
2016-04-26T20:42:43.000Z
2022-02-06T11:12:57.000Z
Qwen/Qwen-72B
1. YES
2. YES