2019年9月3日火曜日

開発環境

デッサン環境

数学デッサン教室 ― 描いて楽しむ数学のかたち (瑞慶山 香佳(著)、技術評論社)の1章(数学とかたち)、1(回転体)の1(回転面(トーラス(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()

入出力結果(Bash、cmd.exe(コマンドプロンプト)、Terminal、Jupyter(IPython))

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軸の向きについては本書と違う、慣れてる座標の方向で記述。

0 コメント:

コメントを投稿