MINT2
Public Member Functions | List of all members
HyperPlane Class Reference

#include <HyperPlane.h>

Inheritance diagram for HyperPlane:
NPlane

Public Member Functions

 HyperPlane (const HyperPointSet &a)
 
virtual void print (std::ostream &os=std::cout, int endline=1) const
 
bool pointInPlane (const HyperPoint &hyperPoint) const
 
HyperPoint findPlaneIntersectionParameters (const HyperPoint &hyperPoint, int dimToOmmit=0) const
 
HyperPoint findIntersectionPoint (const HyperLine &hyperLine) const
 
HyperPoint findLineIntersectionParameter (const HyperLine &hyperLine) const
 
HyperPoint findPlaneIntersectionParameters (const HyperLine &hyperLine) const
 
TMatrixD findIntersectionSolution (const HyperLine &hyperLine) const
 
bool operator== (const HyperPlane &other) const
 
 ~HyperPlane ()
 
- Public Member Functions inherited from NPlane
 NPlane (const HyperPointSet &a)
 
 NPlane (const HyperPoint &origin, const HyperPointSet &v)
 
int getDimension () const
 
int getN () const
 
const HyperPointgetOrigin () const
 
virtual const HyperPointgetDirection (int i=0) const
 
HyperPoint getParametricPoint (const HyperPoint &t) const
 
virtual ~NPlane ()
 

Additional Inherited Members

- Protected Attributes inherited from NPlane
HyperPoint _origin
 
HyperPointSet _v
 

Detailed Description

HyperPlot, Author: Sam Harnew, sam.h.nosp@m.arne.nosp@m.w@gma.nosp@m.il.c.nosp@m.om , Date: Dec 2015

A HyperPlane that is defined by nDim points in space. i.e. a line in 2D, a plane in 3D ...

Definition at line 25 of file HyperPlane.h.

Constructor & Destructor Documentation

◆ HyperPlane()

HyperPlane::HyperPlane ( const HyperPointSet a)

Constructor that requires nDim points to define the HyperPlane

Definition at line 7 of file HyperPlane.cpp.

7  :
8  NPlane(a)
9 {
10  WELCOME_LOG << "Hello from the HyperPlane() Constructor";
11 
12  if ( a.getDimension() < (int)a.size() ) ERROR_LOG << "You only need #dim points to define a hyperplane - I'll just use the first #dim";
13  if ( a.getDimension() > (int)a.size() ) ERROR_LOG << "You have not provided enough points to define a hyperplane - I'll probably crash soon";
14 
15 }
NPlane(const HyperPointSet &a)
Definition: NPlane.cpp:6
#define ERROR_LOG
const int & getDimension() const
Definition: HyperPointSet.h:40
unsigned int size() const
#define WELCOME_LOG

◆ ~HyperPlane()

HyperPlane::~HyperPlane ( )

Definition at line 244 of file HyperPlane.cpp.

244  {
245  GOODBYE_LOG << "Goodbye from the HyperPlane() Constructor";
246 }
#define GOODBYE_LOG

Member Function Documentation

◆ findIntersectionPoint()

HyperPoint HyperPlane::findIntersectionPoint ( const HyperLine hyperLine) const
Todo:
remember how this works

Definition at line 132 of file HyperPlane.cpp.

132  {
133 
134  HyperPoint lineIntersectionParameter = findLineIntersectionParameter(hyperLine);
135 
136  if (lineIntersectionParameter.getDimension()==0) return lineIntersectionParameter;
137 
138  return hyperLine.getParametricPoint(lineIntersectionParameter.at(0));
139 
140 }
HyperPoint findLineIntersectionParameter(const HyperLine &hyperLine) const
Definition: HyperPlane.cpp:142
const double & at(int i) const
Definition: HyperPoint.cpp:433
int getDimension() const
Definition: HyperPoint.h:99
HyperPoint getParametricPoint(const HyperPoint &t) const
Definition: NPlane.cpp:40

◆ findIntersectionSolution()

TMatrixD HyperPlane::findIntersectionSolution ( const HyperLine hyperLine) const
Todo:
remember how this works

Definition at line 165 of file HyperPlane.cpp.

165  {
166 
167  if (hyperLine.getDimension() != getDimension()){
168  ERROR_LOG << "Your HyperPlane and HyperLine have different dimensionality. Returning 0";
169  return TMatrixD(0,0);
170  }
171 
172  int oldErrorLevel = gErrorIgnoreLevel;
173  gErrorIgnoreLevel = 5000;
174 
175  HyperPoint lhs = hyperLine.getOrigin() - getOrigin();
176 
177  VERBOSE_LOG << "Making Column Vector";
178  TMatrixD vectorD(getDimension(), 1);
179 
180  for (int i = 0; i < getDimension(); i++){
181  vectorD(i,0) = lhs.at(i);
182  }
183 
184  VERBOSE_LOG << "Making Matrix";
185  TMatrixD matrix(getDimension(), getDimension());
186 
187  VERBOSE_LOG << "Filling Column 0";
188  for (int i = 0; i < getDimension(); i++){
189  matrix(i,0) = -hyperLine.getDirection().at(i);
190  }
191 
192  for (int j = 1; j < getDimension(); j++){
193  VERBOSE_LOG << "Filling Column " << j;
194  for (int i = 0; i < getDimension(); i++){
195  matrix(i,j) = getDirection(j - 1).at(i);
196  }
197  }
198 
199  TDecompLU lu(matrix);
200  if( !lu.Decompose() ) {
201  VERBOSE_LOG << "Matrix is singular. Cannot find solution.";
202  gErrorIgnoreLevel = oldErrorLevel;
203  return TMatrixD(0,0);
204  }
205 
206  VERBOSE_LOG << "Matrix before inversion";
207  //if (_verbose) matrix.Print();
208 
209  double determinant = 0.0;
210  matrix.Invert(&determinant);
211  VERBOSE_LOG << "Determinant = " << determinant;
212 
213  VERBOSE_LOG << "Matrix after inversion";
214  //if (_verbose) matrix.Print();
215 
216  TMatrixD result = matrix*vectorD;
217 
218  gErrorIgnoreLevel = oldErrorLevel;
219 
220  return result;
221 
222 }
virtual const HyperPoint & getDirection(int i=0) const
Definition: NPlane.h:54
const HyperPoint & getOrigin() const
Definition: NPlane.h:51
#define ERROR_LOG
int getDimension() const
Definition: NPlane.h:45
#define VERBOSE_LOG
const double & at(int i) const
Definition: HyperPoint.cpp:433

◆ findLineIntersectionParameter()

HyperPoint HyperPlane::findLineIntersectionParameter ( const HyperLine hyperLine) const
Todo:
remember how this works

Definition at line 142 of file HyperPlane.cpp.

142  {
143 
144  TMatrixD solution = findIntersectionSolution(hyperLine);
145  if (solution.GetNcols() == 0) return HyperPoint(0);
146  return HyperPoint(solution(0,0));
147 
148 }
TMatrixD findIntersectionSolution(const HyperLine &hyperLine) const
Definition: HyperPlane.cpp:165

◆ findPlaneIntersectionParameters() [1/2]

HyperPoint HyperPlane::findPlaneIntersectionParameters ( const HyperPoint hyperPoint,
int  dimToOmmit = 0 
) const
Todo:
remember how this works

Definition at line 57 of file HyperPlane.cpp.

57  {
58 
59  if (hyperPoint.getDimension() != getDimension()){
60  ERROR_LOG << "Your HyperPlane and HyperPoint have different dimensionality. Returning 0";
61  HyperPoint(0);
62  }
63 
64  int oldErrorLevel = gErrorIgnoreLevel;
65  gErrorIgnoreLevel = 5000;
66 
67  int dim = getDimension();
68  int reducedDim = dim -1;
69 
70  std::vector<int> linIndep;
71  for (int i = 0; i < dim; i++){
72  if (dimToOmmit != i) linIndep.push_back(i);
73  }
74 
75  HyperPoint lhs = hyperPoint - getOrigin();
76 
77  TMatrixD vectorD(reducedDim, 1);
78  for (int i = 0; i < reducedDim ; i++){
79  vectorD(i,0) = lhs.at(linIndep.at(i));
80  }
81 
82  TMatrixD matrix(reducedDim, reducedDim);
83  for (int j = 0; j < reducedDim; j++){
84  for (int i = 0; i < reducedDim; i++){
85  matrix(i,j) = getDirection(j).at(linIndep.at(i));
86  }
87  }
88 
89  TDecompLU lu(matrix);
90 
91  //std::cout << "getting eigenVectors" << std::endl;
92  //TVectorT<double> eigenValues;
93  //matrix.EigenVectors(eigenValues);
94  //std::cout << "done" << std::endl;
95 
96 
97 
98  if( !lu.Decompose() ) {
99 
100  if (dimToOmmit != (dim -1)) return findPlaneIntersectionParameters(hyperPoint, dimToOmmit + 1);
101  VERBOSE_LOG << "Matrix is singular. Cannot find solution.";
102  matrix.Print();
103 
104  gErrorIgnoreLevel = oldErrorLevel;
105 
106  return HyperPoint(0);
107  }
108 
109  VERBOSE_LOG << "Matrix before inversion";
110 
111  double determinant = 0.0;
112  matrix.Invert(&determinant);
113  VERBOSE_LOG << "Determinant = " << determinant;
114 
115  VERBOSE_LOG << "Matrix after inversion";
116 
117  TMatrixD result = matrix*vectorD;
118 
119  HyperPoint interceptionParameter(reducedDim);
120  for (int i = 0; i < reducedDim; i++){
121  interceptionParameter.at(i) = result(i,0);
122  }
123 
124  VERBOSE_LOG << "All done - returning parameters";
125 
126  gErrorIgnoreLevel = oldErrorLevel;
127 
128  return interceptionParameter;
129 
130 }
virtual const HyperPoint & getDirection(int i=0) const
Definition: NPlane.h:54
const HyperPoint & getOrigin() const
Definition: NPlane.h:51
#define ERROR_LOG
int getDimension() const
Definition: NPlane.h:45
#define VERBOSE_LOG
HyperPoint findPlaneIntersectionParameters(const HyperPoint &hyperPoint, int dimToOmmit=0) const
Definition: HyperPlane.cpp:57
const double & at(int i) const
Definition: HyperPoint.cpp:433
int getDimension() const
Definition: HyperPoint.h:99

◆ findPlaneIntersectionParameters() [2/2]

HyperPoint HyperPlane::findPlaneIntersectionParameters ( const HyperLine hyperLine) const
Todo:
remember how this works

Definition at line 150 of file HyperPlane.cpp.

150  {
151 
152  TMatrixD solution = findIntersectionSolution(hyperLine);
153  if (solution.GetNcols() == 0) return HyperPoint(0);
154 
155  HyperPoint point(getDimension() - 1);
156 
157  for (int i = 1; i < getDimension(); i++){
158  point.at(i-1) = solution(i,0);
159  }
160 
161  return point;
162 
163 }
int getDimension() const
Definition: NPlane.h:45
TMatrixD findIntersectionSolution(const HyperLine &hyperLine) const
Definition: HyperPlane.cpp:165

◆ operator==()

bool HyperPlane::operator== ( const HyperPlane other) const

See if two planes are the same. Cannot just comapre the parameters. Instead see if the points that define plane A are within plane B.

Definition at line 227 of file HyperPlane.cpp.

227  {
228  if (other.getDimension() != this->getDimension()) {
229  ERROR_LOG << "Trying to compare HyperPlanes of different dimensions, returning false";
230  return false;
231  }
232  if ( this->pointInPlane(other.getOrigin()) == 0) return false;
233 
234  for (int i = 0; i < getDimension() - 1; i++){
235  HyperPoint parameters(getDimension() - 1);
236  parameters.at(i) = 1;
237  HyperPoint pointInOtherPlane = other.getParametricPoint(parameters);
238  if ( this->pointInPlane(pointInOtherPlane) == 0) return false;
239  }
240  return true;
241 }
bool pointInPlane(const HyperPoint &hyperPoint) const
Definition: HyperPlane.cpp:37
const HyperPoint & getOrigin() const
Definition: NPlane.h:51
#define ERROR_LOG
int getDimension() const
Definition: NPlane.h:45
HyperPoint getParametricPoint(const HyperPoint &t) const
Definition: NPlane.cpp:40

◆ pointInPlane()

bool HyperPlane::pointInPlane ( const HyperPoint hyperPoint) const

Check to see if a point is within a HyperPlane. Distance between the two has to be smaller than sqrt(1e-2)

Definition at line 37 of file HyperPlane.cpp.

37  {
38 
39 
40  HyperPoint interceptionParameters = findPlaneIntersectionParameters(hyperPoint);
41 
42  if (interceptionParameters.size() == 0) return false;
43  HyperPoint pointInPlane = getParametricPoint(interceptionParameters);
44 
45  HyperPoint vectorDifference = hyperPoint - pointInPlane;
46 
47  double difference = 0.0;
48  for (int i = 0; i < getDimension(); i++) difference += fabs(vectorDifference.at(i));
49 
50  if( fabs(difference) < 1e-2 ) return true;
51 
52  return false;
53 
54 }
bool pointInPlane(const HyperPoint &hyperPoint) const
Definition: HyperPlane.cpp:37
int size() const
Definition: HyperPoint.h:96
int getDimension() const
Definition: NPlane.h:45
HyperPoint findPlaneIntersectionParameters(const HyperPoint &hyperPoint, int dimToOmmit=0) const
Definition: HyperPlane.cpp:57
const double & at(int i) const
Definition: HyperPoint.cpp:433
HyperPoint getParametricPoint(const HyperPoint &t) const
Definition: NPlane.cpp:40

◆ print()

void HyperPlane::print ( std::ostream &  os = std::cout,
int  endline = 1 
) const
virtual

Print the parameters that define the HyperPlane

Reimplemented from NPlane.

Definition at line 20 of file HyperPlane.cpp.

20  {
21 
22  os << "HyperPlane: v = ";
23  _origin.print(os, 0);
24 
25  for (unsigned int i = 0; i < _v.size(); i++){
26  os << " + ";
27  _v.at(i).print(os, 0);
28  os << "t_" << i;
29  }
30  if (endline) os << std::endl;
31 
32 }
HyperPointSet _v
Definition: NPlane.h:36
virtual void print(std::ostream &os=std::cout, int endline=1) const
Definition: HyperPoint.cpp:453
const HyperPoint & at(int i) const
HyperPoint _origin
Definition: NPlane.h:34
unsigned int size() const

The documentation for this class was generated from the following files: