1

我正在尝试使用 matplotlib 从与Z轴相切的圆中获取圆弧,如下图所示。

在此处输入图像描述

在此处输入图像描述

我只想要一个被黄色矩形覆盖的弧线。下面是获取圆圈的代码。

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()

如果您能提供以下信息,我将不胜感激,

  1. 我怎样才能得到弧线?
  2. 如何在XY平面上更改与Z轴相切的圆弧角度?
4

1 回答 1

0

要使 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)
于 2019-07-04T14:55:26.960 回答