我有三个代表长度的数字。每个数字是对象在x、y和z轴上的长度。我要表示的对象可能是一个变形的球体。
如何通过指定这3个长度来三维打印此对象?
我想从这个开始:
举个例子(我只是放大了图片):
我试着用下面的代码(从Ellipsoid creation in Python)来解释一下x、y和z的定义:
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
phi = np.linspace(0,2*np.pi, 256).reshape(256, 1) # the angle of the projection in the xy-plane
theta = np.linspace(0, np.pi, 256).reshape(-1, 256) # the angle from the polar axis, ie the polar angle
radius = 4
# Transformation formulae for a spherical coordinate system.
x = radius*np.sin(theta)*np.cos(phi)
y = radius*np.sin(theta)*np.sin(phi)
z = radius*np.cos(theta)
fig = plt.figure(figsize=plt.figaspect(1)) # Square figure
ax = fig.add_subplot(111, projection='3d')
ax.plot_surface(x, y, z, color='b')
但我达不到我想要的。你能帮我一下吗?
最佳答案
您应该为x
、y
和z
坐标使用不同的半径
若要实际看到效果,请使用ax.set_aspect(1.0)
,否则绘图视图将缩小到球体
(使椭球不是轴对齐/零中心:使用旋转和/或翻译在x
,y
和z
)
关于python - 绘制椭球,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37812525/