2

so I wondered if there is a way to use histogram list such that it doesn't bin in quadrat mode, but given a set of 3D points, could bin over a tessellation of some regular tetrahedrons/hexagons/spheres?

Szabolcs
  • 234,956
  • 30
  • 623
  • 1,263
MKF
  • 591
  • 2
  • 10

3 Answers3

3
th = Tetrahedron[{{0, 0, 0}, {1, 0, 0}, {1/2, Sqrt[3]/2, 0}, {1/2, Sqrt[3]/6, Sqrt[6]/3}}];
bins = N @ NestedSymmetricSubdivision[th, 3];
centers = RegionCentroid /@ bins;
nf = Nearest[centers -> "Index"];

SeedRandom[1]
rp = RandomPoint[Cuboid[], 3000];
tF = FindGeometricTransform[th[[1]], Tetrahedron[][[1]]][[2]];
transformed = tF /@ (Normalize[#, Total[#]/Max[#] &] & /@ rp);
Row[{Graphics3D[{Blue, Point@rp, Opacity[.05], Cuboid[]}, ImageSize -> 400], 
  Graphics3D[{Red, Point@transformed, Opacity[.05], th}, 
   BoxRatios -> 1, ImageSize -> 400]}]

enter image description here

groups = GatherBy[transformed, nf[#, 1] &];
tallies = {Rescale[Length /@ groups], bins[[nf[#[[1]], 1]]] & /@ groups};
Show[Graphics3D[{FaceForm[], th, 
   Transpose[{FaceForm[Opacity[Rescale[#, {0, 1}, {0.05, .25}], Blue]]&/@#, #2}&@@tallies]},
  Boxed -> True, BoxRatios -> 1], 
 ListPointPlot3D[groups, PlotStyle -> (ColorData[{"Rainbow", "Reversed"}]/@ tallies[[1]])],
  ImageSize -> Large]

enter image description here

kglr
  • 394,356
  • 18
  • 477
  • 896
1

This isn't an answer, just a response to the previous comment

SymmetricSubdivision[Tetrahedron[pl_], k_] /; 0 <= k < 2^Length[pl] :=
  Module[{n = Length[pl] - 1, i0, bl, pos}, i0 = DigitCount[k, 2, 1];
  bl = IntegerDigits[k, 2, n];
  pos = FoldList[If[#2 == 0, #1 + {0, 1}, #1 + {1, 0}] &, {0, i0}, 
    Reverse[bl]];
  Tetrahedron@Map[Mean, Extract[pl, #] & /@ Map[{#} &, pos + 1, {2}]]]

NestedSymmetricSubdivision[Tetrahedron[pl_], level_Integer] /; 
  level == 0 := Tetrahedron[pl]
NestedSymmetricSubdivision[Tetrahedron[pl_], level_Integer] /; 
  level > 0 := 
 Flatten[NestedSymmetricSubdivision[
     SymmetricSubdivision[Tetrahedron[pl], #], level - 1] & /@ 
   Range[0, 7]]

Graphics3D[
 NestedSymmetricSubdivision[
  Tetrahedron[{{0, 0, 0}, {1, 0, 0}, {1/2, Sqrt[3]/2, 0}, {1/2, Sqrt[
     3]/6, Sqrt[6]/3}}], 3], BaseStyle -> Opacity[0], Boxed -> False]

The mesh I wish to histogram over

MKF
  • 591
  • 2
  • 10
  • So the question is the following now, is there a way to convert this into a mesh, and tally all the points inside each mini tetrahedron, so that each tetrahedron has different opacity based on the number of points inside each region? – MKF Feb 27 '19 at 13:55
  • My guess is yes using ListDensityPlot3D[HistogramList[pts, 10][[2]], DataRange -> the region of the tetrahedron] but with the above converted into a mesh somehow – MKF Feb 27 '19 at 13:56
  • These are all tetrahedra, but they are not identical. Some have a different shape than others. When you mentioned histogram, I assumed you wanted identical shapes (possibly flipped or rotated), something in analogy with a 2D triangular lattice. – Szabolcs Feb 27 '19 at 14:30
  • My bad, Sorry for the confusion! I want to basically implement the technique you have somehow to the tetrahedron layout above; actually I think these are all identical up to reflections... – MKF Feb 27 '19 at 14:34
  • So if you plot a bunch of points in 3D which lie inside each mini tetramino, it does a very similar thing to ListDensityPlot3D[HistogramList[pts, 10][[2]], DataRange -> the region of the tetrahedron], or equivalently your tally function. The feature I want to change is not colour however, but opacity of each tetramino – MKF Feb 27 '19 at 14:35
  • 1
    You can easily find out if a point is in a tetrahedron using RegionMember[Tetraherdon[{....}]][pointOfInterest]. This would be easy to repurpose for tallying the points in each tetrahedron, though it might be slow. – N.J.Evans Feb 27 '19 at 16:26
  • Sorry I'm not sure how this would be implemented, for one if points lie inside a tetramino, how does mathematica know which volume its in? – MKF Feb 28 '19 at 00:26
  • I thought about it, and I think I have an idea... – MKF Feb 28 '19 at 12:10
  • 2
    Taking your own code, look at Graphics3D /@ NestedSymmetricSubdivision[ Tetrahedron[{{0, 0, 0}, {1, 0, 0}, {1/2, Sqrt[3]/2, 0}, {1/2, Sqrt[3]/6, Sqrt[6]/3}}], 1]. It's quite clear from simple visual inspection that the tetrahedra are not identical. We can verify that they have the same Volume, but not the same SurfaceArea or the same shape. Of course we can still use them for binning if we want to. – Szabolcs Feb 28 '19 at 14:49
  • 2
    If you can determine a center for each cell (tetrahedron or other) such that the cell would be a Voronoi cell, then you can use the same approach as in the code I linked: use Nearest to determine which cell each binned point belongs to. – Szabolcs Feb 28 '19 at 14:50
  • They are not the same shape? I need to check this xD thanks for the headsup! Maybe its just the angle, but they look symmetric to me... – MKF Feb 28 '19 at 18:01
  • Exactly that was my idea also to borrow your hexagonal method – MKF Feb 28 '19 at 18:02
  • Damn - they aren't symmetric :( – MKF Feb 28 '19 at 22:19
0

So I have some random points that lie in the tetrahedron, Random points,

and also calculate the centres of the tetraminos using Mean.

I apply indices = First /@ nf /@ cloud as in @Szabolcs code and now want to bin the points in each tetramino bin.

Here is histogram of the indices to check things are happening

Histogram

I have tried

tally = Tally[indices];

ListDensityPlot3D[Join[cloud, List /@ Sort[tally][[All, 2]], 2],
  ColorFunction -> (ColorData["BeachColors"][1 - #] &)]

To bin the points but to no avail.

As for @N.J.Evans response, I define RegionMemberFunctions as

Map[RegionMember, NestedSymmetricSubdivision[
 Tetrahedron[{{0, 0, 0}, {1, 0, 0}, {1/2, Sqrt[3]/2, 0}, {1/2, Sqrt[
    3]/6, Sqrt[6]/3}}], 3]];

But if I try to now tally/bin the points with

    Table[Map[regionmemberfunctions[[i]], cloud], {i, 1, 
   Length[NestedSymmetricSubdivision[
     Tetrahedron[{{0, 0, 0}, {1, 0, 0}, {1/2, Sqrt[3]/2, 0}, {1/2, Sqrt[
        3]/6, Sqrt[6]/3}}], 3]]}];

It takes forever... Any ideas greatly appreciated!

MKF
  • 591
  • 2
  • 10
  • I think perhaps binning over the tetraminos and using something like this is great https://mathematica.stackexchange.com/questions/17260/3d-heatmap-density-plot – MKF Mar 03 '19 at 12:05
  • And maybe via Which or Count there could be some success – MKF Mar 03 '19 at 13:47