Skip to content

Commit

Permalink
various code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
dlegland committed Sep 26, 2019
1 parent 0cf930d commit db834f9
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 26 deletions.
7 changes: 4 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ and finally by module.
## [Unreleased]


## MatGeom 1.2.0 - 2018-06-07
## MatGeom 1.2.1 - 2019-09-26

Main changes are new functions for processing 3D meshes, and renaming of
inertia ellipse/ellipsoid into equivalent ellipse/ellipsoid.
Main changes are new functions for processing 3D meshes (repairing,
simplification), and renaming of inertia ellipse/ellipsoid into equivalent
ellipse/ellipsoid.

### Added

Expand Down
13 changes: 7 additions & 6 deletions matGeom/geom2d/crackPattern.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
% figure;
% drawEdge(E);
%
% See also drawEdge
% See also
% drawEdge
%

% ---------
%
% author : David Legland
Expand Down Expand Up @@ -94,7 +96,7 @@
end
else
if abs(pos2)<abs(posr(i2)) && abs(pos2)<lines(il, 6)
if lines(i, 5) ~= posr(i2);
if lines(i, 5) ~= posr(i2)
edges(i, 3:4) = pi(il,:);
lines(i, 5) = posr(i2);
modif = 1;
Expand All @@ -106,13 +108,12 @@
end % end processing of right points of the line



% consider points to the left (negative position), and sort them
indl = find(pos<=0 && pos~=Inf);
[posl, indl2] = sort(abs(pos(indl)));

% look for the closest intersection to the right
for i2=1:length(indl2)
for i2 = 1:length(indl2)
% index of intersected line
il = indl(indl2(i2));

Expand All @@ -123,7 +124,7 @@
% stop the current line, or if it was stopped before
if pos2>0
if pos2<abs(posl(i2)) && pos2<lines(il, 5)
if lines(i, 6) ~= abs(posl(i2));
if lines(i, 6) ~= abs(posl(i2))
edges(i, 1:2) = pi(il, :);
lines(i, 6) = abs(posl(i2));
modif = 1;
Expand All @@ -132,7 +133,7 @@
end
else
if abs(pos2)<abs(posl(i2)) && abs(pos2)<lines(il, 6)
if lines(i, 6) ~= abs(posl(i2));
if lines(i, 6) ~= abs(posl(i2))
edges(i, 1:2) = pi(il, :);
lines(i, 6) = abs(posl(i2));
modif = 1;
Expand Down
4 changes: 2 additions & 2 deletions matGeom/geom2d/crackPattern2.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
% reach the intersection point.
NP = size(points, 1);
lines = zeros(0, 5);
for i=1:size(alpha, 2)
lines = [lines; points speed.*cos(alpha(:,i)) speed.*sin(alpha(:,i)) Inf*ones(NP, 1)];
for i = 1:size(alpha, 2)
lines = [lines; points speed.*cos(alpha(:,i)) speed.*sin(alpha(:,i)) Inf*ones(NP, 1)]; %#ok<AGROW>
end
NL = size(lines, 1);

Expand Down
23 changes: 11 additions & 12 deletions matGeom/geom2d/hexagonalGrid.m
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
function varargout = hexagonalGrid(bounds, origin, size, varargin)
%HEXAGONALGRID Generate hexagonal grid of points in the plane.
%
% usage
% usage:
% PTS = hexagonalGrid(BOUNDS, ORIGIN, SIZE)
% generate points, lying in the window defined by BOUNDS (=[xmin ymin
% xmax ymax]), starting from origin with a constant step equal to size.
Expand All @@ -10,18 +10,18 @@
%
% TODO: add possibility to use rotated grid
%

% ---------
%
% author : David Legland
% INRA - TPV URPOI - BIA IMASTE
% created the 06/08/2005.
%

size = size(1);
dx = 3*size;
dy = size*sqrt(3);



% consider two square grids with different centers
pts1 = squareGrid(bounds, origin + [0 0], [dx dy], varargin{:});
pts2 = squareGrid(bounds, origin + [dx/3 0], [dx dy], varargin{:});
Expand All @@ -32,11 +32,9 @@
pts = [pts1;pts2;pts3;pts4];




% eventually compute also edges, clipped by bounds
% TODO : manage generation of edges
if nargout>1
if nargout > 1
edges = zeros([0 4]);
x0 = origin(1);
y0 = origin(2);
Expand All @@ -55,34 +53,35 @@
ny = length(ly);
nx = length(lx);

if bounds(1)-x1+dx<size
if bounds(1)-x1+dx < size
disp('intersect bounding box');
end

if bounds(3)-x2<size
if bounds(3)-x2 < size
disp('intersect 2');
edges = [edges;repmat(x2, [ny 1]) ly repmat(bounds(3), [ny 1]) ly];
x2 = x2-dx;
lx = (x1:dx:x2)';
nx = length(lx);
end

for i=1:length(ly)
for i = 1:length(ly)
ind = (1:nx)';
tmpEdges = zeros(length(ind), 4);
tmpEdges(ind, 1) = lx;
tmpEdges(ind, 2) = ly(i);
tmpEdges(ind, 3) = lx+size;
tmpEdges(ind, 4) = ly(i);
edges = [edges; tmpEdges];
edges = [edges; tmpEdges]; %#ok<AGROW>
end

end

% process output arguments
if nargout>0
if nargout > 0
varargout{1} = pts;

if nargout>1
if nargout > 1
varargout{2} = edges;
end
end
4 changes: 2 additions & 2 deletions matGeom/geom3d/rotation3dAxisAndAngle.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function [axis, theta] = rotation3dAxisAndAngle(mat)
%ROTATION3DAXISANDANGLE Determine axis and angle of a 3D rotation matrix.
%ROTATION3DAXISANDANGLE Determine axis and angle of a 3D rotation matrix.
%
% [AXIS, ANGLE] = rotation3dAxisAndAngle(MAT)
% Where MAT is a 4-by-4 matrix representing a rotation, computes the
Expand Down Expand Up @@ -58,7 +58,7 @@

% try to get a point on the line
% seems to work, but not sure about stability
[V, D] = eig(mat-eye(4)); %#ok<NASGU>
[V, D] = eig(mat-eye(4)); %#ok<ASGLU>
origin = V(1:3,4)'/V(4, 4);

% create line corresponding to rotation axis
Expand Down
4 changes: 3 additions & 1 deletion matGeom/meshes3d/cutMeshByPlane.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
function varargout = cutMeshByPlane(v, f, plane, varargin)
%CUTMESHBYPLANE Cut a mesh by a plane.
%
% [ABOVE, IN, BELOW] = cutMeshByPlane(MESH, PLANE)
% where MESH, ABOVE, IN, BELOW are structs with the fields vertices and
% faces, and PLANE is given as a row containing initial point and 2
Expand All @@ -20,6 +21,7 @@
% [BELOW_V, BELOW_F] = cutMeshByPlane(MESH, PLANE, 'part', 'below') is
% possible, too.
%

% ---------
% Authors: oqilipo, David Legland
% Created: 2017-07-09
Expand All @@ -33,7 +35,7 @@
% If first argument is a struct
if nargin == 2 || nargin == 4
if ~isempty(varargin)
varargin={plane, varargin{:}};
varargin = [{plane}, varargin(:)'];
end
plane = f;
[v, f] = parseMeshData(v);
Expand Down

0 comments on commit db834f9

Please sign in to comment.