The family of meshgrid script functions (meshgridx, meshgridy, meshgrid3dx, meshgrid3dy, meshgrid3dz, meshgrid4d) can be very useful when you want to create arrays that contain information associated with each mesh point in a grid. For instance, meshgridx allows you to create a 2D array with the x coordinates of a grid. You can use arrays created with the meshscript functions to quickly calculate functions defined over each point in the grid.
The attached script [sphere_meshgrid3D.lsf (1.1 KB)] shows how to use meshgrid3dx, meshgrid3dy and meshgrid3dz, combined with find, to identify the points in a mesh inside a sphere very easily. The idea is to create arrays X, Y and Z with the coordinates of the points in the mesh and use them to calculate the distance to the center of the sphere; then, the find command provides the indices of the grid points inside the sphere. These operations are done without a single “for” loop in the script! The script also shows how to access the coordinates from the indices returned by find and use them, for example, to draw small cubes centered at the mesh points.