function [pSMinimum,pSMinimumCC]=calculateMinimumSegments(pS1,pS1CC,pS2,pS2CC,forwardBackward,precision)
% function [pSMinimum,pSMinimumCC]=calculateMinimumSegments(pS1,pS1CC,pS2,pS2CC,forwardBackward,precision)
%
% This function splits a sequence of segment defined by pS (and pSCC) in minimum subsegments given by the cuts
% of this sequence with all the segments given by other sequence of segment defined by pS2 (and pS2CC)
%
% Input parameters:
% pS1,pS1CC,pS2,pS2CC-> sequences of segments in 2D cartesian coordinates and in circular trajectory coordinates,
% it is a cell array of segments, each slot contains segments formed by pairs 2D column vectors
% representing the poits defining the segments
% forwardBackward-> it is a logical variable, when it is true the calculation
% considers that the robot is moving forward, if not it is considered that it moves
% backwards
% precision-> indicates the precision at which it is considered that points are inside a segment
%
% Output parameters:
% pSMinimum,pSMinimumCC-> sequence of segments in 2D cartesian coordinates and circular trajectory coordinates,
% they ara cell arrays of segments, each slot contains segments formed by pairs 2D column vectors
% representing the poits defining the segments. Sequence of minimum segments given by the cuts of segments
% defined by pS1 (and pS1CC) with all segments in pS2 (and pS2CC)
%
% Author: Antonio C. DomÃnguez Brito (adominguez@iusiani.ulpgc.es)
% Institution: SIANI-ULPGC (www.iusiani.ulpgc.es)
% Date: March 29th 2009
if isempty(pS1) | isempty(pS2)
pSMinimum=pS1; pSMinimumCC=pS1CC; return;
end
for segment=[1:size(pS1,2)]
pSMinimum{segment}=[]; pSMinimumCC{segment}=[];
for innerSegment=[1:2:size(pS1{segment},2)]
[pSSplit,pSSplitCC]=splitInMinimumSegments( ...
pS1{segment}(:,innerSegment),pS1CC{segment}(:,innerSegment), ...
pS1{segment}(:,innerSegment+1),pS1CC{segment}(:,innerSegment+1), ...
pS2,pS2CC, ...
forwardBackward, ...
precision ...
);
pSMinimum{segment}=[pSMinimum{segment} pSSplit];
pSMinimumCC{segment}=[pSMinimumCC{segment} pSSplitCC];
end
end
[pSMinimum,pSMinimumCC]=refineSegments(pSMinimum,pSMinimumCC,precision);
return;