% function [ok, par] = x_plane_line( p, u, v, p1, p2 )
% Compute intersection parameters of a plane and lines.
% In:
%   p .. plane point
%   u, v .. plane direction vectors
%   p1 .. line start point (column) list
%   p2 .. line end point (column) list
% Out:
%   ok .. intersection indicator
%   par .. intersection parameters
function [ok, par] = x_plane_line( p, u, v, p1, p2 )
  
  np = size( p1, 2 );
  ok = repmat( 2, np, 1 );
  par = repmat( -1, 3, np );
  for i = 1:np
    a = [p1(:,i) - p2(:,i), u(:), v(:)];
    ok(i) = 2 * ~(rank( a ) == 3);
    if (~ok(i))
      par(:,i) = a \ [p1(:,i) - p(:)];
    else
      a = [p1(:,i) - p(:), u(:), v(:)];
      ok(i) = ok(i) - (rank( a ) < 3);
    end
  end
