Чтобы проверить единицы измерения Маджави, я пытаюсь нарисовать сферу внутри кубического прямоугольника (тонущего со скелетом его краев) как изоповерхность гауссовой функции.Я бы хотел, чтобы сфера была в центре.
В следующем коде я пытаюсь использовать кубическое поле с одним ребром в (0,0,0), противоположным в (4.0,4.0,4.0) и его ребрами, параллельными осям.Сфера должна иметь свой центр в (2.0,2.0,2.0).
Следующий код создает сферу и каркас коробки, но, похоже, он не центрирован точно, поэтому я думаю, что путаю единицы quiver3d и contour3d.Любая помощь для исправления?
import numpy as np
from mayavi import mlab
def sphere_cent(x,y,z,x0,y0,z0):
sigma=1.0
value=np.exp((-(x-x0)**2-(y-y0)**2-(z-z0)**2)/(2.0*sigma**2))
return value
def test_sphere(n,dx):
scalars=np.zeros((n,n,n))
x0=((n-1)*dx)/2.0
y0=((n-1)*dx)/2.0
z0=((n-1)*dx)/2.0
for i in range(n):
for j in range(n):
for k in range(n):
x=(i)*dx
y=(j)*dx
z=(k)*dx
scalars[i,j,k]=sphere_cent(x,y,z,x0,y0,z0)
obj = mlab.contour3d(scalars, contours=[0.5], transparent=True)
return obj
n=41
dx=0.1
_ = test_sphere(n,dx)
d=n-1
r=0.02
cyls_1 = mlab.quiver3d(0,0,0,0,0,d,mode='cylinder',scale_factor=1.0)
cyls_2 = mlab.quiver3d(0,d,0,0,0,d, mode='cylinder', scale_factor=1.0)
cyls_3 = mlab.quiver3d(d,0,0,0,0,d, mode='cylinder',scale_factor=1.0)
cyls_4 = mlab.quiver3d(d,d,0,0,0,d,mode='cylinder',scale_factor=1.0)
cyls_5 = mlab.quiver3d(0,0,0,0,d,0, mode='cylinder', scale_factor=1.0)
cyls_6 = mlab.quiver3d(d,0,0,0,d,0, mode='cylinder',scale_factor=1.0)
cyls_7 = mlab.quiver3d(0,0,d,0,d,0,mode='cylinder',scale_factor=1.0)
cyls_8 = mlab.quiver3d(d,0,d,0,d,0, mode='cylinder', scale_factor=1.0)
cyls_9 = mlab.quiver3d(0,0,0,d,0,0, mode='cylinder',scale_factor=1.0)
cyls_10 = mlab.quiver3d(0,d,0,d,0,0,mode='cylinder',scale_factor=1.0)
cyls_11 = mlab.quiver3d(0,0,d,d,0,0, mode='cylinder', scale_factor=1.0)
cyls_12 = mlab.quiver3d(0,d,d,d,0,0, mode='cylinder',scale_factor=1.0)
cyls_1.glyph.glyph_source.glyph_source.radius = r
cyls_2.glyph.glyph_source.glyph_source.radius = r
cyls_3.glyph.glyph_source.glyph_source.radius = r
cyls_4.glyph.glyph_source.glyph_source.radius = r
cyls_5.glyph.glyph_source.glyph_source.radius = r
cyls_6.glyph.glyph_source.glyph_source.radius = r
cyls_7.glyph.glyph_source.glyph_source.radius = r
cyls_8.glyph.glyph_source.glyph_source.radius = r
cyls_9.glyph.glyph_source.glyph_source.radius = r
cyls_10.glyph.glyph_source.glyph_source.radius = r
cyls_11.glyph.glyph_source.glyph_source.radius = r
cyls_12.glyph.glyph_source.glyph_source.radius = r
mlab.show()
ОБНОВЛЕНИЕ: мне удалось получить сферу с центром в этой магистрали:
st=1
cyls_1 = mlab.quiver3d(st,st,st,0,0,d,mode='cylinder',scale_factor=1.0)
cyls_2 = mlab.quiver3d(st,d+st,st,0,0,d, mode='cylinder', scale_factor=1.0)
cyls_3 = mlab.quiver3d(d+st,st,st,0,0,d, mode='cylinder',scale_factor=1.0)
cyls_4 = mlab.quiver3d(d+st,d+st,st,0,0,d,mode='cylinder',scale_factor=1.0)
cyls_5 = mlab.quiver3d(st,st,st,0,d,0, mode='cylinder', scale_factor=1.0)
cyls_6 = mlab.quiver3d(d+st,st,st,0,d,0, mode='cylinder',scale_factor=1.0)
cyls_7 = mlab.quiver3d(st,st,d+st,0,d,0,mode='cylinder',scale_factor=1.0)
cyls_8 = mlab.quiver3d(d+st,st,d+st,0,d,0, mode='cylinder', scale_factor=1.0)
cyls_9 = mlab.quiver3d(st,st,st,d,0,0, mode='cylinder',scale_factor=1.0)
cyls_10 = mlab.quiver3d(st,d+st,st,d,0,0,mode='cylinder',scale_factor=1.0)
cyls_11 = mlab.quiver3d(st,st,d+st,d,0,0, mode='cylinder', scale_factor=1.0)
cyls_12 = mlab.quiver3d(st,d+st,d+st,d,0,0, mode='cylinder',scale_factor=1.0)
, но это было в основном методом проб и ошибок, и я не понимал, почемуМне пришлось перенести происхождение quiver3d.Похоже, что происхождение для quiver3d и contour3d не совпадают?