Как я могу получить дугу из 3D круга в Matplotlib? - PullRequest
0 голосов
/ 04 июля 2019

Я пытаюсь получить дугу от окружности, которая касается оси Z , как показано на рисунке ниже, используя matplotlib.

enter image description here

enter image description here

Я просто хочу, чтобы дуга была покрыта желтым прямоугольником.Ниже приведен код для получения круга.

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. Как изменить угол дуги, который касается оси Z , на плоскости XY ?

1 Ответ

0 голосов
/ 04 июля 2019

Чтобы иметь дугу / окружность в плоскости YZ, как показано, уравнение довольно простое:

image

where y0 and z0 are the center of the circle and R the radius.

A solution of this equation is:

image

where image spans imageto have the full circle.

You can then simply restrict the domain of image to have only an arc and not a circle:

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

circle

Чтобы изменить угол или дугу, есть несколько способов. Более простым, на мой взгляд, является построение дуги эллипса (вместо круга) путем установки различных радиусов для 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)
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...