4
$\begingroup$

Suppose I have the ellipsoid below and a set of points that I know rest on its boundary, which we can visualize:

enter image description here

myEllipsoid = Ellipsoid[{0.0, 0.0, 0.0}, {0.6, 0.51, 0.51}];
myPts = {{0.593679, -0.0735365, 0.00659148}, {0.494143, 0.283443, 
  0.0578081}, {0.584258, 0.0654221, 0.0958602}, {0.402426, 0.310281, 
  0.216377}, {0.459941, 0.281123, 0.168012}, {-0.504438, 0.252776, 
  0.111169}, {0.559942, -0.0130326, -0.182759}, {0.300967, \
-0.0211969, -0.440688}, {-0.317913, -0.0273509, 
  0.431659}, {-0.338246, -0.420491, -0.0250135}, {0.520373, -0.251189,
   0.0368769}, {0.548404, -0.127346, -0.163074}, {0.564902, 0.145276, 
  0.0918395}, {0.53703, -0.0377495, 
  0.224289}, {-0.368742, -0.366963, -0.164922}, {0.0502806, \
-0.220897, -0.457688}, {0.594841, -0.0394563, -0.0538189}, {0.544155, 
  0.0648616, 0.204835}, {0.157706, 
  0.0313612, -0.491067}, {0.572797, -0.140541, 
  0.0574317}, {0.535294, -0.223203, -0.0570592}, {0.459515, -0.25623, \
-0.204665}, {0.581355, 0.0300194, 0.122529}, {0.585535, 
  0.0628569, -0.0918634}, {0.0200364, -0.140076, -0.490091}, \
{0.520035, -0.243296, -0.0742746}, {0.539101, 
  0.182186, -0.130109}, {0.48967, 0.0613401, 
  0.288269}, {0.402467, -0.246313, 
  0.287054}, {0.575742, -0.14353, -0.00233433}, {0.511062, -0.253598, \
-0.0841572}, {0.350632, 0.383596, 0.155332}, {0.499918, 
  0.274937, -0.0628012}, {0.384362, -0.365614, 0.140316}, {-0.59223, 
  0.0754093, -0.0317296}, {0.573891, 0.141038, 
  0.0474573}, {0.570195, -0.145204, -0.0641499}, {0.300396, 
  0.0924771, -0.431684}, {0.591402, -0.0852871, -0.0112781}, \
{-0.507293, 0.145422, 0.230261}, {0.0928641, 
  0.390652, -0.318215}, {0.382672, 0.328638, 
  0.215165}, {0.450786, -0.301918, 
  0.148754}, {0.532054, -0.0794074, -0.221965}, {0.173024, -0.108262, 
  0.476182}, {0.551047, -0.0709817, -0.188871}, {0.591256, -0.0824216,
   0.0270596}, {0.597563, 0.0240085, -0.0391397}, {-0.584905, 
  0.0726007, -0.0874755}, {0.583177, 0.11959, 
  0.00889368}, {-0.523774, -0.240517, -0.0635752}, {0.580437, \
-0.128582, -0.0122874}, {0.569432, 0.0891909, 0.133687}, {0.49999, 
  0.277453, -0.0500251}, {0.565507, 0.081353, 0.149758}, {-0.206338, 
  0.458657, 0.137744}, {-0.464875, -0.15932, -0.280318}, {0.434456, 
  0.132814, -0.32571}, {0.516675, -0.216816, 
  0.142186}, {0.423751, -0.111787, -0.34332}, {0.588299, 
  0.0199414, -0.098227}, {0.582378, -0.044564, 
  0.114317}, {0.548397, -0.0643825, -0.196648}, {0.559008, 
  0.0549179, -0.176947}, {0.312693, -0.0343426, 0.433909}, {0.308635, 
  0.321725, 0.296261}, {0.375231, 
  0.333513, -0.217122}, {0.360862, -0.132396, 0.385339}, {0.531232, 
  0.20298, 0.122493}, {0.512777, 0.261849, 
  0.0395054}, {0.512189, -0.163328, -0.209488}, {0.107448, -0.242647, \
-0.439182}, {0.515151, -0.0724695, 0.251218}, {0.569021, 0.153872, 
  0.0498918}, {0.45504, 0.332394, 0.00350962}, {0.53832, 
  0.0293732, -0.223304}, {0.580887, 0.103948, -0.0741727}, {0.539406, 
  0.0339783, -0.220744}, {0.304372, 0.437276, -0.0442191}, {0.592431, 
  0.0324502, -0.0739451}, {0.533067, -0.194056, -0.130905}, \
{0.571904, -0.136919, 0.0710108}, {0.545131, 
  0.212543, -0.0149038}, {0.553351, -0.167445, -0.10409}, {0.592384, 
  0.0683956, 0.0433925}, {0.551983, 0.0480098, -0.194062}, {0.56086, 
  0.0928923, -0.155558}, {0.490714, 0.290722, 0.040035}, {0.536577, 
  0.0172276, 
  0.227562}, {0.536115, -0.225522, -0.0397386}, {0.105799, -0.0686488,
   0.497293}, {0.179106, 0.0270204, 0.485997}, {0.480118, -0.174415, 
  0.251264}, {0.527599, -0.237323, -0.0515979}, {0.34209, 
  0.382726, -0.170498}, {0.178285, -0.46368, 
  0.148781}, {0.592031, -0.0366386, -0.0743019}, {0.581949, -0.118243,
   0.0378657}, {0.598141, 0.0397553, 
  0.00537969}, {0.557574, -0.0584943, 0.179056}, {0.181338, 
  0.343732, -0.343788}, {0.550845, -0.19825, -0.0396088}, {0.0298082, 
  0.0786698, 0.503258}, {0.4384, 0.0438016, 0.345429}, {0.512319, 
  0.249786, 0.0898446}, {0.411013, 0.178582, 
  0.325815}, {0.449884, -0.336882, 0.0194843}, {0.21589, 0.307635, 
  0.363024}, {0.535883, -0.169128, -0.154968}, {0.398095, 
  0.156826, -0.347856}, {0.408139, -0.211333, -0.30836}, {0.0708964, 
  0.222115, 0.455119}, {0.0577863, -0.267084, -0.431687}, {0.463168, 
  0.323315, 0.0239453}, {-0.584824, 0.0581806, 0.0980116}, {0.536894, 
  0.227047, 0.0168769}, {0.43428, -0.351209, 
  0.0221204}, {0.497472, -0.282963, 
  0.0350587}, {0.456874, -0.0267252, -0.329508}, {0.188642, 
  0.10691, -0.472186}, {0.29668, 0.148713, -0.417601}, {0.585931, 
  0.107533, -0.0221711}, {0.139081, 0.297389, 0.397095}, {0.55664, 
  0.0822179, -0.171682}, {0.571576, -0.126264, -0.0900977}, {0.566408,
   0.0722321, -0.151959}, {-0.541625, -0.0842809, -0.202597}, \
{0.581613, 
  0.0266587, -0.122419}, {-0.213295, -0.467568, -0.0927895}, {0.2543, 
  0.417563, 0.197531}, {0.572915, 0.145749, 0.0413487}, {0.471502, 
  0.207719, 0.237341}, {0.526441, -0.0578416, 0.237741}, {0.572783, 
  0.0448353, -0.145092}, {0.503646, 0.0660191, 
  0.269208}, {0.566383, -0.127961, 
  0.10934}, {0.507364, -0.0627867, -0.264902}, {0.597244, 
  0.0430006, -0.0231319}, {0.587094, -0.0908935, 
  0.0529867}, {0.500906, -0.269482, 0.0787378}, {0.411024, 0.058188, 
  0.366953}, {0.548466, 0.178768, -0.103937}, {0.57667, -0.138372, 
  0.0262143}, {0.431806, 0.24059, -0.259811}, {0.562194, 0.170577, 
  0.0514626}, {0.59487, -0.0569283, -0.0344614}, {0.1424, 0.49073, 
  0.0680694}, {0.374084, -0.240519, 
  0.318032}, {0.570799, -0.131581, -0.0859541}, {0.076717, -0.0164623,
   0.505546}, {0.584972, -0.0919421, 
  0.0664315}, {0.476142, -0.0776265, 0.300458}, {0.551125, 0.159802, 
  0.122931}, {-0.558464, 0.185316, -0.0205674}, {0.0642329, -0.261885,
   0.434206}, {0.54552, -0.206754, -0.0483986}, {0.5614, 
  0.172301, -0.0519852}, {0.358392, -0.258641, -0.316864}, {0.365779, \
-0.219937, -0.339207}, {0.597374, -0.0337621, 0.0336373}, {0.564885, 
  0.113641, -0.128994}, {0.308195, -0.437552, 0.00475064}, {0.579782, 
  0.130226, -0.0165808}, {-0.459815, -0.0768046, -0.318501}, \
{0.511888, -0.036747, -0.263502}, {0.532026, -0.210161, -0.1069}, \
{0.330123, -0.422443, 0.0538807}, {0.582555, 0.0288666, 
  0.118623}, {0.117622, -0.481487, 0.135185}, {0.529074, 
  0.051752, -0.234905}, {0.480519, -0.0912771, -0.291452}, {0.578019, \
-0.0848916, -0.107249}, {0.512038, 0.247668, -0.0966111}, {-0.522405, 
  0.159365, -0.19372}, {0.0116164, -0.462754, -0.214153}, {0.563395, 
  0.151171, 0.0889709}, {-0.580684, 0.0660721, 0.110053}, {0.573207, 
  0.129883, 0.0764261}, {0.563379, 0.163965, 
  0.0624212}, {0.592263, -0.0517964, 0.0631042}, {0.532889, 
  0.225255, -0.0647384}, {0.499886, 
  0.2646, -0.0976922}, {0.589578, -0.0758341, -0.0566247}, {0.5865, \
-0.107561, 0.0018891}, {0.25802, 0.0803959, 0.453361}, {0.483384, 
  0.266277, -0.142749}, {0.548632, 0.153649, 0.137919}, {0.563278, 
  0.168678, -0.0491019}, {0.347009, 0.114294, 0.400046}, {0.181869, 
  0.407917, -0.264208}, {0.52543, -0.241474, 0.0482152}, {0.439454, 
  0.278003, -0.208052}, {0.529985, 0.0429061, 0.235203}, {0.578855, 
  0.100313, -0.0891473}, {0.569105, -0.141127, -0.0786077}, \
{0.586202, -0.108403, 0.00862628}, {0.268968, 0.289547, 
  0.352128}, {0.430088, -0.134101, 0.329351}, {0.582217, 
  0.114561, -0.0454432}, {0.012659, -0.504316, 0.0751613}};

Now, I would like to color the surface of the ellipsoid so that it represents the local density of points on its surface (a density plot). I'm aware of this question but I didn't see a way to apply this to my specific region.

One quite inefficient way I was attempting relies on first making a mesh out of the ellipsoid, then extracting each polygon, then counting how many points are near each polygon within a given (small) distance. However, this takes a while to compute for the real scenarios I'm trying, and also there is no guarantee of avoiding double counting points that are within a distance from adjacent polygons. Still I leave here some code to see the idea. Also there might be a faster way to compute distances (say, not sampling all points but only these within some radius of the polygon query, etc).

(*Brute force, not avoiding double counting approach*)
{myVertex, myPolygons} = {MeshCoordinates[myDiscreteEllipsoid], 
   MeshCells[myDiscreteEllipsoid, 2]};
explicitPolygons = 
  Table[myVertex[[myPolygons[[i]][[1]]]], {i, 1, Length[myPolygons]}];

enter image description here

enter image description here

(*List of points within reach of each polygon*)
distanceThreshold = 0.01;

myPointsWithinReach = 
  Table[Flatten[
    Position[(RegionDistance[Polygon[explicitPolygons[[i]]], #] & /@ 
       myPts), _?(# <= distanceThreshold &)]],
   {i, 1, Length[explicitPolygons]}];

Then the idea would be to re-color the polygons with their associated "density" of points.

I'm aware of ParametricPlot3D[], but I'm working with a few different shapes besides ellipsoids, so I'd like to avoid this function.

Note: I'll be working with thousands of points in different configurations (different sized ellipsoids, and other shapes). So, a good solution should account for the need to use thousands of points.

$\endgroup$

1 Answer 1

4
$\begingroup$

This is not exactly what the OP is asking for, i.e. a true ellipsoidal smooth density histogram, but perhaps it gives satisfactory results and can inspire more answers.

The idea is to construct a full 3D-space kernel-distribution function and plot its density plot on the ellipsoid surface. Note this generalizes nicely to arbitrary surfaces and should be reasonably performant:

kernel = SmoothKernelDistribution[myPts];
pdf = PDF[kernel];

SliceDensityPlot3D[pdf[{x, y, z}], myEllipsoid, 
{x, -0.6, 0.6}, {y, -0.6, 0.6}, {z, -0.6, 0.6},
ColorFunction -> "SunsetColors", BoxRatios -> Automatic]

enter image description here

$\endgroup$
2
  • 1
    $\begingroup$ Seems promising, but the colors seem odd on the surface (like jagged), even when many points are added (which seems weird given that more points should make things smoother, I imagine). I wonder if this has to do with the kernel/pdf generation. EDIT: Yeah, I can smooth things within the kernel. Well, this is a great start, thanks! $\endgroup$ Jul 12, 2022 at 20:48
  • $\begingroup$ You could pre-discretize the ellipse to get the smoother image like: SliceDensityPlot3D[pdf[{x, y, z}], BoundaryDiscretizeRegion[myEllipsoid, AccuracyGoal -> 4], {x, -0.6, 0.6}, {y, -0.6, 0.6}, {z, -0.6, 0.6}, ColorFunction -> "SunsetColors", BoxRatios -> Automatic] $\endgroup$
    – halmir
    Jul 14, 2022 at 16:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.