Hi all,
I have a list of co-ordinates (points on a sphere, given below) that I want to use as input to mlab.mesh. It's not, unfortunately, obvious to me how to construct the 2d arrays required for mesh's input. Can anyone enlighten me? [[ 1. , 0. , 0. ], [ 0.7071, 0.7071, 0. ], [ 0.7071, 0. , 0.7071], [ 0.7071, 0. , -0.7071], [ 0.7071, -0.7071, 0. ],
[ 0.5774, 0.5774, 0.5774], [ 0.5774, 0.5774, -0.5774], [ 0.5774, -0.5774, 0.5774], [ 0.5774, -0.5774, -0.5774], [ 0. , 1. , 0. ], [ 0. , 0.7071, 0.7071],
[ 0. , 0.7071, -0.7071], [ 0. , 0. , 1. ], [ 0. , 0. , -1. ], [ 0. , -0.7071, 0.7071], [ 0. , -0.7071, -0.7071], [ 0. , -1. , 0. ],
[-0.5774, 0.5774, 0.5774], [-0.5774, 0.5774, -0.5774], [-0.5774, -0.5774, 0.5774], [-0.5774, -0.5774, -0.5774], [-0.7071, 0.7071, 0. ], [-0.7071, 0. , 0.7071],
[-0.7071, 0. , -0.7071], [-0.7071, -0.7071, 0. ], [-1. , 0. , 0. ]] Thanks, Angus.
-- AJC McMorland Post-doctoral research fellow Neurobiology, University of Pittsburgh _______________________________________________ Enthought-Dev mailing list [hidden email] https://mail.enthought.com/mailman/listinfo/enthought-dev |
Hi Angus,
On Thu, Apr 15, 2010 at 07:13:50PM +0100, Angus McMorland wrote: > I have a list of co-ordinates (points on a sphere, given below) that I > want to use as input to mlab.mesh. It's not, unfortunately, obvious to me > how to construct the 2d arrays required for mesh's input. Can anyone > enlighten me? I cannot: I don't know how the points are connected. mlab.mesh expects points coordinnates given in a 2D array reflecting the connectivity of those points. If you have different connectivity, you might want to look at the mlab.triangular_mesh function. HTH, Ga�l _______________________________________________ Enthought-Dev mailing list [hidden email] https://mail.enthought.com/mailman/listinfo/enthought-dev |
On 15 April 2010 19:35, Gael Varoquaux <[hidden email]> wrote: -- Hi Angus, Right - I understand that connectivity is needed. Let's say suitable connectivity to make it look like a closed surface approximation of a sphere. In fact, I've horribly hacked the solution out now (code below), by generating a more regular grid and then changing the points that needed it, but I feel there must be a (much) more elegant way. -- import numpy as np def sphere(radius=1.0, npts=(100,100)): ''' Notes ----- Shamelessly borrowed from FPs test_mesh_sphere replacement
''' np_phi = npts[0]*1j np_theta = npts[1]*1j phi, theta = np.mgrid[0:2*np.pi:np_phi,0:np.pi:np_theta] x = radius * np.sin(theta) * np.cos(phi)
y = radius * np.sin(theta) * np.sin(phi) z = radius * np.cos(theta) return x, y, z sphere_pts = sphere(npts=(9,5)) sp = np.asarray(sphere_pts)
sp2 = sp.reshape(3, 9*5) wrong = np.abs(np.abs(sp2[0]) - 0.5) < 1e-8 signs = np.sign(sp2[:,wrong]) sp2[:,wrong] = signs * 1/np.sqrt(3.) x,y,z = sp sphere_mesh = mlab.mesh(x,y,z)
-- Thanks, Angus. AJC McMorland Post-doctoral research fellow Neurobiology, University of Pittsburgh _______________________________________________ Enthought-Dev mailing list [hidden email] https://mail.enthought.com/mailman/listinfo/enthought-dev |
On Thu, Apr 15, 2010 at 07:50:17PM +0100, Angus McMorland wrote:
> Right - I understand that connectivity is needed. �Let's say suitable > connectivity to make it look like a closed surface approximation of a > sphere. > In fact, I've horribly hacked the solution out now (code below), by > generating a more regular grid and then changing the points that needed > it, but I feel there must be a (much) more elegant way. -- import numpy as np def sphere(radius=1.0, npts=(100,100)): �� �''' �� �Notes �� �----- �� �Shamelessly borrowed from FPs test_mesh_sphere replacement �� �''' �� �np_phi = npts[0]*1j �� �np_theta = npts[1]*1j � � �� �phi, theta = np.mgrid[0:2*np.pi:np_phi,0:np.pi:np_theta] �� �x = radius * np.sin(theta) * np.cos(phi) �� �y = radius * np.sin(theta) * np.sin(phi) �� �z = radius * np.cos(theta) �� �return x, y, z sphere_pts = sphere(npts=(9,5)) sp = np.asarray(sphere_pts) sp2 = sp.reshape(3, 9*5) wrong = np.abs(np.abs(sp2[0]) - 0.5) < 1e-8 signs = np.sign(sp2[:,wrong]) sp2[:,wrong] = signs * 1/np.sqrt(3.) x,y,z = sp sphere_mesh = mlab.mesh(x,y,z) No, that's the way it is supposed to be used. Another option would be to build a different mesh representation of a sphere and use mlab.trianuglar_mesh for it, but it would be more work... Ga�l _______________________________________________ Enthought-Dev mailing list [hidden email] https://mail.enthought.com/mailman/listinfo/enthought-dev |
Free forum by Nabble | Edit this page |