% function [xp] = get_x_point( p1, p2, ok, par )
% Compute intersection points from intersection parameters.
% In:
%   p1 .. line start point (column) list
%   p2 .. line end point (column) list
%   ok .. intersection indicator
%   par .. intersection parameters
% Out:
%   xp .. intersection points
function [xp] = get_x_point( p1, p2, ok, par )
  
  nxp = sum( ((par(1,:) >= 0.0) & (par(1,:) <= 1.0)) ) + 2 * sum( (ok == 1) );
  xp = zeros( 3, nxp );
  j = 1;
  for i = 1:length( ok )
    if (~ok(i) & (par(1,i) >= 0.0) & (par(1,i) <= 1.0))
      xp(:,j) = p1(:,i) + par(1,i) * (p2(:,i) - p1(:,i));
      j = j + 1;
    elseif (ok == 1)
      xp(:,j) = p1(:,i);
      j = j + 1;
      xp(:,j) = p2(:,i);
      j = j + 1;
    end
  end
