////////|n|No Unit|2|1|100
/***********************************************************************************
* Name:         LED and other high NA sources - for Programmable Mode Planar Source
* Description:  Customized Mode (cos^n) for LED Source Models
                The given formula numbers refer to the ReadMe.
* Authors:      Michael Kuhn, LightTrans GmbH
* Keywords:     Programmable Mode Planar Source, LED, Lambertian, High NA
* Version:      2.0 (Jan 08, 2014)
* License:      Some Rights reserved, CC-BY 3.0
***********************************************************************************/

// model only valid for a distance > 0.
if(Math.Abs(Distance) == 0){
   return new Complex(0,0);
}

double sx, sy, sz, r;

r = Math.Sqrt(x*x+y*y+Distance*Distance);
sx = x / r;
sy = y / r;
sz = Distance / r;

// formula 3
Complex sum = sx*Jx + sy*Jy;
double a = Math.Pow(sz, n/2) / Math.Sqrt( RefractiveIndex.Re * (sz*sz + sum.Abs()*sum.Abs() ) ) ;

// formula 4
Complex result = - Complex.i * sz * Distance * a;
if(r>0){
  result = result / r;
}

return result;
