BallProject.h 1.66 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

/** \file BallProject.h */

#ifndef AMDIS_BALLPROJECT_H
#define AMDIS_BALLPROJECT_H

28
29
#include "MatrixVectorOperations.h"

30
31
32
33
34
35
36
37
38
namespace AMDiS {

  /** \brief
   * Projects world coordinates to the surface of a ball with given center and 
   * radius. Can be used as boundary or volume projection.
   */
  class BallProject : public Projection
  {
  public:
39
    /// Constructor.
40
41
42
43
44
45
46
    BallProject(int id, 
		ProjectionType type,
		WorldVector<double> &center,
		double radius) 
      : Projection(id, type),
	center_(center),
	radius_(radius)
47
    {}
48

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

52
    /// Implementation of Projection::project();
Thomas Witkowski's avatar
Thomas Witkowski committed
53
54
    void project(WorldVector<double> &x) 
    {
55
56
57
      x -= center_;
      double norm = sqrt(x*x);
      TEST_EXIT(norm != 0.0)("can't project vector x\n");
58
      x *= radius_ / norm;
59
      x += center_;
60
    }
61
62

  protected:
63
    /// Center of the ball.
64
65
    WorldVector<double> center_;

66
    /// Radius of the ball.
67
68
69
70
71
72
    double radius_;
  };

}

#endif