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 /** Healpix-internal class for specifying locations on the sphere. 24 25 @copyright 2011 Max-Planck-Society 26 @author Martin Reinecke */ 27 final class Hploc 28 { 29 public double z, phi, sth; 30 public boolean have_sth; 31 32 /** Default constructor. */ Hploc()33 public Hploc() {} Hploc(Vec3 v)34 public Hploc (Vec3 v) 35 { 36 double xl = 1./v.length(); 37 z = v.z*xl; 38 phi = FastMath.atan2(v.y,v.x); 39 if (Math.abs(z)>0.99) 40 { 41 sth = Math.sqrt(v.x*v.x+v.y*v.y)*xl; 42 have_sth=true; 43 } 44 } Hploc(Zphi zphi)45 public Hploc (Zphi zphi) 46 { 47 z = zphi.z; 48 phi = zphi.phi; 49 have_sth=false; 50 } Hploc(Pointing ptg)51 public Hploc (Pointing ptg) throws Exception 52 { 53 HealpixUtils.check((ptg.theta>=0.)&&(ptg.theta<=Math.PI), 54 "invalid theta value"); 55 z = FastMath.cos(ptg.theta); 56 phi = ptg.phi; 57 if (Math.abs(z)>0.99) 58 { 59 sth = FastMath.sin(ptg.theta); 60 have_sth=true; 61 } 62 } 63 toZphi()64 public Zphi toZphi() 65 { return new Zphi(z,phi); } toPointing()66 public Pointing toPointing() 67 { 68 double st = have_sth ? sth : Math.sqrt((1.0-z)*(1.0+z)); 69 return new Pointing(FastMath.atan2(st,z),phi); 70 } toVec3()71 public Vec3 toVec3() 72 { 73 double st = have_sth ? sth : Math.sqrt((1.0-z)*(1.0+z)); 74 return new Vec3(st*FastMath.cos(phi),st*FastMath.sin(phi),z); 75 } 76 } 77