0

I have the coordinates of points of an empty cube just like down below:

enter image description here

What I would like to do is transform that cube to something like this:

enter image description here

There are two options:

1- Edit the initial cube's coordinates to make it spherical

2- Generate spherical cube from scratch

I couldn't think of a solution so far. How can I generate a spherical cube?

Edit - My code that generates the cube is below. It basically creates a filled cube and then subtracts the nodes on the inside. NL_sph is the final array of the coordinates of the cube surface.


s = 0.1
m = 4
v = 3

b = np.linspace(s*(m+1),s*(m+v-1),v-1)
    
xi, yi, zi = np.meshgrid(b, b, b)
    
xi = np.array([xi.flatten('F')]).T
yi = np.array([yi.flatten('F')]).T
zi = np.array([zi.flatten('F')]).T
    
NL_inc = np.around(np.hstack([xi,yi,zi]), decimals = 5)


c = np.linspace(s*(m),s*(m+v),v+1)
    
xc, yc, zc = np.meshgrid(c, c, c)
    
xc = np.array([xc.flatten('F')]).T
yc = np.array([yc.flatten('F')]).T
zc = np.array([zc.flatten('F')]).T
    
NL_sph = np.around(np.hstack([xc,yc,zc]), decimals = 5)

for i in range(np.size(NL_inc,0)):
    
    idx = np.where((NL_sph == NL_inc[i,:]).all(axis=1))[0]
    
    if len(idx) != 0:
            
        NL_sph = np.delete(NL_sph, idx, axis = 0)

  • I need to connect these points on the "spherical cube" in a square shape just like in the second image. That's why I can't use a regular sphere generated with np.meshgrid. Points need to be arranged just like in a cube but in a spherical shape. I edited the question with the code that generates my cube. @RolandDeschain – Mert Şölen Jul 14 '20 at 19:10
  • see [Reconstruct a sphere from 6 patches](https://stackoverflow.com/a/61770981/2521214) – Spektre Jul 20 '20 at 07:35

1 Answers1

1

Draw grids on the faces cube and project every point that you need radially onto the sphere. Assuming the center of the cube at the origin, transform

(x, y, z) -> (x, y, z) / √(x² + y² + z²)
  • This is exactly what I was looking for. Just a side note, I needed to divide x, y, z coordinates with some number that depends on my mesh. This is because when I only do the calculation above, the radius is always 1. I had to decrease the radius. – Mert Şölen Jul 14 '20 at 20:27
  • @MertŞölen: goes without saying. –  Jul 14 '20 at 20:30