  function [p,N] = StereogrphicProj(q,ToPlane)



  if ~ToPlane

  r = 2;
  n = size ( q, 2 );

  e(1,1:n) = q(1,1:n).^2 + q(2,1:n).^2;

  p = zeros ( 3, n );
  p(1,1:n) = 2 * q(1,1:n)      ./ ( 1 + e(1,1:n) );
  p(2,1:n) = 2 * q(2,1:n)      ./ ( 1 + e(1,1:n) );
  p(3,1:n) = ( -1 + e(1,1:n) ) ./ ( 1 + e(1,1:n) );


  hold on;
  %plot3(e(1,:),e(2,:),-1*ones(1,n),'r*');
  %plot3(p(1,:),p(2,:),p(3,:),'-o','MarkerSize',10)


  N = sqrt(p(1,:).^2 + p(2,:).^2 + p(3,:).^2);

  elseif ToPlane

  x = q(1,:);
  y = q(2,:);
  z = q(3,:);

  px = x./(1-z);
  py = y./(1-z);
  
  p = [px; py];

  end


