Skip to main content
added 1 characters in body
Source Link
Dr. belisarius
  • 116.8k
  • 13
  • 208
  • 466

Here is a simplistic one:

ClearAll[gridReconstruct]; gridReconstruct[unstructuredGrid_List] := Tuples[Range[Min[#], Max[#], First@Sort@Differences@Union@#] & /@ Transpose[unstructuredGrid] ] 

It just determines the minimal step along each direction, as well as maximal and minimal coordinate value, and constructs a grid based on that. Should work in any number of dimensions.

As an example, I cnstructconstruct a simple 2D grid and delete 5 random points from it:

grid = Flatten[Outer[List, Range[-1, 1, 0.5], Range[-1, 1, 0.5]], 1]; unstgrid = Delete[grid, Transpose[{RandomSample[Range[Length[grid]], 5]}]] (* {{-1., -0.5}, {-1., 0.}, {-1., 0.5}, {-1., 1.}, {-0.5, 0.}, {-0.5, 0.5}, {0., -1.}, {0., -0.5}, {0., 0.}, {0., 0.5}, {0.,1.}, {0.5, -1.}, {0.5, -0.5}, {0.5, 0.}, {0.5, 0.5}, {1., -1.}, {1., -0.5}, {1., 0.}, {1., 0.5}, {1., 1.}} *) 

Now, call gridReconstruct

gridReconstruct[unstgrid] == grid 

True

This is, of course, a very simplistic approach.

Here is a simplistic one:

ClearAll[gridReconstruct]; gridReconstruct[unstructuredGrid_List] := Tuples[Range[Min[#], Max[#], First@Sort@Differences@Union@#] & /@ Transpose[unstructuredGrid] ] 

It just determines the minimal step along each direction, as well as maximal and minimal coordinate value, and constructs a grid based on that. Should work in any number of dimensions.

As an example, I cnstruct a simple 2D grid and delete 5 random points from it:

grid = Flatten[Outer[List, Range[-1, 1, 0.5], Range[-1, 1, 0.5]], 1]; unstgrid = Delete[grid, Transpose[{RandomSample[Range[Length[grid]], 5]}]] (* {{-1., -0.5}, {-1., 0.}, {-1., 0.5}, {-1., 1.}, {-0.5, 0.}, {-0.5, 0.5}, {0., -1.}, {0., -0.5}, {0., 0.}, {0., 0.5}, {0.,1.}, {0.5, -1.}, {0.5, -0.5}, {0.5, 0.}, {0.5, 0.5}, {1., -1.}, {1., -0.5}, {1., 0.}, {1., 0.5}, {1., 1.}} *) 

Now, call gridReconstruct

gridReconstruct[unstgrid] == grid 

True

This is, of course, a very simplistic approach.

Here is a simplistic one:

ClearAll[gridReconstruct]; gridReconstruct[unstructuredGrid_List] := Tuples[Range[Min[#], Max[#], First@Sort@Differences@Union@#] & /@ Transpose[unstructuredGrid] ] 

It just determines the minimal step along each direction, as well as maximal and minimal coordinate value, and constructs a grid based on that. Should work in any number of dimensions.

As an example, I construct a simple 2D grid and delete 5 random points from it:

grid = Flatten[Outer[List, Range[-1, 1, 0.5], Range[-1, 1, 0.5]], 1]; unstgrid = Delete[grid, Transpose[{RandomSample[Range[Length[grid]], 5]}]] (* {{-1., -0.5}, {-1., 0.}, {-1., 0.5}, {-1., 1.}, {-0.5, 0.}, {-0.5, 0.5}, {0., -1.}, {0., -0.5}, {0., 0.}, {0., 0.5}, {0.,1.}, {0.5, -1.}, {0.5, -0.5}, {0.5, 0.}, {0.5, 0.5}, {1., -1.}, {1., -0.5}, {1., 0.}, {1., 0.5}, {1., 1.}} *) 

Now, call gridReconstruct

gridReconstruct[unstgrid] == grid 

True

This is, of course, a very simplistic approach.

Source Link
Leonid Shifrin
  • 115.8k
  • 16
  • 341
  • 435

Here is a simplistic one:

ClearAll[gridReconstruct]; gridReconstruct[unstructuredGrid_List] := Tuples[Range[Min[#], Max[#], First@Sort@Differences@Union@#] & /@ Transpose[unstructuredGrid] ] 

It just determines the minimal step along each direction, as well as maximal and minimal coordinate value, and constructs a grid based on that. Should work in any number of dimensions.

As an example, I cnstruct a simple 2D grid and delete 5 random points from it:

grid = Flatten[Outer[List, Range[-1, 1, 0.5], Range[-1, 1, 0.5]], 1]; unstgrid = Delete[grid, Transpose[{RandomSample[Range[Length[grid]], 5]}]] (* {{-1., -0.5}, {-1., 0.}, {-1., 0.5}, {-1., 1.}, {-0.5, 0.}, {-0.5, 0.5}, {0., -1.}, {0., -0.5}, {0., 0.}, {0., 0.5}, {0.,1.}, {0.5, -1.}, {0.5, -0.5}, {0.5, 0.}, {0.5, 0.5}, {1., -1.}, {1., -0.5}, {1., 0.}, {1., 0.5}, {1., 1.}} *) 

Now, call gridReconstruct

gridReconstruct[unstgrid] == grid 

True

This is, of course, a very simplistic approach.