为什么我在球上的圆变成八字形?

问题描述 投票:1回答:1

这是我所拥有的此问题的标题的代码。我已经手工得出了代码背后的公式,因此似乎没有错...

from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
import random as rdm

resol = 30
resolcirc = 15
r=1

########## THE SPHERE ##########
phi = np.linspace(0, np.pi*((resol-1)/resol), resol)
theta = np.linspace(0, 2*np.pi*((resol*2-1)/resol*2), resol*2)
phi, theta = np.meshgrid(phi, theta)

x = r * np.sin(phi) * np.cos(theta)
y = r * np.sin(phi) * np.sin(theta)
z = r * np.cos(phi)    

########## THE RANDOM POINT ##########
r1=1

randphi = rdm.random()*np.pi 
randtheta = rdm.random()*2*np.pi

x1 = r1 * np.sin(randphi) * np.cos(randtheta)
y2 = r1 * np.sin(randphi) * np.sin(randtheta)
z3 = r1 * np.cos(randphi) 

radpoint = 0.5

########## THE RANDOM CIRCLE ##########
rcirc=0.2
gamma = np.linspace(0, 2*np.pi*((resol-1)/resol), resol)

rotanglephi = -1 * rcirc * np.cos(gamma) 
rotangletheta = rcirc * np.sin(gamma)

psitheta=2*np.sin(-1*rcirc*np.cos(gamma)/r)
psiphi=2*np.sin(rcirc*np.sin(gamma)/r)

x1 = r1 * np.sin(randphi+psiphi) * np.cos(randtheta+psitheta)
y2 = r1 * np.sin(randphi+psiphi) * np.sin(randtheta+psitheta)
z3 = r1 * np.cos(randphi+psiphi) 

########## THE PLOT ###########
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter(x, y, z, c='y', marker='.')
ax.scatter(x1,y2,z3, c='r', marker = 'x',s=50)

plt.tight_layout()
#plt.axis('off')

plt.show()

通常,它完全可以按预期工作,例如:enter image description here

但是,我无法终生解决为什么它在球体顶部和底部给我这种时髦的行为的原因:enter image description here

这是此代码的绝对第一步,我需要在该点上创建一个点,并在该点周围做一个环,该环将在此球面上沿轨道运动。非常感谢您的帮助!

python numpy matplotlib plot angle
1个回答
0
投票

您的解决方案似乎没有定义一个圆,这取决于您的theta / phi

查看带有值的图形,为

randphi = np.pi / 8 randtheta = -np.pi / 4

我建议将您的圆定义为平面与球体here的交点>

© www.soinside.com 2019 - 2024. All rights reserved.