RepastHPC  2.3.1
spatial_math.h
1 /*
2  * Repast for High Performance Computing (Repast HPC)
3  *
4  * Copyright (c) 2010 Argonne National Laboratory
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with
8  * or without modification, are permitted provided that the following
9  * conditions are met:
10  *
11  * Redistributions of source code must retain the above copyright notice,
12  * this list of conditions and the following disclaimer.
13  *
14  * Redistributions in binary form must reproduce the above copyright notice,
15  * this list of conditions and the following disclaimer in the documentation
16  * and/or other materials provided with the distribution.
17  *
18  * Neither the name of the Argonne National Laboratory nor the names of its
19  * contributors may be used to endorse or promote products derived from
20  * this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
25  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE TRUSTEES OR
26  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
27  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
28  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
32  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  *
34  *
35  * spatial_math.h
36  *
37  * Created on: Aug 10, 2010
38  * Author: nick
39  */
40 
41 #ifndef SPATIAL_MATH_H_
42 #define SPATIAL_MATH_H_
43 
44 #include <vector>
45 #include "Point.h"
46 
47 namespace repast {
48 
49 const double PI = 3.141592;
50 
51 void _rotate(double* plane, double angle);
52 
53 template<typename GPType>
54 std::vector<GPType> calculateDisplacement(int dimCount, int unitDimension, double scale,
55  const std::vector<double>& anglesInRadians) {
56 
57  std::vector<double> displacement(dimCount, 0);
58  displacement[unitDimension] = 1;
59  double tmp[] = { 0, 0 };
60  int c = 0;
61  for (int i = 0; i < dimCount; i++) {
62  if (i == unitDimension) {
63  continue;
64  } else if (i > unitDimension) {
65  tmp[0] = displacement[unitDimension];
66  tmp[1] = displacement[i];
67  _rotate(tmp, anglesInRadians[c]);
68  displacement[unitDimension] = tmp[0];
69  displacement[i] = tmp[1];
70  } else if (i < unitDimension) {
71  tmp[0] = displacement[i];
72  tmp[1] = displacement[unitDimension];
73  _rotate(tmp, anglesInRadians[c]);
74  displacement[unitDimension] = tmp[1];
75  displacement[i] = tmp[0];
76  }
77  c++;
78  }
79  for (size_t i = 0; i < displacement.size(); ++i) {
80  displacement[i] = displacement[i] * scale;
81  }
82  return displacement;
83 }
84 
85 template<>
86 std::vector<int> calculateDisplacement<int> (int dimCount, int unitDimension, double scale,const std::vector<double>& anglesInRadians);
87 
95 double toRadians(double angdeg);
96 
104 double toDegrees(double angrad);
105 
106 }
107 
108 #endif /* SPATIAL_MATH_H_ */