CASM
AClustersApproachtoStatisticalMechanics
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
QhullHyperplane.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (c) 2009-2015 C.B. Barber. All rights reserved.
4 ** $Id: //main/2015/qhull/src/libqhullcpp/QhullHyperplane.cpp#1 $$Change: 1981 $
5 ** $DateTime: 2015/09/28 20:26:32 $$Author: bbarber $
6 **
7 ****************************************************************************/
8 
9 #include "QhullHyperplane.h"
10 
11 #include "Qhull.h"
12 #include "QhullPoint.h"
13 
14 #include <iostream>
15 
16 
17 #ifdef _MSC_VER // Microsoft Visual C++ -- warning level 4
18 #endif
19 
20 namespace orgQhull {
21 
22 #
23 
24 QhullHyperplane::
25 QhullHyperplane(const Qhull &q)
26 : hyperplane_coordinates(0)
27 , qh_qh(q.qh())
28 , hyperplane_offset(0.0)
29 , hyperplane_dimension(0)
30 {
31 }
32 
33 QhullHyperplane::
34 QhullHyperplane(const Qhull &q, int hyperplaneDimension, coordT *c, coordT hyperplaneOffset)
35 : hyperplane_coordinates(c)
36 , qh_qh(q.qh())
37 , hyperplane_offset(hyperplaneOffset)
38 , hyperplane_dimension(hyperplaneDimension)
39 {
40 }
41 
42 #
43 
44 // See qt-qhull.cpp for QList conversions
45 
46 #ifndef QHULL_NO_STL
47 std::vector<coordT> QhullHyperplane::
48 toStdVector() const
49 {
50  QhullHyperplaneIterator i(*this);
51  std::vector<coordT> fs;
52  while(i.hasNext()){
53  fs.push_back(i.next());
54  }
55  fs.push_back(hyperplane_offset);
56  return fs;
57 }//toStdVector
58 #endif //QHULL_NO_STL
59 
60 #
61 
66 operator==(const QhullHyperplane &other) const
67 {
68  if(hyperplane_dimension!=other.hyperplane_dimension || !hyperplane_coordinates || !other.hyperplane_coordinates){
69  return false;
70  }
71  double d= fabs(hyperplane_offset-other.hyperplane_offset);
72  if(d > (qh_qh ? qh_qh->distanceEpsilon() : 0.0)){
73  return false;
74  }
75  double angle= hyperplaneAngle(other);
76 
77  double a= fabs(angle-1.0);
78  if(a > (qh_qh ? qh_qh->angleEpsilon() : 0.0)){
79  return false;
80  }
81  return true;
82 }//operator==
83 
84 #
85 
86 // qh_distplane [geom_r.c], QhullFacet::distance, and QhullHyperplane::distance are copies
89 // Does not support RANDOMdist or logging
90 double QhullHyperplane::
91 distance(const QhullPoint &p) const
92 {
93  const coordT *point= p.coordinates();
94  int dim= p.dimension();
95  QHULL_ASSERT(dim==dimension());
96  const coordT *normal= coordinates();
97  double dist;
98 
99  switch (dim){
100  case 2:
101  dist= offset() + point[0] * normal[0] + point[1] * normal[1];
102  break;
103  case 3:
104  dist= offset() + point[0] * normal[0] + point[1] * normal[1] + point[2] * normal[2];
105  break;
106  case 4:
107  dist= offset()+point[0]*normal[0]+point[1]*normal[1]+point[2]*normal[2]+point[3]*normal[3];
108  break;
109  case 5:
110  dist= offset()+point[0]*normal[0]+point[1]*normal[1]+point[2]*normal[2]+point[3]*normal[3]+point[4]*normal[4];
111  break;
112  case 6:
113  dist= offset()+point[0]*normal[0]+point[1]*normal[1]+point[2]*normal[2]+point[3]*normal[3]+point[4]*normal[4]+point[5]*normal[5];
114  break;
115  case 7:
116  dist= offset()+point[0]*normal[0]+point[1]*normal[1]+point[2]*normal[2]+point[3]*normal[3]+point[4]*normal[4]+point[5]*normal[5]+point[6]*normal[6];
117  break;
118  case 8:
119  dist= offset()+point[0]*normal[0]+point[1]*normal[1]+point[2]*normal[2]+point[3]*normal[3]+point[4]*normal[4]+point[5]*normal[5]+point[6]*normal[6]+point[7]*normal[7];
120  break;
121  default:
122  dist= offset();
123  for (int k=dim; k--; )
124  dist += *point++ * *normal++;
125  break;
126  }
127  return dist;
128 }//distance
129 
130 double QhullHyperplane::
131 hyperplaneAngle(const QhullHyperplane &other) const
132 {
133  realT result= 0.0;
134  QH_TRY_(qh_qh){ // no object creation -- destructors skipped on longjmp()
135  result= qh_getangle(qh_qh, hyperplane_coordinates, other.hyperplane_coordinates);
136  }
137  qh_qh->NOerrexit= true;
138  qh_qh->maybeThrowQhullMessage(QH_TRY_status);
139  return result;
140 }//hyperplaneAngle
141 
142 double QhullHyperplane::
143 norm() const {
144  double d= 0.0;
145  const coordT *c= coordinates();
146  for (int k=dimension(); k--; ){
147  d += *c * *c;
148  ++c;
149  }
150  return sqrt(d);
151 }//norm
152 
153 }//namespace orgQhull
154 
155 #
156 
157 using std::ostream;
158 using orgQhull::QhullHyperplane;
159 
160 #
161 
162 ostream &
163 operator<<(ostream &os, const QhullHyperplane &p)
164 {
165  os << p.print("");
166  return os;
167 }
168 
169 ostream &
170 operator<<(ostream &os, const QhullHyperplane::PrintHyperplane &pr)
171 {
172  os << pr.print_message;
173  QhullHyperplane p= *pr.hyperplane;
174  const realT *c= p.coordinates();
175  for(int k=p.dimension(); k--; ){
176  realT r= *c++;
177  if(pr.print_message){
178  os << " " << r; // FIXUP QH11010 %8.4g
179  }else{
180  os << " " << r; // FIXUP QH11010 qh_REAL_1
181  }
182  }
183  os << pr.hyperplane_offset_message << " " << p.offset();
184  os << std::endl;
185  return os;
186 }//PrintHyperplane
187 
double angle(const Eigen::Ref< const Eigen::Vector3d > &a, const Eigen::Ref< const Eigen::Vector3d > &b)
Get angle, in radians, between two vectors on range [0,pi].
std::ostream & operator<<(std::ostream &sout, const SelectiveDynamics &sel)
Write SelectiveDynamics options.
Definition: VaspIO.hh:63
QhullRidge – Qhull's ridge structure, ridgeT, as a C++ class.
Definition: Coordinates.cpp:20
bool operator==(const UnitCellCoord &A, const UnitCellCoord &B)
Compare UnitCellCoord.
T norm(const Tensor< T > &ttens)
Definition: Tensor.hh:968