-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaddPolyhedron.m
37 lines (31 loc) · 1022 Bytes
/
addPolyhedron.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
% Add a polyhedron to model
% FUNCTION model_out = addPolyhedron(nodeX,nodeY,nodeZ,model_in,points,val)
% INPUT
% nodeX,nodeY,nodeZ,model_in: input mesh and model
% points: a 3-column matrix to specify a group of X-Y-Z points that
% form a convex hull enclosing target cells' centers
% val: model value to be assgined to the target cells
% OUTPUT
% model_out: model vector with objects embedded
% NOTE
% Only one object at one function call
% LAST MODIFIED 20191107 [email protected]
function model_out = addPolyhedron(nodeX,nodeY,nodeZ,model_in,points,val)
Nx = length(nodeX) - 1;
Ny = length(nodeY) - 1;
Nz = length(nodeZ) - 1;
if isempty(model_in)
model_in = zeros(Nx*Ny*Nz,1);
elseif isscalar(model_in)
model_in = zeros(Nx*Ny*Nz,1) + model_in;
end
model_out = model_in;
temp = CellIndex2PointXYZ(nodeX,nodeY,nodeZ,[]);
x = temp(:,1);
y = temp(:,2);
z = temp(:,3);
tri = delaunayn(points);
tn = tsearchn(points,tri,[x y z]);
isInside = ~isnan(tn);
model_out(isInside) = val;
end