-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
meshes3d: rename meshComplement.m to reverseMeshFaceOrientation.m
- Loading branch information
Showing
2 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
function varargout = reverseMeshFaceOrientation(varargin) | ||
%REVERSEMESHFACEORIENTATION Reverse the normal of each face in the mesh. | ||
% | ||
% [V2, F2] = reverseMeshFaceOrientation(V, F) | ||
% Computes new face vertex indices such that the volume enclosed by the | ||
% mesh becomes the opposite of that of the original mesh. The vertex | ||
% position of the two meshes are the same. | ||
% | ||
% Example | ||
% [v, f] = createOctahedron; | ||
% meshVolume(v, f) | ||
% ans = | ||
% 1.3333 | ||
% [v2, f2] = reverseMeshFaceOrientation(v, f); | ||
% meshVolume(v2, f2) | ||
% ans = | ||
% -1.3333 | ||
% | ||
% See also | ||
% meshes3d, meshVolume | ||
% | ||
|
||
% ------ | ||
% Author: David Legland | ||
% e-mail: david.legland@inrae.fr | ||
% INRAE - BIA Research Unit - BIBS Platform (Nantes) | ||
% Created: 2024-07-15, using Matlab 24.1.0.2628055 (R2024a) Update 4 | ||
% Copyright 2024 INRAE. | ||
|
||
% extract mesh data | ||
mesh = parseMeshData(varargin{:}); | ||
faces = mesh.faces; | ||
|
||
% iterate over faces to invert order of vertex indices | ||
if isnumeric(faces) | ||
faces = faces(:, [1 end:-1:2]); | ||
else | ||
for i = 1:size(faces, 1) | ||
faces{i} = faces{i}([1 end:-1:2]); | ||
end | ||
end | ||
|
||
% create new mesh data | ||
varargout = formatMeshOutput(nargout, mesh.vertices, faces); |