问题
I have the coordinates of points of an empty cube just like down below:
What I would like to do is transform that cube to something like this:
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)
回答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²)
回答2:
Probably one of the most popular solutions to this problem is the Catmull-Clark Subdivision Surface Algorithm which is evulated recursively.
However, that this algorithm "does not approach an actual sphere as a sphere is quadric." Regardless, this algorithm will produce exactly what is in the image you attached. Also note: you would create a simple cube first and then deform it with subdivision, so you would start with 6 faces,
Example of 0 Degree Subdivision
and then a first degree subdivision would give you 24 faces,
Example of 1st degree subdivision
with each of the corner vertices translated towards the center to begin the spherical shape.
来源:https://stackoverflow.com/questions/62902206/transforming-cube-surface-to-spherical-cube-surface-generating-spherical-cube