• Main Page
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

/export/development/ViennaGrid/release/ViennaGrid-1.0.0/viennagrid/algorithm/cross_prod.hpp

Go to the documentation of this file.
00001 #ifndef VIENNAGRID_ALGORITHM_CROSS_PROD_HPP
00002 #define VIENNAGRID_ALGORITHM_CROSS_PROD_HPP
00003 
00004 /* =======================================================================
00005    Copyright (c) 2011, Institute for Microelectronics,
00006                        Institute for Analysis and Scientific Computing,
00007                        TU Wien.
00008 
00009                             -----------------
00010                      ViennaGrid - The Vienna Grid Library
00011                             -----------------
00012 
00013    Authors:      Karl Rupp                           rupp@iue.tuwien.ac.at
00014                  Josef Weinbub                    weinbub@iue.tuwien.ac.at
00015                
00016    (A list of additional contributors can be found in the PDF manual)
00017 
00018    License:      MIT (X11), see file LICENSE in the base directory
00019 ======================================================================= */
00020 
00021 #include "viennagrid/forwards.h"
00022 #include "viennagrid/traits/point.hpp"
00023 #include "viennagrid/point.hpp"
00024 
00029 namespace viennagrid
00030 {
00031 
00032   namespace detail
00033   {
00035     template <typename PointType,
00036               long dim = traits::dimension<PointType>::value>
00037     struct cross_prod_impl;
00038     
00039     
00040     //for compatibility in 1d:
00042     template <typename PointType>
00043     struct cross_prod_impl<PointType, 1>
00044     {
00045       static PointType apply(PointType const & p1,
00046                             PointType const & p2)
00047       {
00048         return PointType(0);
00049       }
00050     };
00051     
00052     //for compatibility in 2d:
00054     template <typename PointType>
00055     struct cross_prod_impl<PointType, 2>
00056     {
00057       static PointType apply(PointType,
00058                             PointType)
00059       {
00060         return PointType(0,0);
00061       }
00062     };
00063     
00065     template <typename PointType>
00066     struct cross_prod_impl<PointType, 3>
00067     {
00068       static PointType apply(PointType const & p1,
00069                             PointType const & p2)
00070       {
00071         return PointType(p1[1]*p2[2]-p1[2]*p2[1], 
00072                         p1[2]*p2[0]-p1[0]*p2[2],
00073                         p1[0]*p2[1]-p1[1]*p2[0]);
00074       }
00075     };
00076   }
00077   
00079   template<typename PointType1, typename PointType2, typename CSystem1, typename CSystem2>
00080   PointType1
00081   cross_prod_impl(PointType1 const & p1, PointType2 const & p2, CSystem1 const &, CSystem2 const &)
00082   {
00083     typedef typename traits::value_type<PointType1>::type    value_type;
00084     typedef typename result_of::cartesian_point<PointType1>::type   CartesianPoint1;
00085     
00086     return detail::cross_prod_impl<CartesianPoint1>::apply(to_cartesian(p1), to_cartesian(p2));
00087   }
00088 
00090   template<typename PointType1, typename PointType2, long d>
00091   PointType1
00092   cross_prod_impl(PointType1 const & p1, PointType2 const & p2, cartesian_cs<d>, cartesian_cs<d>)
00093   {
00094     return detail::cross_prod_impl<PointType1>::apply(p1, p2);
00095   }
00096 
00102   template<typename PointType1, typename PointType2>
00103   PointType1
00104   cross_prod(PointType1 const& v1, PointType2 const& v2)
00105   {
00106     return cross_prod_impl(v1,
00107                            v2,
00108                            typename traits::coordinate_system<PointType1>::type(),
00109                            typename traits::coordinate_system<PointType2>::type());
00110   }
00111 
00112 } 
00113 
00114 #endif

Generated on Wed Sep 14 2011 19:21:30 for ViennaGrid by  doxygen 1.7.1