0
r = 18 
h = 1.7
num_of_steps = 1000
emp = 3
time = np.arange(0, 100, 1)
phi = []
theta = []
Amp = np.pi/8
fphi = 4
ftheta = 2
pics = []

for j in time:
kampas = np.radians(2*np.pi*fphi*j)
kitaskampas = Amp*(np.sin(np.radians(2*np.pi*ftheta*j)))
phi.append(kampas)
theta.append(kitaskampas)
#this loop creates two lists of angles theta and phi in time

x = r * np.cos(phi)
y = r * np.sin(phi) * np.cos(theta) - h * np.sin(theta)
z = r * np.sin(phi) * np.sin(theta) + h * np.cos(theta)
#calculating lists of x, y and z coordinates
points = [x, y, z]
points = np.transpose(points)

#adding the x, y and z coordinates into a list and transposing it so that 
#while iterating through it, i would get x, y and z

n = len(points)

# Calculate the first and second derivative of the 
points
dX = np.apply_along_axis(np.gradient, axis=0, 
arr=points)
ddX = np.apply_along_axis(np.gradient, axis=0, arr=dX)

# Normalize all tangents
f = lambda m: m / np.linalg.norm(m)
T = np.apply_along_axis(f, axis=1, arr=dX)

# Calculate and normalize all binormals
B = np.cross(dX, ddX)
B = np.apply_along_axis(f, axis=1, arr=B)

# Calculate all normals
N = np.cross(B, T)

for t in range(len(theta)):
    fig = plt.figure('Parametrinai blynai')
    ax = fig.add_subplot(111, projection='3d')
    ax.clear()
    ax.plot(x[1:t], y[1:t], z[1:t], '-r', linewidth=3)
    ax.azim = 0
    ax.dist = 10
    ax.elev = 25
    #plotting the frame and the point at each index and setting the view of the plot
    ax.set_xlabel('X', fontweight='bold', fontsize=14)
    ax.set_ylabel('Y', fontweight='bold', fontsize=14)
    ax.set_zlabel('Z', fontweight='bold', fontsize=14)
    ax.set_xlim([-20, 20])
    ax.set_ylim([-20, 20])
    ax.set_zlim([-10, 10])
    plt.title('Parametrinis blynas', fontweight='bold', fontsize=16)

    ax.quiver(x[t - 1], y[t - 1], z[t - 1], emp * T[t, 0], emp * T[t, 1], emp * T[t, 2], color='r')#raudona
    ax.quiver(x[t - 1], y[t - 1], z[t - 1], emp * B[t, 0], emp * B[t, 1], emp * B[t, 2], color='b')#melyna
    ax.quiver(x[t - 1], y[t - 1], z[t - 1], emp * N[t, 0], emp * N[t, 1], emp * N[t, 2], color='g')#zalia
    #plotting the three little coordinate axes that follow the point

I have this code that produces a point, following a trajectory and three coordinate axes that follow that point and rotate accordingly to the "points" matrix. I am trying to incorporate this code:

point  = np.array([1, 2, 3])
normal = np.array([1, 1, 2])

# a plane is a*x+b*y+c*z+d=0
# [a,b,c] is the normal. Thus, we have to calculate
# d and we're set
d = -point.dot(normal)
x = np.linspace(0, 5, 20)
y = np.linspace(0, 5, 20)

# create x,y
xx, yy = np.meshgrid(range(5), range(5))
print(yy)

#print(yy)
# calculate corresponding z
z = (-normal[0] * xx - normal[1] * yy - d) * 1. /normal[2]

# plot the surface
plt3d = plt.figure().gca(projection='3d')
plt3d.plot_surface(xx, yy, z)
plt.show()

to plot a circle, perpendicular to the blue coordinate line on top of the original plot. In the perfect scenario that circle also tilts according to the movement of the point a.k.a. according to angle theta and variable h. Any ideas on how to make this work? All my attempts have been too far off.

  • For the record, this is the third question this week about how to plot a circle in python. If you're a student, it's likely the other two askers are also students from your school. – Stef Nov 26 '22 at 09:28
  • See for instance [Draw a circle with a specified tilt angle in three-dimensional space with Python](https://stackoverflow.com/questions/74444030/draw-a-circle-with-a-specified-tilt-angle-in-three-dimensional-space-with-python/74444329#74444329) – Stef Nov 26 '22 at 09:32
  • 1
    Also, I think you're more likely to get a helpful answer if you describe your problem in detail and with pictures, especially since this is a geometry problem; than if you just show a long piece of code with almost no explanations. When including code in a question, it's good to make this code "minimal", so that people who read your question can focus on answering the question, as opposed to waste time trying to understand your code. – Stef Nov 26 '22 at 09:33

0 Answers0