function [U,V] = calBRF(P)
%
% Purpose : computation of the RF field induced by the ball
% 
% Arguments  in : 
%  P : coordinates of the voxel  in the frame (C,nr,np,ns)
%
% Arguments  out :
% U : cosinus components of the RF induced field in the laboratory frame
% V : sinus components
%
% ARAMIS - (c) S. Balac - ENSSAT - Université de Rennes 1 - 2007 (version 2.0)
%

global r0;  % Radius of the sphere
global delta;
global B1;
global nr; global np; global ns; global C;

rho = sqrt(P'*P);
if rho<r0 % we compute the field inside the sphere
  U=[0,0,0];
  V=[0,0,0];
else     % we compute the field outside the sphere
  CP=P(1)*nr+P(2)*np+P(3)*ns;
  x=C(1)+CP(1);
  y=C(2)+CP(2);
  z=C(3)+CP(3);
  U(1) = r0^3*(3*B1*x^2/rho^5 - B1/rho^3);
  U(2) = 3*r0^3*B1*x*y/rho^5;
%  U(3) = 3*r0^3*B1*x*z/rho^5;
  U(3) = 0;% assumed to be negligible compair to B0 in the following
  V(1) = 3*r0^3*B1*x*y/rho^5;
  V(2) = r0^3*(3*B1*y^2/rho^5 - B1/rho^3);
%  V(3) = 3*r0^3*B1*y*z/rho^5;
   V(3) = 0 ;% assumed to be negligible compair to B0 in the following
end

