addpath '/var/home/$USER/LabData/Toolboxes/mmc-master/iso2mesh-master';
addpath '/var/home/$USER/LabData/Toolboxes/mmc-master/matlab';
addpath '/var/home/$USER/LabData/Toolboxes/mmc-master/mmclab';
clear all;
close all;
%################################
% CONTROL FLAGS
%################################
PLOT_CYLINDERS = true;
%################################
% PROPERTIES OF CYLINDERS
%################################
% Radius
r = 13/2; % [mm]
% Height
h = 20; % [mm]
% Distance between cylinders
dx = 20 % [mm]
% Position along x
xoffset1 = -5; % [mm]
xoffset2 = xoffset1 + dx; % [mm]
xoffset3 = xoffset2 + dx; % [mm]
%################################
% MAKE CYLINDERS
%################################
% Create the three inclusions and merge the meshes.
% Cylinder 1
% Create meshed volume for the first cylinder;
[node1,face1,elem1]=meshacylinder([xoffset1, 0, 0],[xoffset1, 0, h],r);
% Extract longitudinal surface from the meshed cylinder.
[node1,elem1,face1]=surf2mesh(node1,face1,[],[],1,1);
% Remove isolated nodes in the cylinders surface.
[node1,elem1]=removeisolatednode(node1,elem1(:,1:4));
elem1(:,5) = 1;
% Cylinder 2
[node2,face2,elem2]=meshacylinder([xoffset2,0,0],[xoffset2,0,h],r);
% Extract longitudinal surface from the meshed cylinder.
[node2,elem2,face2]=surf2mesh(node2,face2,[],[],1,1);
% Remove isolated nodes in the cylinders surface.
[node2,elem2]=removeisolatednode(node2,elem2(:,1:4));
elem2(:,5) = 1;
% Cylinder 3
[node3,face3,elem3]=meshacylinder([xoffset3,0,0],[xoffset3,0,h],r);
% Extract longitudinal surface from the meshed cylinder.
[node3,elem3,face3]=surf2mesh(node3,face3,[],[],1,1);
% Remove isolated nodes in the cylinders surface.
[node3,elem3]=removeisolatednode(node3,elem3(:,1:4));
elem3(:,5) = 1;
% Merge the three cylinders.
[cnode,celem]=mergemesh(node1,elem1,node2,elem2,node3,elem3);
% If true plot the cylinders
if PLOT_CYLINDERS
plotmesh(cnode, celem);
endif
% Add a box and merge with the cylinders.
[node4,face4,elem4]=meshabox([-20 -50 0], [80 50 40], 1);
elem4(:,5) = 2;
[pnode,pelem]=surfboolean(node4,elem4,'first',cnode,celem); % <==== ERROR
plotmesh(pnode, pelem);