1

I'm trying to get an arc from a circle that is tangent to Z axis, as shown in the figure below, using matplotlib.

enter image description here

enter image description here

I just want an arc that is covered by yellow rectangle. Below is the code to get a circle.

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

I would appreciate it if you could provide the following information,

  1. How can I get the arc?
  2. How can I change the angle of arc, that is tangent to Z-axis, on X-Y plane?
Higa
  • 85
  • 1
  • 1
  • 6

1 Answers1

0

To have the arc/circle in the YZ plane as shown, the equation is quite simple:

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

A solution of this equation is:

where spans to have the full circle.

You can then simply restrict the domain of 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

To change the angle or the arc, there are several ways. The more straightforward to my opinion is to plot the arc of an ellipse (instead of a circle) by setting different radii for y and 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)
Loic
  • 46
  • 3