summaryrefslogtreecommitdiff
path: root/src/utilities/hyperplane2D.hh
blob: 3684e7dc73870170a96a8d7e945fbb9d19f99f89 (plain)
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*  This file is part of the OpenLB library
 *
 *  Copyright (C) 2018 Adrian Kummerlaender
 *  E-mail contact: info@openlb.net
 *  The most recent release of OpenLB can be downloaded at
 *  <http://www.openlb.net/>
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU General Public License
 *  as published by the Free Software Foundation; either version 2
 *  of the License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public
 *  License along with this program; if not, write to the Free
 *  Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 *  Boston, MA  02110-1301, USA.
*/

#ifndef HYPERPLANE_2D_HH
#define HYPERPLANE_2D_HH

#include "hyperplane2D.h"
#include "core/olbDebug.h"

namespace olb {


template <typename T>
Hyperplane2D<T>& Hyperplane2D<T>::originAt(const Vector<T,2>& o)
{
  origin[0] = o[0] - 2*std::numeric_limits<T>::epsilon()*fabs(o[0]);
  origin[1] = o[1] - 2*std::numeric_limits<T>::epsilon()*fabs(o[1]);

  return *this;
}

template <typename T>
Hyperplane2D<T>& Hyperplane2D<T>::centeredIn(const Cuboid2D<T>& cuboid)
{
  const Vector<T,2>& cuboidOrigin = cuboid.getOrigin();
  const Vector<int,2>& extend     = cuboid.getExtend();
  const T deltaR = cuboid.getDeltaR();

  origin[0] = (cuboidOrigin[0] + 0.5 * deltaR * extend[0]);
  origin[1] = (cuboidOrigin[1] + 0.5 * deltaR * extend[1]);
  origin[0] -= 2*std::numeric_limits<T>::epsilon()*fabs(origin[0]);
  origin[1] -= 2*std::numeric_limits<T>::epsilon()*fabs(origin[1]);

  return *this;
}

template <typename T>
Hyperplane2D<T>& Hyperplane2D<T>::parallelTo(const Vector<T,2>& direction)
{
  u = direction;
  normal = { u[1], -u[0] };
  normal.normalize();

  OLB_POSTCONDITION(util::nearZero(util::dotProduct2D(u,normal)));

  return *this;
}

template <typename T>
Hyperplane2D<T>& Hyperplane2D<T>::normalTo(const Vector<T,2>& n)
{
  normal = n;

  if ( util::nearZero(normal[0]*normal[1]) ) {
    if ( util::nearZero(normal[0]) ) {
      u = {T(1), T()};
    }
    else if ( util::nearZero(normal[1]) ) {
      u = {T(), T(1)};
    }
  }
  else {
    u = {normal[1], -normal[0]};
  }

  u.normalize();
  normal.normalize();

  OLB_POSTCONDITION(util::nearZero(util::dotProduct2D(u,normal)));

  return *this;
}

template <typename T>
bool Hyperplane2D<T>::isParallelToX() const
{
  return util::nearZero(util::dotProduct2D(normal, {1,0}));
}

template <typename T>
bool Hyperplane2D<T>::isParallelToY() const
{
  return util::nearZero(util::dotProduct2D(normal, {0,1}));
}


}

#endif