I've been using random walk Metropolis to sample from the (unnormalised distribution) which is defined as $p(r)\propto e^{-100 r}$, where $r$ is the perpendicular distance of a point in 3D space from the surface of the cow:
The code to do so is,
polygonCoords = Flatten[Cases[Normal[ExampleData[{"Geometry3D", "Cow"}]],
Polygon[x_, ___] :> x, {0, Infinity}], 1];
fPDF[aPoint__, lPolygonCoords__] := Module[{aMin =
Min[EuclideanDistance[#, aPoint] & /@ lPolygonCoords]}, Exp[-100 aMin]]
fStep[aPoint__, aStepSize_] :=RandomVariate[MultinormalDistribution[aPoint,
aStepSize IdentityMatrix[3]], {1}][[1]]
fAcceptStep[aPoint_, aStepSize_, lPolygonCoords__] := Module[{aProposed = fStep[aPoint, aStepSize], aRand = RandomReal[], r}, r = fPDF[aProposed, lPolygonCoords]/
fPDF[aPoint, lPolygonCoords]; If[r > aRand, aProposed, aPoint]]
fMetropolis[numSteps_Integer, aStart__, aStepSize_, lPolygonCoords__] := NestList[fAcceptStep[#, aStepSize, lPolygonCoords] &, aStart, numSteps]
data = Flatten[ParallelTable[
fMetropolis[1000, {0, 0, 0}, 0.001, polygonCoords], {i, 1, 4, 1}],1];
which generates sample paths over time that look like,
I want to draw a 3D point plot of all the sampled values where each of the points is a cow shape. I have tried doing this with,
n=10;
BubbleChart3D[
Thread[{data[[1 ;; n, 1]], data[[1 ;; n, 2]], data[[1 ;; n, 3]],
ConstantArray[0.1, n]}], ChartElements -> aCow,
ChartStyle -> Black, BubbleSizes -> {0.02, 0.04}]
which does work for a small number of points (10 in the below case),
However, it does not scale well to 1000s of points, which is unsurprising given that each cow is a fairly complex 3D graphic. I have tried downsampling the cow's polygon coordinates and using these as markers instead by,
lRandomComponents = RandomInteger[{1, 5804}, 2000];
aLowResCow =
Graphics3D[{Opacity[1], EdgeForm[Opacity[1]],
Polygon[#, VertexColors -> Table[Hue[0, 0, 0], {Length[#]}]] & /@
Cases[Normal[ExampleData[{"Geometry3D", "Cow"}]],
Polygon[x_, ___] :> x, {0, Infinity}][[lRandomComponents]]}]
which generates a fragmented cow,
but using these doesn't really work on the BubbleChart3D plot (they are shaded grey -- I want them black -- and don't look much like cows).
Does anyone have any idea how I can generate a 3D point plot like what I want without having an enormous file size and taking my computer a day to produce? If it helps, I don't need to be able to rotate such a plot in 3D.
Rasterize
your file size will drop considerably. Just set theViewPoint
and things on the chart properly. $\endgroup$