EDGETOPOLYLINE Convert an edge to a polyline with a given number of segments. POLY = edgeToPolyline(EDGE, N) Example edge = [10 20 60 40]; poly = edgeToPolyline(edge, 10); drawEdge(edge, 'lineWidth', 2); hold on drawPoint(poly); axis equal; See also edges2d, drawEdge, drawPolyline ------ Author: David Legland e-mail: david.legland@grignon.inra.fr Created: 2011-11-25, using Matlab 7.9.0.529 (R2009b) Copyright 2011 INRA - Cepia Software Platform.
0001 function poly = edgeToPolyline(edge, N) 0002 %EDGETOPOLYLINE Convert an edge to a polyline with a given number of segments. 0003 % 0004 % POLY = edgeToPolyline(EDGE, N) 0005 % 0006 % Example 0007 % edge = [10 20 60 40]; 0008 % poly = edgeToPolyline(edge, 10); 0009 % drawEdge(edge, 'lineWidth', 2); 0010 % hold on 0011 % drawPoint(poly); 0012 % axis equal; 0013 % 0014 % See also 0015 % edges2d, drawEdge, drawPolyline 0016 % 0017 % ------ 0018 % Author: David Legland 0019 % e-mail: david.legland@grignon.inra.fr 0020 % Created: 2011-11-25, using Matlab 7.9.0.529 (R2009b) 0021 % Copyright 2011 INRA - Cepia Software Platform. 0022 0023 if N < 1 0024 error('number of segments must be greater than 1'); 0025 end 0026 0027 0028 if length(edge) == 4 0029 % case of planar edges 0030 p1 = edge(1:2); 0031 p2 = edge(3:4); 0032 poly = [linspace(p1(1), p2(1), N+1)' linspace(p1(2), p2(2), N+1)']; 0033 0034 else 0035 % case of 3D edges 0036 p1 = edge(1:3); 0037 p2 = edge(4:6); 0038 poly = [... 0039 linspace(p1(1), p2(1), N+1)' ... 0040 linspace(p1(2), p2(2), N+1)' ... 0041 linspace(p1(3), p2(3), N+1)']; 0042 end