You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.2 KiB
43 lines
1.2 KiB
3 years ago
|
%--------------------------
|
||
|
% @Author: Jingqiao Hu
|
||
|
% @Date: 2021-12-03 19:58:59
|
||
|
% @LastEditTime: 2022-01-27 16:43:01
|
||
|
%--------------------------
|
||
|
function [valid_tets] = checkValid_tetmesh(node, tets)
|
||
|
|
||
|
delta = 1e-3;
|
||
|
|
||
|
x = node(:,1); % n,1
|
||
|
y = node(:,2);
|
||
|
z = node(:,3);
|
||
|
x = x(tets); % m,4
|
||
|
y = y(tets);
|
||
|
z = z(tets);
|
||
|
|
||
|
vol = tet_volume(x,y,z);
|
||
|
[idx, ~] = find(abs(vol) < delta);
|
||
|
|
||
|
ntet = size(tets, 1);
|
||
|
vaild_idx = setdiff(1:ntet, idx);
|
||
|
valid_tets = tets(vaild_idx, :);
|
||
|
% nonvalid_faces = tets(idx, :);
|
||
|
|
||
|
if max(valid_tets(:)) ~= size(node, 1) || min(valid_tets(:)) ~= 1
|
||
|
error("fixme!");
|
||
|
end
|
||
|
|
||
|
% valid_nodes = nodes;
|
||
|
% test = unique(valid_tets(:));
|
||
|
% figure; trimesh(valid_tets,nodes(:,1),nodes(:,2));
|
||
|
end
|
||
|
|
||
|
function [v] = tet_volume(x,y,z)
|
||
|
|
||
|
x1 = x(:,1); x2 = x(:,2); x3 = x(:,3); x4 = x(:,4);
|
||
|
y1 = y(:,1); y2 = y(:,2); y3 = y(:,3); y4 = y(:,4);
|
||
|
z1 = z(:,1); z2 = z(:,2); z3 = z(:,3); z4 = z(:,4);
|
||
|
|
||
|
v = (x2-x1) .* ((y3-y1) .* (z4-z1) - (y4-y1) .* (z3-z1)) + ...
|
||
|
(y2-y1) .* ((x4-x1) .* (z3-z1) - (x3-x1) .* (z4-z1)) + ...
|
||
|
(z2-z1) .* ((x3-x1) .* (y4-y1) - (x4-x1) .* (y3-y1));
|
||
|
end
|