1 /*
2  *  This file is part of Healpix Java.
3  *
4  *  This code is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; either version 2 of the License, or
7  *  (at your option) any later version.
8  *
9  *  This code is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with this code; if not, write to the Free Software
16  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17  *
18  *  For more information about HEALPix, see http://healpix.sourceforge.net
19  */
20 
21 package healpix.essentials;
22 
23 /** Class describing a location on the sphere
24 
25     @copyright 2012 Max-Planck-Society
26     @author Martin Reinecke */
27 public final class Fxyf extends HealpixTables
28   {
29   /** x-coordinate within the basis pixel, range [0.0;1.0] */
30   public double fx;
31   /** y-coordinate within the basis pixel, range [0.0;1.0] */
32   public double fy;
33   /** index of the HEALPix basis pixel, range [0;11] */
34   public int face;
Fxyf(double x, double y, int f)35   public Fxyf (double x, double y, int f)
36     { fx=x; fy=y; face=f; }
37 
Fxyf(Hploc loc)38   protected Fxyf(Hploc loc)
39     {
40     double z=loc.z, phi=loc.phi;
41 
42     double za = Math.abs(z);
43     double tt = HealpixUtils.fmodulo((phi*Constants.inv_halfpi),4.0);// in [0,4)
44 
45     if (za<=Constants.twothird) // Equatorial region
46       {
47       double temp1 = 0.5+tt;
48       double temp2 = z*0.75;
49       double jp = temp1-temp2; // index of  ascending edge line
50       double jm = temp1+temp2; // index of descending edge line
51       long ifp = (long)jp;  // in {0,4}
52       long ifm = (long)jm;
53       long face_num = (ifp==ifm) ? (ifp|4) : ((ifp<ifm) ? ifp : (ifm+8));
54       fx = HealpixUtils.fmodulo(jm,1.);
55       fy = 1.-HealpixUtils.fmodulo(jp,1.);
56       face = (int)face_num;
57       }
58     else // polar region, za > 2/3
59       {
60       int ntt = Math.min(3,(int)tt);
61       double tp = tt-ntt;
62       double tmp = ((za<0.99)||(!loc.have_sth)) ?
63                     Math.sqrt(3*(1-za)) :
64                     loc.sth/Math.sqrt((1.+za)/3.);
65 
66       double jp = tp*tmp; // increasing edge line index
67       double jm = (1.0-tp)*tmp; // decreasing edge line index
68       if (jp>=1.) jp = 1.; // for points too close to the boundary
69       if (jm>=1.) jm = 1.;
70       if (z>=0)
71         { fx=1.-jm; fy=1.-jp; face=ntt; }
72       else
73         { fx=jp; fy=jm; face=ntt+8; }
74       }
75     }
76 
Fxyf(Vec3 v)77   public Fxyf(Vec3 v)
78     { this(new Hploc(v)); }
79 
toHploc()80   protected Hploc toHploc()
81     {
82     Hploc loc = new Hploc();
83     double jr = jrll[face] - fx - fy;
84 
85     double nr;
86     if (jr<1)
87       {
88       nr = jr;
89       double tmp = nr*nr/3.;
90       loc.z = 1 - tmp;
91       if (loc.z>0.99) { loc.sth=Math.sqrt(tmp*(2.-tmp)); loc.have_sth=true; }
92       }
93     else if (jr>3)
94       {
95       nr = 4-jr;
96       double tmp = nr*nr/3.;
97       loc.z = tmp - 1;
98       if (loc.z<-0.99) { loc.sth=Math.sqrt(tmp*(2.-tmp)); loc.have_sth=true; }
99       }
100     else
101       {
102       nr = 1;
103       loc.z = (2-jr)*2./3.;
104       }
105 
106     double tmp=jpll[face]*nr+fx-fy;
107     if (tmp<0) tmp+=8;
108     if (tmp>=8) tmp-=8;
109     loc.phi = (nr<1e-15) ? 0 : (0.5*Constants.halfpi*tmp)/nr;
110     return loc;
111     }
toVec3()112   public Vec3 toVec3()
113     { return toHploc().toVec3(); }
114   }
115