49 template<
typename floatT>
52 return static_cast<floatT
>(2.3548200450309493820231386529193992754947713787716);
64 template<
typename floatT>
67 return fw / twosqrt2log2<floatT>();
79 template<
typename floatT>
82 return sig*twosqrt2log2<floatT>();
99 template<
typename realT>
107 return G0 +
G * exp( -(
static_cast<realT
>(0.5)/(
sigma*
sigma) * ( ( (x-x0)*(x-x0))) ));
126 template<
typename realT>
136 return G0 +
G*std::exp( -( 0.5/(
sigma*
sigma) * ( ( (x-x0)*(x-x0)) + ((y-y0)*(y-y0))) ));
149 template<
typename realT>
162 for(
size_t j=0;j<ny; ++j)
164 for(
size_t i=0;i<nx; ++i)
202 template<
typename realT>
217 return G0 +
G*std::exp( -0.5* ( a*dx*dx + 2.*b*dx*dy +
c*dy*dy));
244 template<
typename realT>
253 realT x1, x2, s, s2, theta0, theta1;
255 realT arg = a*a - 2*a*
c + 4*b*b +
c*
c;
264 x2 = 0.5*(a +
c) + 0.5*sqrt(arg);
265 x1 = 0.5*(a +
c) - 0.5*sqrt(arg);
269 sigma_x = sqrt(1./x1);
270 sigma_y = sqrt(1./x2);
280 s = (a-x1)*(a-x1)/(b*b + (a-x1)*(a-x1));
284 if(fabs(x1-x2) < 1e-12)
290 theta0 = 0.5*asin( 2*b/(x1-x2));
291 theta1 = asin(sqrt(s));
294 if( std::signbit(theta0) == std::signbit(theta1))
301 theta = asin(-sqrt(s));
327 template<
typename realT>
336 realT sn,cs, sx2, sy2;
340 sx2 = sigma_x * sigma_x;
341 sy2 = sigma_y * sigma_y;
343 a = cs*cs/sx2 + sn*sn/sy2;
344 b = sn*cs*(1./sx2-1./sy2);
345 c = sn*sn/sx2 + cs*cs/sy2;
375 template<
typename realT>
419 template<
typename realT>
434 for(
size_t j=0;j<ny; ++j)
436 for(
size_t i=0;i<nx; ++i)
440 arr[idx] =
gaussian2D((realT) i, (realT) j,G0,
G, x0, y0, a, b,
c);
472 template<
typename realT>
534 template<
typename realT>
546 realT G_G0 = gaussian2D<realT>(x, y, 0,
G, x0, y0, a, b ,
c);
552 j[2] = 0.5*G_G0 * ( 2*a*(x-x0) + b*(y-y0));
554 j[3] = 0.5*G_G0 * ( b*(x-x0) + 2*
c*(y-y0));
556 j[4] = -0.5*G_G0 * ( (x-x0)*(x-x0) );
558 j[5] = -0.5*G_G0 * ( (x-x0)*(y-y0) );
560 j[6] = -0.5*G_G0 * ( (y-y0)*(y-y0) );
constexpr units::realT G()
Newton's Gravitational Constant.
constexpr units::realT c()
The speed of light.
constexpr units::realT sigma()
Stefan-Boltzmann Constant.
floatT sigma2fwhm(floatT sig)
Convert from Gaussian width parameter to FWHM.
floatT fwhm2sigma(floatT fw)
Convert from FWHM to the Gaussian width parameter.
realT gaussian(const realT x, const realT G0, const realT G, const realT x0, const realT sigma)
Find value at position (x) of the 1D arbitrarily-centered symmetric Gaussian.
void gaussian2D(realT *arr, size_t nx, size_t ny, const realT G0, const realT G, const realT x0, const realT y0, const realT a, const realT b, const realT c)
Fill in an array with the 2D general elliptical Gaussian.
void gaussian2D_gen2rot(realT &sigma_x, realT &sigma_y, realT &theta, const realT a, const realT b, const realT c)
Convert from (a,b,c) to ( , , ) for the elliptical Gaussian.
void gaussian2D_jacobian(realT *j, const realT x, const realT y, const realT G0, const realT G, const realT x0, const realT y0, const realT a, const realT b, const realT c)
Calculate the Jacobian at position (x,y) for the 2D general elliptical Gaussian.
constexpr floatT twosqrt2log2()
Constant to convert between the Gaussian width parameter and FWHM.
void gaussian2D_rot2gen(realT &a, realT &b, realT &c, const realT sigma_x, const realT sigma_y, const realT theta)
Convert from ( , , ) to (a,b,c) for the elliptical Gaussian.
void gaussian2D_ang(realT *arr, size_t nx, size_t ny, const realT G0, const realT G, const realT x0, const realT y0, const realT sigma_x, const realT sigma_y, const realT theta)
Fill in an array with the 2D general elliptical Gaussian.