ViennaGrid - The Vienna Grid Library
2.1.0
|
00001 #ifndef VIENNAGRID_ALGORITHM_CROSS_PROD_HPP 00002 #define VIENNAGRID_ALGORITHM_CROSS_PROD_HPP 00003 00004 /* ======================================================================= 00005 Copyright (c) 2011-2014, Institute for Microelectronics, 00006 Institute for Analysis and Scientific Computing, 00007 TU Wien. 00008 00009 ----------------- 00010 ViennaGrid - The Vienna Grid Library 00011 ----------------- 00012 00013 License: MIT (X11), see file LICENSE in the base directory 00014 ======================================================================= */ 00015 00016 #include "viennagrid/forwards.hpp" 00017 #include "viennagrid/point.hpp" 00018 00023 namespace viennagrid 00024 { 00025 00026 namespace detail 00027 { 00029 template <typename PointT, 00030 long dim = viennagrid::result_of::dimension<PointT>::value> 00031 struct cross_prod_impl; 00032 00033 00034 //for compatibility in 1d: 00036 template <typename PointT> 00037 struct cross_prod_impl<PointT, 1> 00038 { 00039 static PointT apply(PointT const &, 00040 PointT const &) 00041 { 00042 return PointT(0); 00043 } 00044 }; 00045 00046 //for compatibility in 2d: 00048 template <typename PointT> 00049 struct cross_prod_impl<PointT, 2> 00050 { 00051 static PointT apply(PointT, 00052 PointT) 00053 { 00054 return PointT(0,0); 00055 } 00056 }; 00057 00059 template <typename PointT> 00060 struct cross_prod_impl<PointT, 3> 00061 { 00062 static PointT apply(PointT const & p1, 00063 PointT const & p2) 00064 { 00065 return PointT(p1[1]*p2[2]-p1[2]*p2[1], 00066 p1[2]*p2[0]-p1[0]*p2[2], 00067 p1[0]*p2[1]-p1[1]*p2[0]); 00068 } 00069 }; 00070 } 00071 00073 template<typename PointT1, typename PointT2, typename CSystem1, typename CSystem2> 00074 PointT1 00075 cross_prod_impl(PointT1 const & p1, PointT2 const & p2, CSystem1 const &, CSystem2 const &) 00076 { 00077 typedef typename result_of::cartesian_point<PointT1>::type CartesianPoint1; 00078 00079 return detail::cross_prod_impl<CartesianPoint1>::apply(to_cartesian(p1), to_cartesian(p2)); 00080 } 00081 00083 template<typename PointT1, typename PointT2, int d> 00084 PointT1 00085 cross_prod_impl(PointT1 const & p1, PointT2 const & p2, cartesian_cs<d>, cartesian_cs<d>) 00086 { 00087 return detail::cross_prod_impl<PointT1>::apply(p1, p2); 00088 } 00089 00095 template<typename PointT1, typename PointT2> 00096 PointT1 00097 cross_prod(PointT1 const& v1, PointT2 const& v2) 00098 { 00099 return cross_prod_impl(v1, 00100 v2, 00101 typename result_of::coordinate_system<PointT1>::type(), 00102 typename result_of::coordinate_system<PointT2>::type()); 00103 } 00104 00105 } 00106 00107 #endif