cheshirekow  v0.1.0
Simplex.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 Josh Bialkowski (jbialk@mit.edu)
3  *
4  * This file is part of mpblocks.
5  *
6  * mpblocks is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * mpblocks is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with mpblocks. If not, see <http://www.gnu.org/licenses/>.
18  */
27 #ifndef MPBLOCKS_CLARKSON93_SIMPLEX_HPP_
28 #define MPBLOCKS_CLARKSON93_SIMPLEX_HPP_
29 
30 #include <mpblocks/clarkson93.hpp>
31 
32 namespace mpblocks {
33 namespace clarkson93 {
34 
35 
36 template <class Traits>
38 {
39  typedef Eigen::Matrix<Scalar,NDim,NDim> Matrix;
40  typedef Eigen::Matrix<Scalar,NDim,1> Vector;
41 
42  Matrix A;
43  Vector b;
44 
45  for(unsigned int i=1; i < NDim+1; i++)
46  A.row(i-1) = deref(V[i]);
47  b.setConstant(1);
48 
49  // solve for the normal
50  n = A.fullPivLu().solve(b);
51  n.normalize();
52 
53  // and then find the value of 'c' (hyperplane offset)
54  o = deref(V[1]).dot(n);
55 }
56 
57 template <class Traits>
60 {
61  // then orient the hyperplane so that the peak vertex is on the
62  // "positive" side (i.e. the 'less than' side)
63 
64  switch( orient )
65  {
66  case INSIDE:
67  {
68  if( n.dot( x ) > o )
69  {
70  n = -n;
71  o = -o;
72  }
73  break;
74  }
75 
76  case OUTSIDE:
77  {
78  if( n.dot( x ) < o )
79  {
80  n = -n;
81  o = -o;
82  }
83  break;
84  }
85 
86  default:
87  assert(false);
88  break;
89  }
90 }
91 
92 
93 template <class Traits>
94 typename Traits::Scalar SimplexBase<Traits>::normalProjection( const Point& x )
95 {
96  return o - n.dot(x);
97 }
98 
99 
100 template <class Traits>
102 {
103  return V[0] == antiOrigin;
104 }
105 
106 template <class Traits>
108 {
109  return ( n.dot(x) < o );
110 }
111 
112 
113 
114 } // namespace clarkson93
115 } // namespace mpblocks
116 
117 
118 
119 
120 #endif // SIMPLEX_HPP_
void calculateConstraint(PointDeref &deref)
calculate the normal and offset of the constraint given the d vertices on it's base facet (does not c...
Definition: Simplex.hpp:37
Traits::PointRef PointRef
Definition: Simplex.h:97
Scalar normalProjection(const Point &x)
returns the distance of x to the base facet, used in walking the triangulation to x ...
Definition: Simplex.hpp:94
bool isInfinite(PointRef antiOrigin)
returns true if vertex[0] is the anti origin
Definition: Simplex.hpp:101
Traits::PointDeref PointDeref
Definition: Simplex.h:98
void orientConstraint(const Point &x, Orientation orient=INSIDE)
orient the constraint by ensuring that the point x satisfies it (i.e. )
Definition: Simplex.hpp:59
bool isVisible(const Point &x)
returns true if x is on the inside of the base facet (i.e. x is in the same half space as the simplex...
Definition: Simplex.hpp:107