变半径函数的三维圆柱体

2024-04-25 09:00:56 发布

您现在位置:Python中文网/ 问答频道 /正文

我想从一个随半径变化的函数中创建一个圆柱体(双曲面)。所以我有一个函数:

def f(x):
     return np.sqrt(1+(x/constant)**(2))

当然在y方向。我想要的是,这个函数旋转,看起来像一个双曲面(见图)。我创建了这些曲面图,但没有使用f(x)这样的函数。

enter image description here


Tags: 函数returndefnp半径sqrt方向曲面
2条回答

我这样做了,但不是100%正确。在x,y=0时,函数应为w0*np.sqrt公司(1) =w0=1.701。事实并非如此。你知道吗

import numpy as np
from numpy import pi, cos, sin, sqrt, outer, ones
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

fig = plt.figure(figsize=(10, 10))
ax = fig.add_subplot(111, projection='3d')
u = np.linspace(0, 2 * pi, 100)
v = np.linspace(0, pi, 100)
one_v = ones(100)

w0=1.701
lamb=0.90846
d_in1=45
foc1=38.35
zR=np.pi*w0**(2)/(lamb)


x=np.linspace(-30,30,100)
def f(x):
    return w0*np.sqrt(1+(x/zR)**(2))

# Hyperboloid
v = 2*v/pi - 1
x3 = 6 * outer(cos(u), sqrt(1 + v**2))
y3 = 6 * outer(sin(u), sqrt(1 + v**2)) 
z3 = f(x)
ax.plot_surface(x3, y3, z3, rstride=5, cstride=5, cmap='Spectral',
                linewidth=0.5)

# Fix aspect ratio and axes details
#ax.set_xlim(-13, 13)
#ax.set_ylim(-13, 13)
#ax.set_zlim(-13, 13)
#ax.view_init(elev=35, azim=-45)
#plt.axis('off')
plt.savefig('Gaussian curvature.svg', transparent=True)
plt.show()

我从维基百科上得到这个脚本:

from __future__ import division
import numpy as np
from numpy import pi, cos, sin, sqrt, outer, ones
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

fig = plt.figure(figsize=(10, 10))
ax = fig.add_subplot(111, projection='3d')
u = np.linspace(0, 2 * pi, 100)
v = np.linspace(0, pi, 100)
one_v = ones(100)


# Hyperboloid
v = 2*v/pi - 1
x3 = 6 * outer(cos(u), sqrt(1 + v**2))
y3 = 6 * outer(sin(u), sqrt(1 + v**2)) - 16
z3 = 12 * outer(one_v, v)
ax.plot_surface(x3, y3, z3, rstride=5, cstride=5, cmap='Spectral',
                linewidth=0.5)

# Fix aspect ratio and axes details
ax.set_xlim(-13, 13)
ax.set_ylim(-13, 13)
ax.set_zlim(-13, 13)
ax.view_init(elev=35, azim=-45)
plt.axis('off')
plt.savefig('Gaussian curvature.svg', transparent=True)
plt.show()

但我不知道,如何实现我的功能。我想要我的功能和旋转。你知道吗

相关问题 更多 >