Home > matGeom > geom2d > crackPattern2.m

crackPattern2

PURPOSE ^

CRACKPATTERN2 Create a (bounded) crack pattern tessellation.

SYNOPSIS ^

function edges = crackPattern2(box, points, alpha, varargin)

DESCRIPTION ^

CRACKPATTERN2 Create a (bounded) crack pattern tessellation.

   E = crackPattern2(BOX, POINTS, ALPHA)
   create a crack propagation pattern wit following parameters :
   - pattern is bounded by area BOX which is a polygon.
   - each crack originates from points given in POINTS
   - directions of each crack is given by a [NxM] array ALPHA, where M is
   the number of rays emanating from each seed/
   - a crack stop when it reaches another already created crack. 
   - all cracks stop when they reach the border of the frame, given by box
   (a serie of 4 points).
   The result is a collection of edges, in the form [x1 y1 x2 y2].

   E = crackPattern2(BOX, POINTS, ALPHA, SPEED)
   Also specify speed of propagation of each crack.


   See the result with :
     figure;
     drawEdge(E);

   See also drawEdge

   ---------

   author : David Legland
   INRA - TPV URPOI - BIA IMASTE
   created the 25/05/2004.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function edges = crackPattern2(box, points, alpha, varargin)
0002 %CRACKPATTERN2 Create a (bounded) crack pattern tessellation.
0003 %
0004 %   E = crackPattern2(BOX, POINTS, ALPHA)
0005 %   create a crack propagation pattern wit following parameters :
0006 %   - pattern is bounded by area BOX which is a polygon.
0007 %   - each crack originates from points given in POINTS
0008 %   - directions of each crack is given by a [NxM] array ALPHA, where M is
0009 %   the number of rays emanating from each seed/
0010 %   - a crack stop when it reaches another already created crack.
0011 %   - all cracks stop when they reach the border of the frame, given by box
0012 %   (a serie of 4 points).
0013 %   The result is a collection of edges, in the form [x1 y1 x2 y2].
0014 %
0015 %   E = crackPattern2(BOX, POINTS, ALPHA, SPEED)
0016 %   Also specify speed of propagation of each crack.
0017 %
0018 %
0019 %   See the result with :
0020 %     figure;
0021 %     drawEdge(E);
0022 %
0023 %   See also drawEdge
0024 %
0025 %   ---------
0026 %
0027 %   author : David Legland
0028 %   INRA - TPV URPOI - BIA IMASTE
0029 %   created the 25/05/2004.
0030 %
0031 
0032 %   HISTORY :
0033 
0034 if ~isempty(varargin)
0035     speed = varargin{1};
0036 else
0037     speed = ones(size(points, 1), 1);
0038 end
0039 
0040 % Compute line equations for each initial crack.
0041 % The 'Inf' at the end correspond to the position of the limit.
0042 % If an intersection point is found with another line, but whose position
0043 % is after this value, this means that another crack stopped it before it
0044 % reach the intersection point.
0045 NP = size(points, 1);
0046 lines = zeros(0, 5);
0047 for i = 1:size(alpha, 2)
0048     lines = [lines; points speed.*cos(alpha(:,i)) speed.*sin(alpha(:,i)) Inf*ones(NP, 1)]; %#ok<AGROW>
0049 end
0050 NL = size(lines, 1);
0051 
0052 % initialize lines for borders, but assign a very high speed, to be sure
0053 % borders will stop all cracks.
0054 dx = (box([2 3 4 1],1)-box([1 2 3 4],1))*max(speed)*5;
0055 dy = (box([2 3 4 1],2)-box([1 2 3 4],2))*max(speed)*5;
0056 
0057 % add borders to the lines set
0058 lines = [lines ; createLine(box, dx, dy) Inf*ones(4,1)];
0059 
0060 edges = zeros(0, 4);
0061 
0062 
0063 while true    
0064     modif = 0;
0065     
0066     % try to update each line
0067     for i=1:NL
0068         
0069         % initialize first point of edge
0070         edges(i, 1:2) = lines(i, 1:2);
0071         
0072         % compute intersections with all other lines
0073         pi = intersectLines(lines(i,:), lines);
0074         
0075         % compute position of all intersection points on the current line
0076         pos = linePosition(pi, lines(i,:));
0077         
0078                 
0079         % consider points to the right (positive position), and sort them
0080         indr = find(pos>1e-12 & pos~=Inf);
0081         [posr, indr2] = sort(pos(indr));
0082         
0083         
0084         % look for the closest intersection to the right
0085         for i2=1:length(indr2)
0086             
0087             % index of intersected line
0088             il = indr(indr2(i2));
0089 
0090             % position of point relative to intersected line
0091             pos2 = linePosition(pi(il, :), lines(il, :));
0092             
0093             % depending on the sign of position, tests if the line2 can
0094             % stop the current line, or if it was stopped before
0095             if pos2>0
0096                 if pos2<abs(posr(i2)) && pos2<lines(il, 5)
0097                     if lines(i, 5) ~= posr(i2)
0098                         edges(i, 3:4) = pi(il,:);
0099                         lines(i, 5) = posr(i2); 
0100                         modif = 1;
0101                     end                                                           
0102                     break;
0103                 end
0104             end
0105         end   % end processing of right points of the line
0106               
0107         
0108     end % end processing of all lines
0109     
0110     % break the infinite loop if no more modification was made
0111     if ~modif
0112         break;
0113     end
0114 end
0115 
0116 % add edges of the surronding box.
0117 edges = [edges ; box(1,:) box(2,:) ; box(2,:) box(3,:); ...
0118                  box(3,:) box(4,:) ; box(4,:) box(1,:)  ];
0119

Generated on Wed 16-Feb-2022 15:10:47 by m2html © 2003-2019