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_DYNAMIC_SIMPLEX_HPP_
28 #define MPBLOCKS_CLARKSON93_DYNAMIC_SIMPLEX_HPP_
29 
30 #include <mpblocks/clarkson93.hpp>
31 
32 namespace mpblocks {
33 namespace clarkson93 {
34 namespace dynamic {
35 
36 
37 template <class Traits>
39 {
40  typedef Eigen::Matrix<Scalar,Eigen::Dynamic,Eigen::Dynamic> Matrix;
41  typedef Eigen::Matrix<Scalar,Eigen::Dynamic,1> Vector;
42 
43  Matrix A(ndim,ndim);
44  Vector b(ndim);
45 
46  for(int i=1; i < ndim+1; i++)
47  A.row(i-1) = deref(vertices[i]);
48  b.setConstant(1);
49 
50  // solve for the normal
51  n = A.partialPivLu().solve(b);
52  n.normalize();
53 
54  // and then find the value of 'c' (hyperplane offset)
55  c = deref(vertices[1]).dot(n);
56 }
57 
58 template <class Traits>
61 {
62  // then orient the hyperplane so that the peak vertex is on the
63  // "positive" side (i.e. the 'less than' side)
64 
65  switch( orient )
66  {
67  case INSIDE:
68  {
69  if( n.dot( x ) > c )
70  {
71  n = -n;
72  c = -c;
73  }
74  break;
75  }
76 
77  case OUTSIDE:
78  {
79  if( n.dot( x ) < c )
80  {
81  n = -n;
82  c = -c;
83  }
84  break;
85  }
86 
87  default:
88  assert(false);
89  break;
90  }
91 }
92 
93 
94 template <class Traits>
95 typename Traits::Scalar SimplexBase<Traits>::normalProjection( const Point& x )
96 {
97  return c - n.dot(x);
98 }
99 
100 
101 template <class Traits>
103 {
104  return vertices[0] == antiOrigin;
105 }
106 
107 template <class Traits>
109 {
110  return ( n.dot(x) < c );
111 }
112 
113 
114 } // namespace dynamic
115 } // namespace clarkson93
116 } // namespace mpblocks
117 
118 
119 
120 
121 #endif // SIMPLEX_HPP_
Scalar normalProjection(const Point &x)
returns the distance of x to the base facet, used in walking the triangulation to x ...
Definition: Simplex.hpp:95
bool isInfinite(PointRef antiOrigin)
returns true if vertex[0] is the anti origin
Definition: Simplex.hpp:102
void calculateConstraint(uint ndim, 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:38
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:108
void orientConstraint(const Point &x, Orientation orient=INSIDE)
orient the constraint by ensuring that the point x satisfies it (i.e. )
Definition: Simplex.hpp:60