gpt4 book ai didi

python - 绘制椭圆体

转载 作者:行者123 更新时间:2023-11-28 22:35:59 27 4
gpt4 key购买 nike

我有三个数字代表长度。每个数字都是对象在 x、y 和 z 轴上的长度。我要表示的对象(可能)是一个变形的球体。

如何通过指定这 3 个长度来 3D 绘制此对象?

我想从这里开始:

enter image description here

例如这样的事情(我只是放大了图片):

enter image description here

我尝试使用以下代码(来自 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')

但我无法达到我想要的。你能帮我一下吗?

最佳答案

  1. 您应该为 xyz 坐标使用不同的半径
  2. 要实际查看效果,请使用 ax.set_aspect(1.0) 否则绘图 View 将缩小为球体
  3. (要使椭圆体不与轴对齐/以零为中心:在 xyz 上使用旋转和/或平移)

关于python - 绘制椭圆体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37812525/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com