Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- data3C = RandomReal[1, {10, 6}];
- func3C = Nearest[{#, #2, #3} -> {##4, .03} & @@@ data3C];
- tbl3C = Table[ First[func3C[{x, y, z}]] // Quiet, {x, 0, 1, .01},
- {y, 0, 1, .01}, {z, 0, 1, .01}];
- Row[Labeled[Graphics3D[Raster3D[tbl3C, ColorFunction -> #,
- Method -> {"InterpolateValues" -> True}],
- Background -> Black, ImageSize -> 400,
- SphericalRegion -> True], #, Top] & /@
- {Hue, RGBColor, (GrayLevel[#[[1]], .03] &)}, Spacer[5]]
- colorRules = Thread[# -> (ColorData[1, "ColorList"][[;; Length@#]])] &[
- Flatten[tbl3C, 2] // DeleteDuplicates] /. RGBColor -> List;
- Row[Labeled[ Graphics3D[Raster3D[tbl3C /. colorRules, ColorFunction -> #,
- Method -> {"InterpolateValues" -> True}],
- Background -> Black, ImageSize -> 400,
- SphericalRegion -> True], #, Top] & /@
- {(RGBColor[#[[1]], #[[2]], #[[3]], .01] &),
- (RGBColor[#[[1]], #[[2]], #[[3]], .03] &),
- (RGBColor[#[[1]], #[[2]], #[[3]], .05] &)}, Spacer[5]]
- data = RandomReal[1, {20, 4}];
- func = Nearest[{#, #2, #3} -> #4 & @@@ data];
- dta = Table[func[{x, y, z}] // Quiet, {x, 0, 1, .005}, {y, 0, 1, .005}, {z, 0, 1, .005}];
- Grid[Partition[
- Image3D[dta,
- ImageSize -> 350, ColorFunction -> #, Background -> Black] & /@
- {"SunsetColorsOpacity", "RainbowOpacity", "WhiteBlackOpacity",
- (Append[Blend[{LightBlue, Blue, Yellow}, #], #] &)}, 2]]
- data = RandomReal[1, {20, 4}];
- func = Nearest[{#, #2, #3} -> #4 & @@@ data];
- ContourPlot3D[
- func[{x, y, z}] // Quiet,
- {x, 0, 1}, {y, 0, 1}, {z, 0, 1},
- ColorFunction -> (Hue@#3 &)
- ]
- BlockRandom[SeedRandom["voronoi"]; pts = RandomReal[{-1, 1}, {32, 3}]];
- nf = Nearest[pts];
- (* gradient-normalized function *)
- vfun[x_?NumericQ, y_?NumericQ, z_?NumericQ] := With[{np = nf[{x, y, z}, 2]},
- (EuclideanDistance[{x, y, z}, np[[2]]] - EuclideanDistance[{x, y, z}, np[[1]]])/
- EuclideanDistance[Normalize[{x, y, z} - np[[2]]], Normalize[{x, y, z} - np[[1]]]]]
- With[{ε = 1/100}, (* tiny number, increase if you want to see gaps between cells *)
- ContourPlot3D[vfun[x, y, z] == ε, {x, -1, 1}, {y, -1, 1}, {z, -1, 1},
- MaxRecursion -> 1, Mesh -> False, PlotPoints -> 35]]
- $QHULL::usage="$QHULL should contain the name (as a string) of the folder that contains the QHULL binaries on your system.
- $QHULL = ToFileName[{$UserBaseDirectory, "Applications", "qhull", "src"}];
- $QHULL = ToFileName[{NotebookDirectory[], "qhull", "bin"}];
- SetDirectory[NotebookDirectory[]]
- << "mPower.m"
- Warning: regtet binary not found. Expected location: /mPower-1.0-11-May-2008-1631/qhull/bin/
- Warning: pwrvtx binary not found. Expected location: /mPower-1.0-11-May-2008-1631/qhull/bin/
- (* random 3D points *)
- points = RandomReal[1, {40, 3}];
- (* construct 3D convexhull *)
- ch = convexHull[points, convexHullFormat -> {facetNormals -> True, facets -> True}];
- (* generate facets for 3D convexhull *)
- facetIndices = facets /. ch;
- loop[alist_] := Append[alist, alist[[1]]];
- loopedFacetIndices = loop /@ facetIndices;
- index2xyz[ijklist_] := points[[#]] & /@ ijklist;
- loopedFacetCoordinates = index2xyz /@ loopedFacetIndices;
- (* visulization 3D convexhull *)
- convexObject =
- Graphics3D[{PointSize[Large], Point[points], FaceForm[],
- EdgeForm[Blue], Polygon /@ loopedFacetCoordinates},
- ImageSize -> 500]
- pad[δ_][{min_, max_}] := {min, max} + δ(max-min){-1, 1}
- VoronoiCells[pts_] :=
- Block[{bds, dm, init, conn, adj, lc, pc, cpts, hpts, hns, hp, vcells},
- bds = pad[.1] /@ MinMax /@ Transpose[pts];
- dm = DelaunayMesh[pts];
- init = BoundaryMeshRegion[Tuples[bds], Polygon[{{1,2,4,3},{2,4,8,6},{8,6,5,7},{1,5,7,3},{1,5,6,2},{3,7,8,4}}]];
- conn = dm["ConnectivityMatrix"[0, 1]];
- adj = conn . Transpose[conn];
- lc = conn["MatrixColumns"];
- pc = adj["MatrixColumns"];
- cpts = MeshCoordinates[dm];
- vcells = Table[
- hpts = PropertyValue[{dm, {1, lc[[i]]}}, MeshCellCentroid];
- hns = Transpose[Transpose[cpts[[DeleteCases[pc[[i]], i]]]] - cpts[[i]]];
- hp = MapThread[HalfSpace, {hns, hpts}];
- RegionIntersection @@ Prepend[BoundaryDiscretizeGraphics[Graphics3D[#, PlotRange -> bds]]& /@ hp, init],
- {i, MeshCellCount[dm, 0]}
- ];
- AssociationThread[cpts, vcells]
- ]
- SeedRandom[10000];
- pts = RandomReal[1, {10, 3}];
- vc = VoronoiCells[pts]
- Show[MapIndexed[
- BoundaryMeshRegion[#, MeshCellStyle -> {1 -> {Black, Thick}, 2 -> {ColorData[112][First[#2]]}}] &,
- Values[vc]
- ]]
- Show[
- MapIndexed[
- BoundaryMeshRegion[#, MeshCellStyle -> {1 -> {Black, Thick}, 2 -> {ColorData[112][First[#2]]}}] &,
- Values[vc]
- ],
- Graphics3D[{PointSize[Large], Point[pts]}],
- Method -> {"RelieveDPZFighting" -> True}
- ]
Add Comment
Please, Sign In to add comment