00001 /* 00002 * This file is part of libcxxsupport. 00003 * 00004 * libcxxsupport is free software; you can redistribute it and/or modify 00005 * it under the terms of the GNU General Public License as published by 00006 * the Free Software Foundation; either version 2 of the License, or 00007 * (at your option) any later version. 00008 * 00009 * libcxxsupport is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with libcxxsupport; if not, write to the Free Software 00016 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00017 */ 00018 00019 /* 00020 * libcxxsupport is being developed at the Max-Planck-Institut fuer Astrophysik 00021 * and financially supported by the Deutsches Zentrum fuer Luft- und Raumfahrt 00022 * (DLR). 00023 */ 00024 00025 /*! \file geom_utils.h 00026 * Geometric utility functions. 00027 * 00028 * Copyright (C) 2003-2011 Max-Planck-Society 00029 * \author Martin Reinecke 00030 * \author Reinhard Hell 00031 */ 00032 00033 #ifndef PLANCK_GEOM_UTILS_H 00034 #define PLANCK_GEOM_UTILS_H 00035 00036 #include "math_utils.h" 00037 #include "vec3.h" 00038 00039 template<typename T> class arr; 00040 00041 /*! Returns the orientation when looking from point \a loc on the unit 00042 sphere in the direction \a dir. \a loc must be normalized. The result 00043 ranges from -pi to pi, is 0 for North and pi/2 for West, i.e. the angle 00044 is given in mathematically positive sense. 00045 00046 If \a loc is the North or South pole, the returned angle is 00047 \a atan2(dir.y,dir.x). */ 00048 inline double orientation (const vec3 &loc, const vec3 &dir) 00049 { 00050 // FIXME: here is still optimization potential 00051 if (loc.x==0 && loc.y==0) 00052 return (loc.z>0) ? safe_atan2(dir.y,-dir.x) : safe_atan2(dir.y,dir.x); 00053 vec3 east (-loc.y, loc.x, 0); 00054 vec3 north = crossprod(loc,east); 00055 return safe_atan2(-dotprod(dir,east),dotprod(dir,north)); 00056 } 00057 00058 /*! Returns the angle between \a v1 and \a v2 in radians. */ 00059 inline double v_angle (const vec3 &v1, const vec3 &v2) 00060 { 00061 using namespace std; 00062 return atan2 (crossprod(v1,v2).Length(), dotprod(v1,v2)); 00063 } 00064 00065 /*! Returns the cosine of the angle between the two points on the sphere defined 00066 by (\a z1, \a phi1) and (\a z2, \a phi2), respectively. \a z is the cosine 00067 of the colatitude, and \a phi is the longitude. */ 00068 inline double cosdist_zphi (double z1, double phi1, double z2, double phi2) 00069 { 00070 using namespace std; 00071 return z1*z2+cos(phi1-phi2)*sqrt((1.-z1*z1)*(1.-z2*z2)); 00072 } 00073 00074 /*! Finds the smallest enclosing cone for a point set on the sphere according to 00075 Barequet & Elber: Information Processing Letters 93(2005), p.83. 00076 All points are expected to be passed as unit vectors. 00077 The enclosing cone must have an opening angle <pi/2. */ 00078 void find_enclosing_circle (const arr<vec3> &point, vec3 ¢er, 00079 double &cosrad); 00080 00081 #endif