GeometryTools.hh 1.01 KB
Newer Older
Praetorius, Simon's avatar
Praetorius, Simon committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
namespace meshconv {

  template<int dow>
  void coordinate_transform(double x[], double shift[], double scale[], double alpha=0.0, double beta=0.0)
  {
    mtl::dense2D<double> Rx(dow,dow),Ry(dow,dow),T(dow,dow),S(dow,dow);
    Rx = 1.0;
    Ry = 1.0;
    S = 1.0;
    if (dow == 3) {
      Rx(1,1) = cos(alpha);  Rx(1,2) = -sin(alpha);
      Rx(2,1) = sin(alpha);  Rx(2,2) = cos(alpha);

      Ry(0,0) = cos(beta);  Ry(0,2) = sin(beta);
      Ry(2,0) = -sin(beta); Ry(2,2) = cos(beta);

      S(0,0) = scale[0];  S(1,1) = scale[1];  S(2,2) = scale[2];
    } else if (dow == 2) {
      Rx(0,0) = cos(alpha);  Rx(0,1) = -sin(alpha);
      Rx(1,0) = sin(alpha);  Rx(1,1) = cos(alpha);

      Ry = 1.0;

      S(0,0) = scale[0];  S(1,1) = scale[1];
    } else {
      S(0,0) = scale[0];
    }

    T = Ry*Rx*S;

    mtl::dense_vector<double> coords(dow);
    for (int i = 0; i < dow; i++)
      coords[i] = x[i];

    coords = T*coords;

    for (int i = 0; i < dow; i++)
      x[i] = coords[i]+shift[i];
  }

} // end namespace meshconv