Mar-21-2024, 08:08 PM
I don't think you can do this. You have 3 shapes and you cannot just concatenate the points together to get a surface. The problem you have no way to transition gracefully from one surface to another.
Try joining just the two hemispheres to see what I mean.
You can't blame numpy and matplotlib for not being able to plot your "surface". By definition, what you are creating is not a surface at all. At best we could describe it as a piece-wise surface, but I challenge you to define a piece-wise function that will generate points on your surface.
Try joining just the two hemispheres to see what I mean.
import numpy as np import matplotlib.pyplot as plt long = 20 fig = plt.figure() ax = plt.axes(projection='3d') theta = np.linspace(0, 2*np.pi, 100) theta_1 = np.linspace(0, np.pi/2, 100) x, y = np.meshgrid(theta, theta_1) x_grid_sphere = np.cos(x)*np.sin(y) y_grid_sphere = np.sin(x)*np.sin(y) z_grid_sphere = np.cos(y)+long-1 theta_2 = np.linspace(0, np.pi/2, 100) x_bas, y_bas = np.meshgrid(theta, theta_2) x_grid_sphere_bas = np.cos(x_bas)*np.sin(y_bas) y_grid_sphere_bas = np.sin(x_bas)*np.sin(y_bas) z_grid_sphere_bas = -np.cos(y_bas)+1 test_x = np.concatenate((x_grid_sphere, x_grid_sphere_bas),axis=1) test_y = np.concatenate((y_grid_sphere, y_grid_sphere_bas),axis=1) test_z = np.concatenate((z_grid_sphere, z_grid_sphere_bas),axis=1) ax.plot_surface(test_x,test_y,test_z, color ="green", alpha=0.5) plt.show()Now change how the points are concatenated:
test_x = np.concatenate((x_grid_sphere, x_grid_sphere_bas),axis=0) test_y = np.concatenate((y_grid_sphere, y_grid_sphere_bas),axis=0) test_z = np.concatenate((z_grid_sphere, z_grid_sphere_bas),axis=0)A much different plot, but you can see how matplotlib is creating a "transition" surface to go frm one set of points to another.
You can't blame numpy and matplotlib for not being able to plot your "surface". By definition, what you are creating is not a surface at all. At best we could describe it as a piece-wise surface, but I challenge you to define a piece-wise function that will generate points on your surface.