我试图从一个与Z轴相切的圆上得到一个弧线,如下图所示,使用matplotlib。


我只想要一个被黄色长方形覆盖的弧线。下面是得到一个圆的代码。
import matplotlib as mpl
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
r = input('Enter the radius: ')
d = 2*r
theta = np.linspace(0, 2 * np.pi, 201)
y = d*np.cos(theta)
z = d*np.sin(theta)
for i in range(1):
phi = i*np.pi
ax.plot(y*np.sin(phi)+d*np.sin(phi),
y*np.cos(phi)+d*np.cos(phi), z)
ax.plot((0,0),(0,0), (-d,d), '-r', label='z-axis')
ax.set_xlabel('X-Axis')
ax.set_ylabel('Y-Axis')
ax.set_zlabel('Z-Axis')
ax.legend()
plt.show()如果你能提供以下信息,我将不胜感激,
发布于 2019-07-04 14:55:26
如图所示,要在YZ平面上有弧/圆,方程非常简单:

其中y0和z0是圆的中心,R是半径。
这个方程的一个解是:

哪里

跨度

有一个完整的圆圈。
然后,您可以简单地限制

只有一个弧线而不是一个圆:
import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
r = 5.
y0 = r # To have the tangent at y=0
z0 = 0.
# Theta varies only between pi/2 and 3pi/2. to have a half-circle
theta = np.linspace(np.pi/2., 3*np.pi/2., 201)
x = np.zeros_like(theta) # x=0
y = r*np.cos(theta) + y0 # y - y0 = r*cos(theta)
z = r*np.sin(theta) + z0 # z - z0 = r*sin(theta)
ax.plot(x, y, z)
ax.plot((0, 0), (0, 0), (-r, r), '-r', label='z-axis')
ax.set_xlabel('X-Axis')
ax.set_ylabel('Y-Axis')
ax.set_zlabel('Z-Axis')
ax.legend()
plt.show()

要改变角度或弧,有几种方法。我认为更直接的方法是通过为y和z设置不同的半径来绘制椭圆(而不是圆)的弧度:
x = np.zeros_like(theta) # x=0
y = a*np.cos(theta) + y0 # y - y0 = a*cos(theta)
z = b*np.sin(theta) + z0 # z - z0 = b*sin(theta)https://stackoverflow.com/questions/56888248
复制相似问题