/** * Return the inverse of healpix_sphere(). **/ LP healpix_sphere_inverse(XY xy) { LP lp; double x = xy.x; double y = xy.y; double y0 = M_PI/4.0; /* Equatorial region. */ if (fabsl(y) <= y0) { lp.lam = x; lp.phi = asin(8.0*y/(3.0*M_PI)); } else if (fabsl(y) < M_PI/2.0) { double cn = floor(2.0*x/M_PI + 2.0); double xc, tau; if (cn >= 4) { cn = 3; } xc = -3.0*M_PI/4.0 + (M_PI/2.0)*cn; tau = 2.0 - 4.0*fabsl(y)/M_PI; lp.lam = xc + (x - xc)/tau; lp.phi = pj_sign(y)*asin(1.0 - pow(tau , 2.0)/3.0); } else { lp.lam = -1.0*M_PI; lp.phi = pj_sign(y)*M_PI/2.0; } return (lp); }
inline void healpix_sphere_inverse(T const& xy_x, T const& xy_y, T& lp_lam, T& lp_phi) { static const T pi = detail::pi<T>(); static const T half_pi = detail::half_pi<T>(); static const T fourth_pi = detail::fourth_pi<T>(); T x = xy_x; T y = xy_y; T y0 = fourth_pi; /* Equatorial region. */ if (math::abs(y) <= y0) { lp_lam = x; lp_phi = asin(8.0*y/(3.0*pi)); } else if (fabsl(y) < half_pi) { T cn = floor(2.0*x/pi + 2.0); T xc, tau; if (cn >= 4) { cn = 3; } xc = -3.0*fourth_pi + (half_pi)*cn; tau = 2.0 - 4.0*fabsl(y)/pi; lp_lam = xc + (x - xc)/tau; lp_phi = pj_sign(y)*asin(1.0 - math::pow(tau, 2)/3.0); } else { lp_lam = -1.0*pi; lp_phi = pj_sign(y)*half_pi; } return; }
inline void healpix_sphere(T const& lp_lam, T const& lp_phi, T& xy_x, T& xy_y) { static const T pi = detail::pi<T>(); static const T half_pi = detail::half_pi<T>(); static const T fourth_pi = detail::fourth_pi<T>(); T lam = lp_lam; T phi = lp_phi; T phi0 = asin(T(2.0)/T(3.0)); /* equatorial region */ if ( fabsl(phi) <= phi0) { xy_x = lam; xy_y = 3.0*pi/8.0*sin(phi); } else { T lamc; T sigma = sqrt(3.0*(1 - math::abs(sin(phi)))); T cn = floor(2*lam / pi + 2); if (cn >= 4) { cn = 3; } lamc = -3*fourth_pi + half_pi*cn; xy_x = lamc + (lam - lamc)*sigma; xy_y = pj_sign(phi)*fourth_pi*(2 - sigma); } return; }
/** * Return the authalic latitude of latitude alpha (if inverse=0) or * return the approximate latitude of authalic latitude alpha (if inverse=1). * P contains the relavent ellipsoid parameters. **/ double auth_lat(PJ *P, double alpha, int inverse) { if (inverse == 0) { /* Authalic latitude. */ double q = pj_qsfn(sin(alpha), P->e, 1.0 - P->es); double qp = P->qp; double ratio = q/qp; if (fabsl(ratio) > 1) { /* Rounding error. */ ratio = pj_sign(ratio); } return asin(ratio); } else { /* Approximation to inverse authalic latitude. */ return pj_authlat(alpha, P->apa); } }
inline T auth_lat(const Parameters& par, const par_healpix<T>& proj_parm, T const& alpha, int inverse) { if (inverse == 0) { /* Authalic latitude. */ T q = pj_qsfn(sin(alpha), par.e, 1.0 - par.es); T qp = proj_parm.qp; T ratio = q/qp; if (math::abs(ratio) > 1) { /* Rounding error. */ ratio = pj_sign(ratio); } return asin(ratio); } else { /* Approximation to inverse authalic latitude. */ return pj_authlat(alpha, proj_parm.apa); } }
/** * Return the HEALPix projection of the longitude-latitude point lp on * the unit sphere. **/ XY healpix_sphere(LP lp) { double lam = lp.lam; double phi = lp.phi; double phi0 = asin(2.0/3.0); XY xy; /* equatorial region */ if ( fabsl(phi) <= phi0) { xy.x = lam; xy.y = 3.0*PI/8.0*sin(phi); } else { double lamc; double sigma = sqrt(3.0*(1 - fabsl(sin(phi)))); double cn = floor(2*lam / PI + 2); if (cn >= 4) { cn = 3; } lamc = -3*PI/4 + (PI/2)*cn; xy.x = lamc + (lam - lamc)*sigma; xy.y = pj_sign(phi)*PI/4*(2 - sigma); } return xy; }