SourceForge.net

Search

View of /quan-trunk/quan_matters/examples/fusion/rotate_coord_90_deg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (download)
Mon Jan 15 22:48:13 2007 UTC (20 months, 3 weeks ago) by kwikius
Branch: MAIN
CVS Tags: HEAD
Changes since 1.3: +0 -0 lines
FILE REMOVED
cleaning
    1 
    2 #define FUSION_MAX_VECTOR_SIZE 16
    3 #include <quan/fusion/boost/advance_iterator.hpp>
    4 #include <boost/fusion/sequence.hpp>
    5 #include <boost/fusion/sequence/io.hpp>
    6 #include <quan/fusion/dot_product.hpp>
    7 #include <quan/fusion/static_value/out/static_value.hpp>
    8 #include <quan/out/length.hpp>
    9 #include <quan/out/reciprocal_length.hpp>
   10 #include <quan/angle.hpp>
   11 //required for pi
   12 #include <quan_matters/src/constant.cpp>
   13 #include <quan/static.hpp>
   14 
   15 /*
   16     basic matrix calc
   17 */
   18 
   19 namespace quan{
   20 
   21     template <typename T, int N>
   22     struct rotation;
   23     template <typename T>
   24     struct rotation<T,2>{
   25         typedef typename  quan::meta::binary_operation<
   26             T,quan::meta::divides,T
   27         >::type numeric_type;
   28         typedef typename quan::meta::unary_operation<
   29             quan::meta::reciprocal,T
   30         >::type reciprocal_type;
   31 
   32         typedef boost::fusion::vector9<
   33             numeric_type,       numeric_type,   typename static_<
   34                                                     reciprocal_type,0
   35                                                 >::type,
   36 
   37             numeric_type,       numeric_type,   typename static_<
   38                                                     reciprocal_type,0
   39                                                 >::type,
   40             typename static_<
   41                 T,0
   42             >::type,            typename static_<
   43                                     T,0
   44                                 >::type,        typename static_<
   45                                                     numeric_type,1
   46                                                 >::type
   47         > type;
   48         type m_matrix;
   49 
   50         rotation(quan::angle::rad theta)
   51         :m_matrix(
   52             quan::cos(theta)     ,quan::sin(theta)      ,static_<reciprocal_type,0>::type(),
   53             -quan::sin(theta)    ,quan::cos(theta)      ,static_<reciprocal_type,0>::type(),
   54             static_<T,0>::type() ,static_<lT,0>::type() ,static_<numeric_type,1>::type()
   55         ){}
   56     };
   57 
   58 }//quan
   59 
   60 int main()
   61 {
   62     using quan::static_;
   63     using quan::length;
   64     using quan::reciprocal_length;
   65     namespace fusion = boost::fusion;
   66     namespace result_of = boost::fusion::result_of;
   67 
   68     // set up the matrix
   69     // many elements can be static_values
   70     // hence can be optimised in a calc
   71     typedef fusion::vector9<
   72         double      ,double      ,static_<reciprocal_length::per_m,0>::type,
   73         double      ,double      ,static_<reciprocal_length::per_m,0>::type,
   74         static_<length::m,0>::type ,static_<length::m,0>::type ,static_<double,1>::type
   75     > matrix_3x3_type;
   76 
   77     quan::angle::rad theta(quan::angle::deg(-45));
   78 
   79     // a pure rotation by -45 deg
   80     matrix_3x3_type rotation(
   81         quan::cos(theta)  ,quan::sin(theta) ,static_<reciprocal_length::per_m,0>::type(),
   82         -quan::sin(theta) ,quan::cos(theta) ,static_<reciprocal_length::per_m,0>::type(),
   83         static_<length::m,0>::type(),static_<length::m,0>::type(),static_<double,1>::type()
   84     );
   85 
   86     // set up ranges representing matrix columns
   87     using boost::mpl::int_;
   88     typedef fusion::advance_iterator<matrix_3x3_type,int_<3>,0,0> col0_start;
   89     typedef fusion::advance_iterator<matrix_3x3_type,int_<3>,3,0> col0_end;
   90     typedef fusion::iterator_range<col0_start,col0_end> col0_type;
   91 
   92     typedef fusion::advance_iterator<matrix_3x3_type,int_<3>,0,1> col1_start;
   93     typedef fusion::advance_iterator<matrix_3x3_type,int_<3>,3,1> col1_end;
   94     typedef fusion::iterator_range<col1_start,col1_end> col1_type;
   95 
   96     typedef fusion::advance_iterator<matrix_3x3_type,int_<3>,0,2> col2_start;
   97     typedef fusion::advance_iterator<matrix_3x3_type,int_<3>,3,2> col2_end;
   98     typedef fusion::iterator_range<col2_start,col2_end> col2_type;
   99 
  100     // get the columns
  101     col0_type col0 = col0_type(col0_start(rotation),col0_end(rotation));
  102     col1_type col1 = col1_type(col1_start(rotation),col1_end(rotation));
  103     col2_type col2 = col2_type(col2_start(rotation),col2_end(rotation));
  104 
  105     // set up a coordinate
  106     typedef fusion::vector3<double,double,static_<reciprocal_length::per_m,1>::type > coordinate_type;
  107 
  108     // set up the result type
  109     // of rotating the coordinate
  110     typedef quan::fusion::dot_product::result<
  111         coordinate_type,col0_type
  112     >::type result0_type;
  113 
  114     typedef quan::fusion::dot_product::result<
  115         coordinate_type,col1_type
  116     >::type result1_type;
  117 
  118     typedef quan::fusion::dot_product::result<
  119         coordinate_type,col2_type
  120     >::type result2_type;
  121 
  122     typedef fusion::vector3<
  123         result0_type,
  124         result1_type,
  125         result2_type
  126     > result_type;
  127 
  128     //set up runtime coordinate
  129     coordinate_type coordinate(1,0,static_<reciprocal_length::per_m,1>::type());
  130 
  131     std::cout << "input coordinate: "
  132     << fusion::tuple_open('[')
  133     << fusion::tuple_close(']')
  134     << fusion::tuple_delimiter(", ")
  135     << coordinate << '\n';
  136 
  137     // do runtime calc
  138     quan::fusion::dot_product dot;
  139     result_type result(
  140         dot(coordinate,col0),
  141         dot(coordinate,col1),
  142         dot(coordinate,col2)
  143     );
  144 
  145     std::cout << "output coordinate: "
  146     << fusion::tuple_open('[')
  147     << fusion::tuple_close(']')
  148     << fusion::tuple_delimiter(", ")
  149     << result << '\n';
  150 
  151 }
  152 
  153 
  154 
  155 
  156 
  157 
  158 
  159 
  160 
  161 
  162 

Powered by ViewVC 1.0.5 ViewVC Help