## 2019年9月3日火曜日

### 数学 - Python - デッサン教室 ― 回転面(トーラス(torus)) - 三角関数(正弦、余弦)、リングトーラス、ホーントーラス、スピンドルトーラス(自己交差)、球体

デッサン環境

コード

Python 3

```#!/usr/bin/env python3
from sympy import symbols, cos, sin, pi
from sympy.plotting import plot3d_parametric_surface

u, v = symbols('u, v')
u_interval = (u, 0, 2 * pi)
v_interval = (v, 0, 2 * pi)

x = (3 + cos(u)) * cos(v)
y = (3 + cos(u)) * sin(v)
z = sin(u)

p = plot3d_parametric_surface(x, y, z, u_interval, v_interval, show=False)
p.xlabel = 'x'
p.ylabel = 'y'

print(p)
p.save('torus.png')

for i, r in enumerate([0.5, 0, 1, 1.5]):
x = (r + cos(u)) * cos(v)
y = (r + cos(u)) * sin(v)
z = sin(u)
p = plot3d_parametric_surface(x, y, z, u_interval, v_interval, show=False,
title=f'r = 1, R = {r}')
p.xlabel = 'x'
p.ylabel = 'y'
print(p)
p.save(f'sample4_{i}.png')

p.show()
```

```C:\Users\...>py sample4.py
Plot object containing:
[0]: parametric cartesian surface: ((cos(u) + 3)*cos(v), (cos(u) + 3)*sin(v), sin(u)) for u over (0.0, 6.283185307179586) and v over (0.0, 6.283185307179586)
Plot object containing:
[0]: parametric cartesian surface: ((cos(u) + 0.5)*cos(v), (cos(u) + 0.5)*sin(v), sin(u)) for u over (0.0, 6.283185307179586) and v over (0.0, 6.283185307179586)
Plot object containing:
[0]: parametric cartesian surface: (cos(u)*cos(v), sin(v)*cos(u), sin(u)) for u over (0.0, 6.283185307179586) and v over (0.0, 6.283185307179586)
Plot object containing:
[0]: parametric cartesian surface: ((cos(u) + 1)*cos(v), (cos(u) + 1)*sin(v), sin(u)) for u over (0.0, 6.283185307179586) and v over (0.0, 6.283185307179586)
Plot object containing:
[0]: parametric cartesian surface: ((cos(u) + 1.5)*cos(v), (cos(u) + 1.5)*sin(v), sin(u)) for u over (0.0, 6.283185307179586) and v over (0.0, 6.283185307179586)

C:\Users\...>
```

デッサン。x軸とy軸の向きについては本書と違う、慣れてる座標の方向で記述。