CylinderProject.h 2 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/******************************************************************************
 *
 * AMDiS - Adaptive multidimensional simulations
 *
 * Copyright (C) 2013 Dresden University of Technology. All Rights Reserved.
 * Web: https://fusionforge.zih.tu-dresden.de/projects/amdis
 *
 * Authors: 
 * Simon Vey, Thomas Witkowski, Andreas Naumann, Simon Praetorius, et al.
 *
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 *
 *
 * This file is part of AMDiS
 *
 * See also license.opensource.txt in the distribution.
 * 
 ******************************************************************************/
20
21


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

/** \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:
37
    /// Constructor.
38
39
40
41
42
43
44
45
46
47
48
49
    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;
50
    }
51

52
53
    /// Destructor.
    virtual ~CylinderProject() {}
54

55
56
57
    /// Implementation of Projection::project();
    void project(WorldVector<double> &x) 
    {
58
59
60
61
62
63
64
65
      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_;
66
    }
67
68

  protected:
69
    /// Center of the cylinder.
70
71
    WorldVector<double> center_;

72
    /// Direction of the cylinder.
73
74
    WorldVector<double> direction_;

75
    /// Radius of the cylinder.
76
77
78
79
80
81
    double radius_;
  };

}

#endif