Search code examples
matlabpde3d-modelling3d-model

Manipulating 3D models using Matlab to create specified Voids


I am working to create a basic model of bubbles within a static cube of water to test the electric field generated between an ideal system of parallel plates. I am currently using the PDEToolbox included with matlab so am working with DiscreteGeometries. I have also been tinkering with importing a cube and bubbles as .stl files from CAD software and pairing them. I wish to control the location/size of the blocks such as those used in this example. I wish to create 'bubbles' so just changing the shape/size/location of the sphere used would be great! Is this feasible using matlab at all? Either of the methods stated above would be best unless there is a more applicable way to do this more simply.


Solution

  • I used the example you gave to show how you can create bubbles by eliminating grid points from the cube gird:

    % create the "cube"
    [xg, yg, zg] = meshgrid(-2:0.25:2);
    Pcube = [xg(:) yg(:), zg(:)];
    

    make a "helper" function to only consider the x,y,z indices of a sphere keeping only the grid points above some radius r

    bubble = @(x,y,z,r) vecnorm(bsxfun(@minus,Pcube',[x y z]')) > r;
    

    Now we can create the "bubbles" by eliminating grid points in the cube according to the "bubble" function above

    Pcavitycube = Pcube( bubble(0.5, 0.8, 1.1, 0.25) & ...
                         bubble( 1 ,-0.2, 0.1, 0.4 ) & ...
                         bubble( -1,-0.8,  -1, 0.7 ) ...
                         ,:);
    
    plot(alphaShape(Pcavitycube),'FaceAlpha',0.1)
    

    enter image description here