CVR-Lib last update 20 Sep 2009

cvrConstants.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 1998 - 2004
00003  * Lehrstuhl fuer Technische Informatik, RWTH-Aachen, Germany
00004  *
00005  *
00006  * This file is part of the Computer Vision and Robotics Library (CVR-Lib)
00007  *
00008  * The CVR-Lib is free software; you can redistribute it and/or
00009  * modify it under the terms of the BSD License.
00010  *
00011  * All rights reserved.
00012  *
00013  * Redistribution and use in source and binary forms, with or without
00014  * modification, are permitted provided that the following conditions are met:
00015  *
00016  * 1. Redistributions of source code must retain the above copyright notice,
00017  *    this list of conditions and the following disclaimer.
00018  *
00019  * 2. Redistributions in binary form must reproduce the above copyright notice,
00020  *    this list of conditions and the following disclaimer in the documentation
00021  *    and/or other materials provided with the distribution.
00022  *
00023  * 3. Neither the name of the authors nor the names of its contributors may be
00024  *    used to endorse or promote products derived from this software without
00025  *    specific prior written permission.
00026  *
00027  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00028  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00029  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00030  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00031  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00032  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00033  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00034  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00035  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00036  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00037  * POSSIBILITY OF SUCH DAMAGE.
00038  */
00039 
00040 
00041 
00042 /**
00043  * \file   cvrConstants.h
00044  *         Definition of some often needed mathematical constants as
00045  *         static member functions of a template class: pi(), twoPi(),
00046  *         halfPi(), e(), and sqrt2().
00047  * \author Pablo Alvarado
00048  * \date   16.05.2001
00049  *
00050  * $Id: cvrConstants.h,v 1.3 2005/01/03 16:17:50 alvarado Exp $
00051  */
00052 
00053 #ifndef _CVR_CONSTANTS_H_
00054 #define _CVR_CONSTANTS_H_
00055 
00056 namespace cvr {
00057 
00058   /**
00059    * This class is a container of some mathematical and physical
00060    * constants as static member functions.
00061    *
00062    * Example:
00063    * \code
00064    * constants<float>::pi();
00065    * \endcode
00066    */
00067   template<class T>
00068   class constants {
00069   public:
00070     /**
00071      * Pi
00072      */
00073     static inline const T pi() throw() {
00074       return static_cast<T>(3.1415926535897932384626433832795);
00075     };
00076 
00077     /**
00078      * Twice Pi (2*pi())
00079      */
00080     static inline const T twoPi() throw() {
00081       return static_cast<T>(3.1415926535897932384626433832795*2.0);
00082     };
00083 
00084     /**
00085      * Half Pi (pi()/2)
00086      */
00087     static inline const T halfPi() throw() {
00088       return static_cast<T>(3.1415926535897932384626433832795/2.0);
00089     };
00090 
00091     /**
00092      * e (basis of natural logarithm) = 2.7182818284590452353602874713526...
00093      */
00094     static inline const T e() throw() {
00095       return static_cast<T>(2.7182818284590452353602874713526);
00096       // continuing with ... 62497757247093699959574966967627724076630353547594571382178525166427427466391932003059921817413596629043572900334295260
00097       // more at http://sources.wikipedia.org/wiki/E_to_10%2C000_places
00098     };
00099 
00100     /**
00101      * square root of 2 = 1.4142135623730950488016887242097...
00102      */
00103     static inline const T sqrt2() throw() {
00104       return static_cast<T>(1.4142135623730950488016887242097);
00105     };
00106 
00107   private:
00108     /**
00109      * Private constructor avoids the creation of
00110      * an instance of this class.
00111      */
00112     constants() {};
00113   };
00114 }
00115 
00116 
00117 #endif
00118 

Generated on Sun Sep 20 22:07:59 2009 for CVR-Lib by Doxygen 1.5.8