diff --git a/engine/ext_make3dgrains.go b/engine/ext_make3dgrains.go index 0d8d8961f..d81a4c29f 100644 --- a/engine/ext_make3dgrains.go +++ b/engine/ext_make3dgrains.go @@ -26,18 +26,19 @@ type tesselation3d struct { maxRegion int rnd *rand.Rand startRegion int - shape Shape //Shape of the tesselated region - centers []center3d //List of Voronoi centers + shape Shape //Shape of the tesselated region + centers []center3d //List of Voronoi centers } + // Stores location of each Voronoi center type center3d struct { - x, y, z float64 // center position (m) - region byte // region for all cells near center + x, y, z float64 // center position (m) + region byte // region for all cells near center } // Stores location of each cell -type cellLocs struct{ x, y, z float64 } +type cellLocs struct {x, y, z float64} // nRegion exclusive func newTesselation3d(grainsize float64, nRegion int, seed int64, startRegion int, inputShape Shape) *tesselation3d { @@ -63,25 +64,26 @@ func shuffleCells(src []cellLocs) []cellLocs { return dest } + func (t *tesselation3d) makeRandomCenters() { //Make a list of all the cells in the shape. cells := t.tabulateCells() cells = shuffleCells(cells) //Choose number of grains to make. Assume volume of grain is given by (4/3)*pi*r^3 - shapeVolume := cellVolume() * float64(len(cells)) - grainVolume := (float64(1) / 6) * math.Pi * t.grainsize * t.grainsize * t.grainsize - nAvgGrains := shapeVolume / grainVolume + shapeVolume := cellVolume()*float64(len(cells)) + grainVolume := (float64(1)/6)*math.Pi*t.grainsize*t.grainsize*t.grainsize + nAvgGrains := shapeVolume/grainVolume nGrains := t.truncNorm(nAvgGrains) //TODO: same cell can be chosen twice by random chance t.centers = make([]center3d, nGrains) - for p := 0; p < nGrains; p++ { + for p := 0; p