Python Matplotlib 3D line passing through the surface

I use mapping to transform points on the surface of a cube into a sphere.

I want to build the surface of the resulting sphere and lines where the faces of the cube are displayed.

So far I have tried the following, working on one face of the cube at a time:

import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D def sphere_mapping(xbar,ybar,zbar): xx = xbar**2 yy = ybar**2 zz = zbar**2 x = xbar*np.sqrt(1 - yy/2 - zz/2 + yy*zz/3) y = ybar*np.sqrt(1 - xx/2 - zz/2 + xx*zz/3) z = zbar*np.sqrt(1 - xx/2 - yy/2 + xx*yy/3) return x,y,z fig = plt.figure() ax = fig.add_subplot(111,projection='3d',aspect='equal') sgrd1,sgrd2 = np.meshgrid(np.linspace(-1,1,100),np.linspace(-1,1,100)) sgrd3 = np.ones((100,100)) lgrd1 = np.hstack([np.linspace(-1,1,100),np.ones(100,),np.linspace(1,-1,100),-np.ones(100,)]) lgrd2 = np.hstack([np.ones(100,),np.linspace(1,-1,100),-np.ones(100,),np.linspace(-1,1,100)]) lgrd3 = np.ones(400,) # Plot surface # x=+1 x,y,z=transform(fgrd3,fgrd1,fgrd2) ax.plot_surface(x,y,z,linewidth=0) # y=+1 x,y,z=transform(fgrd1,fgrd3,fgrd2) ax.plot_surface(x,y,z,linewidth=0) # x=-1 x,y,z=transform(-fgrd3,fgrd1,fgrd2) ax.plot_surface(x,y,z,linewidth=0) # y=-1 x,y,z=transform(fgrd1,-fgrd3,fgrd2) ax.plot_surface(x,y,z,linewidth=0) # z=+1 x,y,z=transform(fgrd2,fgrd1,fgrd3) ax.plot_surface(x,y,z,linewidth=0) # z=-1 x,y,z=transform(fgrd2,fgrd1,-fgrd3) ax.plot_surface(x,y,z,linewidth=0) # Plot lines # x=+1 x,y,z=transform(lgrd3,lgrd1,lgrd2) ax.plot_wireframe(x,y,z,linewidth=4,color='k') # y=+1 x,y,z=transform(lgrd1,lgrd3,lgrd2) ax.plot_wireframe(x,y,z,linewidth=4,color='k') # x=-1 x,y,z=transform(-lgrd3,lgrd1,lgrd2) ax.plot_wireframe(x,y,z,linewidth=4,color='k') # y=-1 x,y,z=transform(lgrd1,-lgrd3,lgrd2) ax.plot_wireframe(x,y,z,linewidth=4,color='k') # z=+1 x,y,z=transform(lgrd2,lgrd1,lgrd3) ax.plot_wireframe(x,y,z,linewidth=4,color='k') # z=-1 x,y,z=transform(lgrd2,lgrd1,-lgrd3) ax.plot_wireframe(x,y,z,linewidth=4,color='k') plt.show() 

This works great. I get a sphere and I get thick black lines of edges. However, the lines are displayed across the surface of the sphere. enter image description here

If you change the display so that it simply xbar,ybar,zbar , you will get the original cube and the rows displayed correctly. enter image description here

Any ideas why my lines show the scope and how to fix it?

+2
source share

Source: https://habr.com/ru/post/1014738/


All Articles