function [intersections]=calcIntersections(A,B,xas)
C=A-B;
%% intersections between the profiles
% At this place the intersections between the two profiles are being
% calculated, the intersection point can be found in a matrix called
% reduced_matrix_intersections_A_and_B [x-value; y-value]
%

for j=1:(size(A(1,:),2)-1);
    if C(j)==0; 
        x_intersect(j)=xas(j);
        y_intersect(j)=A(1,j);
    end
    if C(j)*C(j+1)>0; 
                    x_intersect(j)=0;
                    y_intersect(j)=0;
    end
    if C(j)*C(j+1)<=0; %interpolation
        if min(abs(A(1,j)-B(1,j)))||min(abs(A(1,j+1)-B(1,j+1)))>=0.0005;
            parts=5;
            dj=(xas(j+1)-xas(j))/parts;
            k=[1:1:parts];
                for m=1:parts;
                    z_A(m)=dj*k(m)*((A(1,j+1)-A(1,j))/(xas(j+1)-xas(j)))+A(1,j);
                    z_B(m)=dj*k(m)*((B(1,j+1)-B(1,j))/(xas(j+1)-xas(j)))+B(1,j);
                end
            [error_crossing x_intersection_crossing]=min(abs(z_A-z_B));
            x_intersect(j)=x_intersection_crossing*dj + xas(j);
            y_intersect(j)=x_intersection_crossing*dj*((A(1,j+1)-A(1,j))/(xas(j+1)-xas(j)))+A(1,j);
        end
    end
end
        
        x_intersections_all=x_intersect>0;
    x_intersections=x_intersect(x_intersections_all);
        y_intersections_all=x_intersect>0;
    y_intersections=y_intersect(y_intersections_all);
intersections=[x_intersections;y_intersections];