CylinderProject.h 2.72 KB
Newer Older
1
2
3
4
5
6
// ============================================================================
// ==                                                                        ==
// == AMDiS - Adaptive multidimensional simulations                          ==
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
7
// ==  TU Dresden                                                            ==
8
// ==                                                                        ==
9
10
11
// ==  Institut fr Wissenschaftliches Rechnen                               ==
// ==  Zellescher Weg 12-14                                                  ==
// ==  01069 Dresden                                                         ==
12
13
14
15
// ==  germany                                                               ==
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
16
// ==  https://gforge.zih.tu-dresden.de/projects/amdis/                      ==
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// ==                                                                        ==
// ============================================================================

/** \file CylinderProject.h */

#ifndef AMDIS_CYLINDERPROJECT_H
#define AMDIS_CYLINDERPROJECT_H

namespace AMDiS {

  /** \brief
   * Projects world coordinates to the surface of a cylinder with given center, 
   * radius and direction. Can be used as boundary or volume projection.
   */
  class CylinderProject : public Projection
  {
  public:
34
    /// Constructor.
35
36
37
38
39
40
41
42
43
44
45
46
    CylinderProject(int id,
		    ProjectionType type,
		    WorldVector<double> &c,
		    WorldVector<double> &d,
		    double r) 
      : Projection(id, type),
	center_(c),
	direction_(d),
	radius_(r)
    {
      double norm = sqrt(direction_*direction_);
      direction_ *= 1.0 / norm;
47
    }
48

49
50
    /// Destructor.
    virtual ~CylinderProject() {}
51

52
53
54
    /// Implementation of Projection::project();
    void project(WorldVector<double> &x) 
    {
55
56
57
58
59
60
61
62
      x -= center_;
      WorldVector<double> v1 = direction_; v1 *= (x*direction_);
      WorldVector<double> v2 = x; v2 -= v1;
      double norm = sqrt(v2 * v2);
      TEST_EXIT(norm != 0.0)("can't project vector x\n");
      v2 *= 1.0 / norm;
      x = v2; x *= radius_; x += v1;
      x += center_;
63
    }
64
65

  protected:
66
    /// Center of the cylinder.
67
68
    WorldVector<double> center_;

69
    /// Direction of the cylinder.
70
71
    WorldVector<double> direction_;

72
    /// Radius of the cylinder.
73
74
75
76
77
78
    double radius_;
  };

}

#endif