image thumbnail

3D voronoi via fem mesh, the voronoi3d class, visualization

version 1.0.0 (61.3 KB) by Wan Ji
The project defines a voronoi3d class, which can generate 3d voronoi polyhedrons from fem mesh and visualize them

86 Downloads

Updated Mon, 28 Jun 2021 03:05:22 +0000

View License

voronoi3d class
This is a class that describes the 3d voronoi polyhedron, several member variables and functions are attached. The first variable is Nodes, it is the coordinates of nodes neccessary to construct the whole voronoi cells. Then Faces provides the connectivity list of nodes for each face. Voronois gives the list of faces that belong to each voronoi cell. FaceNormals are the unit normal vector of each face. Volumes and Centroids are the volume and centroid of each cell respectively.
voronoi3d
This function can generate an empty voronoi3d object if no input is provided, e.g.
voronoi3d_obj = voronoi3d();
If you want construct a non-empty polyhedron or voronoi object, Input like Nodes, Faces and Voronois are necessary, e.g.
Nodes = [0,0,0; 2,0,0; 1,1.5,0; 1,1,1.5; 1,0,1];
Faces = {[1,2,3];[2,3,4];[3,1,4];[1,2,4];[1,2,5];[2,4,5];[4,1,5]};
% patch two tetrahedrons(Of course polyhedron like voronoi can be patched like this)
Voronois = {[1,2,3,4];[4,5,6,7]};
voronoi3d_obj = voronoi3d(Nodes, Faces, Voronois);
createVoronoi3dFromMesh
The function uses tetrahedron(C3D4 or C3D10) mesh to generate voronoi cells. C3D4 or C3D8 mesh must not be abnormal, viz. quite tetrahedral. To use this function, empty voronoi3d object must be generate first. Example like
Nodes = [0,0,0; 2,0,0; 1,1.5,0; 1,1,1.5; 1,0,1];
Elements = [1,2,3,4; 1,2,4,5];
obj = voronoi3d; % create an empty voronoi3d object
obj = createVoronoi3dFromMesh(obj, Nodes, Elements); % create voronoi by geometry
voronoiPatch(obj,'bycell');
Then we have the figure of this example
createVoronoi3dFromMesh
This function is to some extent, the same as createVoronoi3dFromMesh, but the geometry can be regenerated meshes, Example like
myGeo3d = multicylinder(1,3); % create a cylinder geometry with radius 1 and height 3
obj = voronoi3d; % create an empty voronoi3d object
edgeSize = 0.5;
obj = createVoronoi3dFromGeometry(obj, myGeo3d, edgeSize); % create voronoi by geometry
voronoiPatch(obj,'bycell');
The final picture
voronoiPatch
This function is for the visualization of voronoi class. There are two options of visualization type. One is 'bycell', the other is 'nodal'. Using 'bycell', colors of cells are generated randomly, whilst the utilization of 'nodal' should provide the corresponding nodal field variables of all the nodes. Examlpe can be seen as follows
%% Example
Nodes = [
0,0,0;
2,0,0;
1,1.5,0;
1,1,1.5;
1,0,1;
];
Faces = {
[1,2,3];[2,3,4];[3,1,4];[1,2,4];
[1,2,5];[2,4,5];[4,1,5];
};
% patch two tetrahedrons(Of course polyhedron like voronoi can be patched like this)
Voronois = {[1,2,3,4];[4,5,6,7]};
v3dCell = voronoi3d(Nodes, Faces, Voronois);
voronoiPatch(v3dCell,'bycell');
v3dCell.voronoiPatch('nodal',Nodes(:,3));
bycell
nodal
Other functions like icosohedron.m, surfaceReduction.m, specialVoronoi3d.m, simplifyVoronoi3d.m, renumber.m, buckyballs.m are functions that are necessary for the examples or voronoi3d class.
Here many thanks to linear2quad.m and Polyhedron_VAC.m

Cite As

Wan Ji (2022). 3D voronoi via fem mesh, the voronoi3d class, visualization (https://www.mathworks.com/matlabcentral/fileexchange/94955-3d-voronoi-via-fem-mesh-the-voronoi3d-class-visualization), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2020a
Compatible with R2016a and later releases
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!