[英]Is there a way to graph 3d points on a cylinder graph in python?
为了在圆柱体的表面上放置点,您必须对表面进行参数化。 这是一种方式:
import numpy as np
import matplotlib.pyplot as plt
def cylinder(R, z_min, z_max, theta_max, N):
z = np.random.uniform(z_min, z_max, N)
theta = np.random.uniform(0, theta_max, N)
x = R * np.cos(theta)
y = R * np.sin(theta)
return x, y, z
def dics(z, R_max, theta_max, N):
r = np.random.uniform(0, R_max, N)
theta = np.random.uniform(0, theta_max, N)
x = r * np.cos(theta)
y = r * np.sin(theta)
return x, y, z * np.ones_like(x)
def plane(theta, R_max, z_min, z_max, N):
r = np.random.uniform(0, R_max, N)
x = r * np.cos(theta)
y = r * np.sin(theta)
z = np.random.uniform(z_min, z_max, N)
return x, y, z
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1, projection="3d")
N = 1000
z_min = -1
z_max = 1
R = 3
theta_max = 1.5 * np.pi
# points on the cylindrical surface
x_cyl, y_cyl, z_cyl = cylinder(R, z_min, z_max, theta_max, N)
ax.scatter(x_cyl, y_cyl, z_cyl)
# points on the top cap
x_top, y_top, z_top = dics(z_max, R, theta_max, N)
ax.scatter(x_top, y_top, z_top)
# points on the bottom cap
x_bottom, y_bottom, z_bottom = dics(z_min, R, theta_max, N)
ax.scatter(x_bottom, y_bottom, z_bottom)
# points on the first slice-wall
x1, y1, z1 = plane(0, R, z_min, z_max, N)
ax.scatter(x1, y1, z1)
# points on the second slice-wall
x2, y2, z2 = plane(theta_max, R, z_min, z_max, N)
ax.scatter(x2, y2, z2)
plt.show()
然后,您必须修改上述函数以返回角度theta
和半径r
,这样您就可以根据 H、S、V 应用 colors,但这留给您作为练习:)
编辑:如果你只是想将 plot 散点到切片圆柱体的体积中,你可以这样修改cylinder
function:
def cylinder(R, z_min, z_max, theta_max, N):
z = np.random.uniform(z_min, z_max, N)
theta = np.random.uniform(0, theta_max, N)
r = np.random.uniform(0, R, N)
x = r * np.cos(theta)
y = r * np.sin(theta)
return x, y, z
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.