
283Implicit Parallelization (Vectorization and Indexing)
%...Transpose and prepare for output
i=i'; dx2=dx2'; dy2=dy2'; S2 = S2';
L = dy2(j).*dx1(i) - dy1(i).*dx2(j);
i=i(L~=0); j=j(L~=0); L=L(L~=0); %...Avoid divisions by 0
%...Solve system of eqs to get the common points
P = unique([dx2(j).*S1(i) - dx1(i).*S2(j),...
dy2(j).*S1(i) - dy1(i).*S2(j)]./[L L],'rows')';
function u = D(x,y)
u = bsxfun(,1:end-1),y).*bsxfun(,2:end),y);
end
The usage, as shown in the utility’s help section, is as follows:
t = linspace(0,2*pi);
r1 = sin(4*t)+2;
x1 = r1.*cos(t);
y1 = r1.*sin(t);
r2 = sin(8*t)+2;
x2 = r2.*cos(t);
y2 = r2.*sin(t);