Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GeoPrimitives.H
Go to the documentation of this file.
1 #ifndef _GeoPrimitives_H_
7 #define _GeoPrimitives_H_
8 #include <cmath>
9 #include <istream>
10 #include <ostream>
11 #include <vector>
12 #include <cassert>
13 
14 
15 namespace GeoPrim {
16 
17  const double TOL = 1e-16;
18  const double PI = 4.0*atan(1.0);
19 
20  class CLine;
21 
22  class CPoint {
23  friend CPoint operator*(double,const CPoint &p);
24  friend std::ostream &operator<<(std::ostream &oSt,const CPoint &p);
25  friend std::istream &operator>>(std::istream &iSt,CPoint &p);
26  friend double Distance(const CPoint &p,const GeoPrim::CLine &l);
27  protected:
28  double P[3];
29  public:
31  {
32  P[0] = P[1] = P[2] = 0.0;
33  };
34  CPoint(double ix,double iy,double iz = 0.0)
35  {
36  P[0] = ix;
37  P[1] = iy;
38  P[2] = iz;
39  };
40  CPoint(const double *p)
41  {
42  P[0] = p[0];
43  P[1] = p[1];
44  P[2] = p[2];
45  };
46  CPoint(const CPoint &in)
47  {
48  P[0] = in.P[0];
49  P[1] = in.P[1];
50  P[2] = in.P[2];
51  };
53  {
54  P[0] = 0.;
55  P[1] = 0.;
56  P[2] = 0;
57  return(*this);
58  };
59  CPoint &init(double ix,double iy,double iz = 0.0)
60  {
61  P[0] = ix;
62  P[1] = iy;
63  P[2] = iz;
64  return(*this);
65  };
66  CPoint &init(const double *p)
67  {
68  P[0] = p[0];
69  P[1] = p[1];
70  P[2] = p[2];
71  return(*this);
72  };
73  CPoint &operator=(const CPoint &p)
74  {
75  P[0] = p.P[0];
76  P[1] = p.P[1];
77  P[2] = p.P[2];
78  return(*this);
79  };
80  CPoint &copy(const CPoint &p)
81  {
82  *this = p;
83  return(*this);
84  };
85  double norm() const
86  {
87  return(sqrt((x()*x()) + (y()*y()) + (z()*z())));
88  };
89  bool operator==(const CPoint &p) const
90  {
91  return( (fabs(P[0] - p.P[0]) < TOL) &&
92  (fabs(P[1] - p.P[1]) < TOL) &&
93  (fabs(P[2] - p.P[2]) < TOL) );
94  };
95  bool operator!=(const CPoint &p) const
96  {
97  return (!((*this)==p));
98  };
99  bool operator<(const CPoint &p) const
100  {
101  return (norm() < p.norm());
102  };
103  bool operator>(const CPoint &p) const
104  {
105  return (norm() > p.norm());
106  };
107  bool operator<=(const CPoint &p) const
108  {
109  return ((norm() < p.norm()) ||
110  (*this == p));
111  };
112  bool operator>=(const CPoint &p) const
113  {
114  return((norm() > p.norm()) ||
115  (*this == p));
116  };
118  {
119  P[0] += p.P[0];
120  P[1] += p.P[1];
121  P[2] += p.P[2];
122  return(*this);
123  };
125  {
126  P[0] -= p.P[0];
127  P[1] -= p.P[1];
128  P[2] -= p.P[2];
129  return(*this);
130  };
131  CPoint operator*(double num) const
132  {
133  CPoint rp(P[0]*num,P[1]*num,P[2]*num);
134  return(rp);
135  };
136  CPoint &operator*=(double num)
137  {
138  P[0] *= num;
139  P[1] *= num;
140  P[2] *= num;
141  return(*this);
142  };
143  double &x(){ return P[0]; };
144  CPoint &x(double i)
145  {
146  P[0] = i;
147  return(*this);
148  };
149  const double &x() const { return P[0]; };
150  double &y(){ return P[1]; };
151  CPoint &y(double i)
152  {
153  P[1] = i;
154  return(*this);
155  };
156  const double &y() const { return P[1]; };
157  double &z(){ return P[2]; };
158  CPoint &z(double i)
159  {
160  P[2] = i;
161  return(*this);
162  }
163  const double &z() const { return P[2]; };
164  const double &operator[](unsigned int i) const
165  {
166  if( i > 2 ) i = 0;
167  return(P[i]);
168  };
169  double &operator[](unsigned int i)
170  {
171  if (i > 2) i = 0;
172  return(P[i]);
173  };
174  CPoint operator+(const CPoint &p) const
175  {
176  CPoint rp(P[0]+p.P[0],P[1]+p.P[1],P[2]+p.P[2]);
177  return(rp);
178  };
179  CPoint operator-(const CPoint &p) const
180  {
181  CPoint rp(P[0]-p.P[0],P[1]-p.P[1],P[2]-p.P[2]);
182  return(rp);
183  };
184  double Distance(const CPoint &p) const
185  {
186  return((*this - p).norm());
187  }
188  CPoint &set(double ix,double iy,double iz)
189  {
190  P[0] = ix;
191  P[1] = iy;
192  P[2] = iz;
193  return(*this);
194  };
196  {
197  P[0] = 0.0;
198  P[1] = 0.0;
199  P[2] = 0.0;
200  return(*this);
201  };
202  };
203 
204  class CVector {
205  friend CVector operator*(double,const CVector &);
206  friend std::ostream &operator<<(std::ostream &,const CVector &);
207  friend std::istream &operator>>(std::istream &,CVector &);
208  protected:
209  double V[3];
210  public:
212  {
213  V[0] = V[1] = V[2] = 0.;
214  };
215  CVector(double ix,double iy,double iz = 0.0)
216  {
217  V[0] = ix;
218  V[1] = iy;
219  V[2] = iz;
220  };
221  CVector(const CPoint &p1,const CPoint &p2)
222  {
223  V[0] = (p2 - p1).x();
224  V[1] = (p2 - p1).y();
225  V[2] = (p2 - p1).z();
226  };
227  CVector(const CPoint &p)
228  {
229  V[0] = p.x();
230  V[1] = p.y();
231  V[2] = p.z();
232  };
233  CVector(const double *a)
234  {
235  V[0] = a[0];
236  V[1] = a[1];
237  V[2] = a[2];
238  };
239  CVector(const CVector &v)
240  {
241  V[0] = v.V[0];
242  V[1] = v.V[1];
243  V[2] = v.V[2];
244  };
245  CVector &init(const CPoint &p)
246  {
247  V[0] = p[0];
248  V[1] = p[1];
249  V[2] = p[2];
250  return(*this);
251  };
252  CVector &init(const double *a)
253  {
254  V[0] = a[0];
255  V[1] = a[1];
256  V[2] = a[2];
257  return(*this);
258  };
260  {
261  V[0] = v[0];
262  V[1] = v[1];
263  V[2] = v[2];
264  return(*this);
265  };
266  CVector &init(double ix,double iy,double iz)
267  {
268  V[0] = ix;
269  V[1] = iy;
270  V[2] = iz;
271  return(*this);
272  };
273  CVector &init(const CPoint &p1,const CPoint &p2)
274  {
275  V[0] = (p2 - p1).x();
276  V[1] = (p2 - p1).y();
277  V[2] = (p2 - p1).z();
278  return(*this);
279  };
281  {
282  V[0] = V[1] = V[2] = 0.0;
283  return(*this);
284  };
285  double norm() const
286  {
287  return(sqrt((V[0] * V[0]) + (V[1] * V[1]) + (V[2] * V[2])));
288  };
289  double mag() const
290  {
291  return (norm());
292  };
293  double mag2() const
294  {
295  return ((V[0]*V[0])+(V[1]*V[1])+(V[2]*V[2]));
296  };
298  {
299  double n = norm();
300  V[0] /= n;
301  V[1] /= n;
302  V[2] /= n;
303  return(*this);
304  };
305  CVector unit() const
306  {
307  CVector v(*this);
308  double n = norm();
309  v.V[0] /= n;
310  v.V[1] /= n;
311  v.V[2] /= n;
312  return(v);
313  };
314  double operator*(const CVector &v2) const
315  {
316  return((V[0] * v2.V[0]) +
317  (V[1] * v2.V[1]) +
318  (V[2] * v2.V[2]));
319  };
320  CVector operator*(double num) const
321  {
322  CVector rv(num*V[0],num*V[1],num*V[2]);
323  return(rv);
324  };
325  CVector &operator*=(double num)
326  {
327  V[0] *= num;
328  V[1] *= num;
329  V[2] *= num;
330  return(*this);
331  };
332  CVector operator%(const CVector &v2) const
333  {
334  CVector v;
335  v.V[0] = ((v2.V[2] * V[1]) - (v2.V[1] * V[2]));
336  v.V[1] = ((v2.V[0] * V[2]) - (v2.V[2] * V[0]));
337  v.V[2] = ((v2.V[1] * V[0]) - (v2.V[0] * V[1]));
338  return(v);
339  };
340  CVector &copy(const CVector &v2)
341  {
342  V[0] = v2.V[0];
343  V[1] = v2.V[1];
344  V[2] = v2.V[2];
345  return(*this);
346  };
348  {
349  return(copy(v2));
350  };
352  {
353  V[0] = p.x();
354  V[1] = p.y();
355  V[2] = p.z();
356  return(*this);
357  };
359  {
360  return(copy((*this)%v2));
361  };
362  CVector operator+(const CVector &v2) const
363  {
364  CVector v(V[0] + v2.V[0], V[1] + v2.V[1], V[2] + v2.V[2]);
365  return(v);
366  };
367  CVector operator-(const CVector &v2) const
368  {
369  return((*this) + (-1.0 * v2));
370  };
372  {
373  V[0] += v2.V[0];
374  V[1] += v2.V[1];
375  V[2] += v2.V[2];
376  return(*this);
377  };
379  {
380  V[0] += p.x();
381  V[1] += p.y();
382  V[2] += p.z();
383  return(*this);
384  };
386  {
387  return(copy((*this) - v2));
388  };
389  double &x()
390  {
391  return(V[0]);
392  };
393  double x() const
394  {
395  return(V[0]);
396  };
397  CVector &x(double i)
398  {
399  V[0] = i;
400  return(*this);
401  };
402  double &y()
403  {
404  return(V[1]);
405  };
406  double y() const
407  {
408  return(V[1]);
409  };
410  CVector &y(double i)
411  {
412  V[1] = i;
413  return(*this);
414  };
415  double &z()
416  {
417  return(V[2]);
418  };
419  double z() const
420  {
421  return(V[2]);
422  };
423  CVector &z(double i)
424  {
425  V[2] = i;
426  return(*this);
427  };
428  const double &operator[](unsigned int i) const
429  {
430  if(i > 2) i = 0;
431  return(V[i]);
432  };
433  double &operator[](unsigned int i)
434  {
435  if(i > 2) i = 0;
436  return(V[i]);
437  };
438  bool operator==(const CVector &v) const
439  {
440  return( (fabs(V[0] - v.V[0]) < TOL) &&
441  (fabs(V[1] - v.V[1]) < TOL) &&
442  (fabs(V[2] - v.V[2]) < TOL) );
443  };
444  bool operator<(const CVector &v) const
445  {
446  return (norm() < v.norm());
447  };
448  bool operator>(const CVector &v) const
449  {
450  return (norm() > v.norm());
451  };
452  bool operator<=(const CVector &v) const
453  {
454  return ( (*this < v) ||
455  (*this == v));
456  };
457  bool operator>=(const CVector &v) const
458  {
459  return ( (*this > v) ||
460  (*this == v) );
461  };
462  };
463 
464 
468  class C3Vector {
469  friend C3Vector operator*(double,const C3Vector &);
470  friend std::ostream &operator<<(std::ostream &,const C3Vector &);
471  friend std::istream &operator>>(std::istream &,C3Vector &);
472  private:
473  bool _mydata;
474  protected:
475  double *V;
476  public:
478  {
479  _create();
480  V[0] = V[1] = V[2] = 0.;
481  };
483  {
484  _create();
485  V[0] = inv.x();
486  V[1] = inv.y();
487  V[2] = inv.z();
488  };
489  C3Vector(const CPoint &inp)
490  {
491  _create();
492  V[0] = inp.x();
493  V[1] = inp.y();
494  V[2] = inp.z();
495  };
496  C3Vector(double ix,double iy,double iz = 0.0)
497  {
498  _create();
499  V[0] = ix;
500  V[1] = iy;
501  V[2] = iz;
502  };
503  C3Vector(const C3Vector &p1,const C3Vector &p2)
504  {
505  _create();
506  Copy(p2-p1);
507  };
508  C3Vector(double *a)
509  {
510  _mydata = false;
511  V = a;
512  };
513  C3Vector(const double *a)
514  {
515  _create();
516  V[0] = a[0];
517  V[1] = a[1];
518  V[2] = a[2];
519  };
521  {
522  _create();
523  Copy(v);
524  };
526  {
527  _destroy();
528  };
530  {
531  V[0] = v.V[0];
532  V[1] = v.V[1];
533  V[2] = v.V[2];
534  return(*this);
535  };
536  C3Vector &Init(const double *a)
537  {
538  V[0] = a[0];
539  V[1] = a[1];
540  V[2] = a[2];
541  return(*this);
542  };
544  {
545  V[0] = v[0];
546  V[1] = v[1];
547  V[2] = v[2];
548  return(*this);
549  };
550  C3Vector &Init(double ix,double iy,double iz)
551  {
552  V[0] = ix;
553  V[1] = iy;
554  V[2] = iz;
555  return(*this);
556  };
557  C3Vector &Init(const C3Vector &p1,const C3Vector &p2)
558  {
559  Copy(p2 - p1);
560  return(*this);
561  };
563  {
564  V[0] = V[1] = V[2] = 0.0;
565  return(*this);
566  };
568  {
569  V[0] = V[1] = V[2] = 0.0;
570  return(*this);
571  };
572  double Norm() const
573  {
574  return(sqrt((V[0] * V[0]) + (V[1] * V[1]) + (V[2] * V[2])));
575  };
576  double Mag() const
577  {
578  return (Norm());
579  };
580  double Mag2() const
581  {
582  return ((V[0]*V[0])+(V[1]*V[1])+(V[2]*V[2]));
583  };
585  {
586  double n = Norm();
587  V[0] /= n;
588  V[1] /= n;
589  V[2] /= n;
590  return(*this);
591  };
592  C3Vector Unit() const
593  {
594  C3Vector v(*this);
595  return(v.Normalize());
596  };
600  double operator*(const C3Vector &v2) const
601  {
602  return((V[0] * v2.V[0]) +
603  (V[1] * v2.V[1]) +
604  (V[2] * v2.V[2]));
605  };
609  C3Vector operator*(double num) const
610  {
611  C3Vector rv(num*V[0],num*V[1],num*V[2]);
612  return(rv);
613  };
614  C3Vector &operator*=(double num)
615  {
616  V[0] *= num;
617  V[1] *= num;
618  V[2] *= num;
619  return(*this);
620  };
624  C3Vector operator%(const C3Vector &v2) const
625  {
626  C3Vector v;
627  v.V[0] = ((v2.V[2] * V[1]) - (v2.V[1] * V[2]));
628  v.V[1] = ((v2.V[0] * V[2]) - (v2.V[2] * V[0]));
629  v.V[2] = ((v2.V[1] * V[0]) - (v2.V[0] * V[1]));
630  return(v);
631  };
633  {
634  return(Copy(v2));
635  };
637  {
638  double t0 = V[0];
639  double t1 = V[1];
640  double t2 = V[2];
641  V[0] = ((v2.V[2] * t1) - (v2.V[1] * t2));
642  V[1] = ((v2.V[0] * t2) - (v2.V[2] * t0));
643  V[2] = ((v2.V[1] * t0) - (v2.V[0] * t1));
644  return(*this);
645  };
646  C3Vector operator+(const C3Vector &v2) const
647  {
648  C3Vector v(V[0] + v2.V[0], V[1] + v2.V[1], V[2] + v2.V[2]);
649  return(v);
650  };
651  C3Vector operator-(const C3Vector &v2) const
652  {
653  return((*this) + (-1.0 * v2));
654  };
656  {
657  V[0] += v2.V[0];
658  V[1] += v2.V[1];
659  V[2] += v2.V[2];
660  return(*this);
661  };
663  {
664  V[0] -= v2.V[0];
665  V[1] -= v2.V[1];
666  V[2] -= v2.V[2];
667  return(*this);
668  };
669  double &x()
670  {
671  return(V[0]);
672  };
673  double x() const
674  {
675  return(V[0]);
676  };
677  C3Vector &x(double i)
678  {
679  V[0] = i;
680  return(*this);
681  };
682  double &y()
683  {
684  return(V[1]);
685  };
686  double y() const
687  {
688  return(V[1]);
689  };
690  C3Vector &y(double i)
691  {
692  V[1] = i;
693  return(*this);
694  };
695  double &z()
696  {
697  return(V[2]);
698  };
699  double z() const
700  {
701  return(V[2]);
702  };
703  C3Vector &z(double i)
704  {
705  V[2] = i;
706  return(*this);
707  };
708  const double &operator[](unsigned int i) const
709  {
710  assert(i>0 && i<4);
711  return(V[i-1]);
712  };
713  double &operator[](unsigned int i)
714  {
715  assert(i>0 && i<4);
716  return(V[i-1]);
717  };
718  bool operator==(const C3Vector &v) const
719  {
720  return( (fabs(V[0] - v.V[0]) < TOL) &&
721  (fabs(V[1] - v.V[1]) < TOL) &&
722  (fabs(V[2] - v.V[2]) < TOL) );
723  };
724  bool operator<(const C3Vector &v) const
725  {
726  return (Mag2() < v.Mag2());
727  };
728  bool operator>(const C3Vector &v) const
729  {
730  return (Mag2() > v.Mag2());
731  };
732  bool operator<=(const C3Vector &v) const
733  {
734  return ( (*this < v) ||
735  (*this == v));
736  };
737  bool operator>=(const C3Vector &v) const
738  {
739  return ( (*this > v) ||
740  (*this == v) );
741  };
742  void DestroyData() { _destroy(); };
743  void SetData(double *d) {
744  V = d;
745  _mydata = false;
746  };
747  private:
748  void _create()
749  {
750  V = new double [3];
751  _mydata = true;
752  };
753  void _destroy()
754  {
755  if(_mydata){
756  delete [] V;
757  _mydata = false;
758  V = NULL;
759  }
760  };
761  };
762 
763  typedef C3Vector C3Point;
764 
765 
766 // class C3Point {
767 // friend C3Point operator*(double,const C3Point &p);
768 // friend std::ostream &operator<<(std::ostream &oSt,const C3Point &p);
769 // friend std::istream &operator>>(std::istream &iSt,C3Point &p);
770 // friend double Distance(const C3Point &p,const CLine &l);
771 // private:
772 // bool mydata;
773 // protected:
774 // double *P;
775 // // double P[3];
776 // public:
777 // C3Point()
778 // {
779 // _create();
780 // P[0] = P[1] = P[2] = 0.0;
781 // };
782 // C3Point(double ix,double iy,double iz = 0.0)
783 // {
784 // _create();
785 // P[0] = ix;
786 // P[1] = iy;
787 // P[2] = iz;
788 // };
789 // C3Point(double *p)
790 // {
791 // mydata = false;
792 // P = p;
793 // P[0] = p[0];
794 // P[1] = p[1];
795 // P[2] = p[2];
796 // };
797 // C3Point(const double *p)
798 // {
799 // _create();
800 // P[0] = p[0];
801 // P[1] = p[1];
802 // P[2] = p[2];
803 // };
804 // C3Point(C3Point &in)
805 // {
806 // mydata = false;
807 // P = in.P;
808 // };
809 // C3Point(const C3Point &in)
810 // {
811 // Copy(in);
812 // };
813 // ~C3Point()
814 // {
815 // _destroy();
816 // };
817 // bool Good()
818 // {
819 // return(!(P==NULL));
820 // };
821 // void _destroy()
822 // {
823 // if(mydata){
824 // mydata = false;
825 // delete [] P;
826 // P = NULL;
827 // }
828 // };
829 // void _create()
830 // {
831 // if(!mydata){
832 // mydata = true;
833 // P = new double [3];
834 // }
835 // Clear();
836 // };
837 // void Copy(const C3Point &in)
838 // {
839 // // _create();
840 // P[0] = in.P[0];
841 // P[1] = in.P[1];
842 // P[2] = in.P[2];
843 // };
844 // C3Point &Clear()
845 // {
846 // P[0] = 0.;
847 // P[1] = 0.;
848 // P[2] = 0;
849 // return(*this);
850 // };
851 // C3Point &Create()
852 // {
853 // _create();
854 // return(*this);
855 // };
856 // C3Point &Init(double ix,double iy,double iz = 0.0)
857 // {
858 // P[0] = ix;
859 // P[1] = iy;
860 // P[2] = iz;
861 // return(*this);
862 // };
863 // C3Point &Init(const double *p)
864 // {
865 // P[0] = p[0];
866 // P[1] = p[1];
867 // P[2] = p[2];
868 // return(*this);
869 // };
870 // C3Point &operator=(const C3Point &p)
871 // {
872 // P[0] = p.P[0];
873 // P[1] = p.P[1];
874 // P[2] = p.P[2];
875 // return(*this);
876 // };
877 // // CPoint &copy(const CPoint &p)
878 // // {
879 // // *this = p;
880 // // return(*this);
881 // // };
882 // double Norm() const
883 // {
884 // return(sqrt((x()*x()) + (y()*y()) + (z()*z())));
885 // };
886 // bool operator==(const C3Point &p) const
887 // {
888 // return( (fabs(P[0] - p.P[0]) < TOL) &&
889 // (fabs(P[1] - p.P[1]) < TOL) &&
890 // (fabs(P[2] - p.P[2]) < TOL) );
891 // };
892 // bool operator!=(const C3Point &p) const
893 // {
894 // return (!((*this)==p));
895 // };
896 // bool operator<(const C3Point &p) const
897 // {
898 // return (Norm() < p.Norm());
899 // };
900 // bool operator>(const C3Point &p) const
901 // {
902 // return (Norm() > p.Norm());
903 // };
904 // bool operator<=(const C3Point &p) const
905 // {
906 // return ((Norm() < p.Norm()) ||
907 // (*this == p));
908 // };
909 // bool operator>=(const C3Point &p) const
910 // {
911 // return((Norm() > p.Norm()) ||
912 // (*this == p));
913 // };
914 // C3Point &operator+=(const C3Point &p)
915 // {
916 // P[0] += p.P[0];
917 // P[1] += p.P[1];
918 // P[2] += p.P[2];
919 // return(*this);
920 // };
921 // C3Point &operator-=(const C3Point &p)
922 // {
923 // P[0] -= p.P[0];
924 // P[1] -= p.P[1];
925 // P[2] -= p.P[2];
926 // return(*this);
927 // };
928 // C3Point operator*(double num) const
929 // {
930 // C3Point rp(P[0]*num,P[1]*num,P[2]*num);
931 // return(rp);
932 // };
933 // C3Point &operator*=(double num)
934 // {
935 // P[0] *= num;
936 // P[1] *= num;
937 // P[2] *= num;
938 // return(*this);
939 // };
940 // double &x(){ return P[0]; };
941 // C3Point &x(double i)
942 // {
943 // P[0] = i;
944 // return(*this);
945 // };
946 // const double &x() const { return P[0]; };
947 // double &y(){ return P[1]; };
948 // C3Point &y(double i)
949 // {
950 // P[1] = i;
951 // return(*this);
952 // };
953 // const double &y() const { return P[1]; };
954 // double &z(){ return P[2]; };
955 // C3Point &z(double i)
956 // {
957 // P[2] = i;
958 // return(*this);
959 // }
960 // const double &z() const { return P[2]; };
961 // const double &operator[](unsigned int i) const
962 // {
963 // assert(i > 0 && i < 4);
964 // // if( i > 2 ) i = 0;
965 // return(P[i-1]);
966 // };
967 // double &operator[](unsigned int i)
968 // {
969 // assert(i > 0 && i < 4);
970 // return(P[i-1]);
971 // };
972 // C3Point operator+(const C3Point &p) const
973 // {
974 // C3Point rp(P[0]+p.P[0],P[1]+p.P[1],P[2]+p.P[2]);
975 // return(rp);
976 // };
977 // C3Point operator-(const C3Point &p) const
978 // {
979 // C3Point rp(P[0]-p.P[0],P[1]-p.P[1],P[2]-p.P[2]);
980 // return(rp);
981 // };
982 // double Distance(const C3Point &p) const
983 // {
984 // return((*this - p).Norm());
985 // }
986 // C3Point &Set(double ix,double iy,double iz)
987 // {
988 // P[0] = ix;
989 // P[1] = iy;
990 // P[2] = iz;
991 // return(*this);
992 // };
993 // C3Point &Reset()
994 // {
995 // P[0] = 0.0;
996 // P[1] = 0.0;
997 // P[2] = 0.0;
998 // return(*this);
999 // };
1000 // };
1001 
1002  class CLine {
1003  friend double Distance(const CPoint &p,const CLine &l);
1004  friend double Distance(const C3Point &p,const CLine &l);
1005  protected:
1008  public:
1010  {};
1011  CLine(const CPoint &p1,const CPoint &p2)
1012  : p(p1),v(p1,p2)
1013  {};
1014  CLine(const CLine &l)
1015  : p(l.p), v(l.v)
1016  {};
1017  CLine(const CPoint &p1,const CVector &v1)
1018  : p(p1),v(v1)
1019  {};
1020  CLine(const CVector &v1)
1021  : p(0,0,0),v(v1)
1022  {};
1023  CLine &move(const CPoint &p1)
1024  {
1025  p = p1;
1026  return(*this);
1027  };
1028  bool operator==(const CLine &l) const
1029  {
1030  return( (p == l.p) &&
1031  (v == l.v) );
1032  };
1033  bool has_point(const CPoint &p2) const
1034  {
1035  CVector v2(p2,p);
1036  v2.normalize();
1037  double r = v2 * v.unit();
1038  return( (fabs(r - 1.0) < TOL) ||
1039  (fabs(r + 1.0) < TOL) );
1040  };
1042  {
1043  return(v);
1044  };
1045  const CVector &slope() const
1046  {
1047  return(v);
1048  };
1050  {
1051  return(p);
1052  };
1053  const CPoint &point() const
1054  {
1055  return(p);
1056  };
1057  };
1058 
1060  protected:
1063  public:
1065  : p1(0,0,0),p2(0,0,0)
1066  {};
1068  : p1(0,0,0),p2(p)
1069  {};
1070  CLineSegment(const CPoint &pb,const CPoint &pe)
1071  : p1(pb),p2(pe)
1072  {};
1073  double length() const
1074  {
1075  CVector v(p1,p2);
1076  return(v.norm());
1077  };
1078  CVector slope() const
1079  {
1080  CVector v(p1,p2);
1081  return(v);
1082  };
1083  bool has_point(const CPoint &p3) const
1084  {
1085  if(p3 == p1 || p3 == p2) return true;
1086  if(p1 == p2) return false;
1087  CLine l(p1,p2);
1088  if(!l.has_point(p3)) return false;
1089  double u;
1090  if(p1.x() != p2.x())
1091  u = (p3.x() - p1.x())/(p2.x() - p1.x());
1092  else if(p1.y() != p2.y())
1093  u = (p3.y() - p1.y())/(p2.y() - p1.y());
1094  else if(p1.z() != p2.z())
1095  u = (p3.z() - p1.z())/(p2.z() - p1.z());
1096  return ( u >= 0.0 && u <= 1.0 );
1097  };
1099  {
1100  return (p1);
1101  };
1103  {
1104  return (p2);
1105  };
1106  const CPoint &point1() const
1107  {
1108  return (p1);
1109  };
1110  const CPoint &point2() const
1111  {
1112  return (p2);
1113  };
1115  {
1116  p1 = p;
1117  return(*this);
1118  };
1120  {
1121  p2 = p;
1122  return(*this);
1123  };
1124  };
1125 
1126  class CBox {
1127  friend std::ostream &operator<<(std::ostream &,const CBox &);
1128  private:
1129  bool initd;
1130  protected:
1131  CPoint p1; // xmin,ymin,zmin
1132  CPoint p2; // xmax,ymax,zmax
1133  public:
1135  {
1136  p1.reset();
1137  p2.reset();
1138  initd=false;
1139  };
1140  CBox(const std::vector<CPoint> &pv)
1141  {
1142  std::vector<CPoint>::const_iterator pvi = pv.begin();
1143  p1.x(pvi->x());
1144  p2.x(p1.x());
1145  p1.y(pvi->y());
1146  p2.y(p1.y());
1147  p1.z(pvi->z());
1148  p2.z(p1.z());
1149  pvi++;
1150  while(pvi != pv.end()){
1151  if(pvi->x() < p1.x()) p1.x(pvi->x());
1152  if(pvi->x() > p2.x()) p2.x(pvi->x());
1153  if(pvi->y() < p1.y()) p1.y(pvi->y());
1154  if(pvi->y() > p2.y()) p2.y(pvi->y());
1155  if(pvi->z() < p1.z()) p1.z(pvi->z());
1156  if(pvi->z() > p2.z()) p2.z(pvi->z());
1157  pvi++;
1158  }
1159  initd = true;
1160  }
1161  CBox(const double *points,unsigned int n)
1162  {
1163  p1.x(points[0]);
1164  p1.y(points[1]);
1165  p1.z(points[2]);
1166  p2 = p1;
1167  for(unsigned int i = 1;i<n;i++){
1168  if(points[i*3] < p1.x()) p1.x(points[i*3]);
1169  if(points[i*3] > p2.x()) p2.x(points[i*3]);
1170  if(points[(i*3)+1] < p1.y()) p1.y(points[(i*3)+1]);
1171  if(points[(i*3)+1] > p2.y()) p2.y(points[(i*3)+1]);
1172  if(points[(i*3)+2] < p1.z()) p1.z(points[(i*3)+2]);
1173  if(points[(i*3)+2] > p2.z()) p2.z(points[(i*3)+2]);
1174  }
1175  initd = true;
1176  };
1177  CBox(const CPoint &ip1,const CPoint &ip2)
1178  : p1(ip1),p2(ip2)
1179  {initd = true;};
1180  CBox(const CBox &box)
1181  : p1(box.p1),p2(box.p2)
1182  {initd = true;};
1183  const CPoint &P1() const {return p1;};
1184  const CPoint &P2() const {return p2;};
1185  bool empty() const {return ((std::fabs(p2.x()-p1.x()) < TOL) ||
1186  (std::fabs(p2.y()-p1.y()) < TOL) ||
1187  (std::fabs(p2.z()-p1.z()) < TOL));};
1188  CPoint &P1() {return p1;};
1189  CPoint &P2() {return p2;};
1190  void init(const double *points,unsigned int n)
1191  {
1192  initd = true;
1193  p1.x(points[0]);
1194  p1.y(points[1]);
1195  p1.z(points[2]);
1196  p2 = p1;
1197  for(unsigned int i = 1;i<n;i++){
1198  if(points[i*3] < p1.x()) p1.x(points[i*3]);
1199  if(points[i*3] > p2.x()) p2.x(points[i*3]);
1200  if(points[(i*3)+1] < p1.y()) p1.y(points[(i*3)+1]);
1201  if(points[(i*3)+1] > p2.y()) p2.y(points[(i*3)+1]);
1202  if(points[(i*3)+2] < p1.z()) p1.z(points[(i*3)+2]);
1203  if(points[(i*3)+2] > p2.z()) p2.z(points[(i*3)+2]);
1204  }
1205  };
1206  CBox &operator=(const CBox &b)
1207  {
1208  p1 = b.p1;
1209  p2 = b.p2;
1210  initd = true;
1211  return(*this);
1212  };
1213  CBox around(const CPoint &p) const
1214  {
1215  CVector v(p1,p2);
1216  CPoint minp(p.x()-fabs(v.x()/2.0),
1217  p.y()-fabs(v.y()/2.0),
1218  p.z()-fabs(v.z()/2.0));
1219  CPoint maxp(p.x()+fabs(v.x()/2.0),
1220  p.y()+fabs(v.y()/2.0),
1221  p.z()+fabs(v.z()/2.0));
1222  CBox box(minp,maxp);
1223  return(box);
1224  };
1225  bool operator==(const CBox &b) const
1226  {
1227  return(p1 == b.p1 && p2 == b.p2);
1228  };
1229  // CBox operator&(const CBox &b) const
1230  // {
1231  // return(this->intersect(b));
1232  // };
1234  {
1235  return(p1);
1236  };
1237  const CPoint &min() const
1238  {
1239  return(p1);
1240  };
1242  {
1243  return(p2);
1244  };
1245  const CPoint &max() const
1246  {
1247  return(p2);
1248  };
1249  bool contains(const CPoint &p) const
1250  {
1251  return( p.x() <= p2.x() && p.x() >= p1.x() &&
1252  p.y() <= p2.y() && p.y() >= p1.y() &&
1253  p.z() <= p2.z() && p.z() >= p1.z() );
1254  };
1255  bool contains(const double *p) const
1256  {
1257  return( p[0] <= p2.x() && p[0] >= p1.x() &&
1258  p[1] <= p2.y() && p[1] >= p1.y() &&
1259  p[2] <= p2.z() && p[2] >= p1.z() );
1260  };
1261  // Volume of the box
1262  double size() const
1263  {
1264  CVector v(p1,p2);
1265  return(fabs(v.x()*v.y()*v.z()));
1266  };
1267  bool operator<(const CBox &b) const
1268  {
1269  return(this->size() < b.size());
1270  };
1271  bool operator>(const CBox &b) const
1272  {
1273  return(this->size() > b.size());
1274  };
1275  void AddPoint(const CPoint &p)
1276  {
1277  if(!initd){
1278  p1 = p;
1279  p2 = p;
1280  initd = true;
1281  }
1282  else{
1283  if(p.x() < p1.x()) p1.x() = p.x();
1284  if(p.x() > p2.x()) p2.x() = p.x();
1285  if(p.y() < p1.y()) p1.y() = p.y();
1286  if(p.y() > p2.y()) p2.y() = p.y();
1287  if(p.z() < p1.z()) p1.z() = p.z();
1288  if(p.z() > p2.z()) p2.z() = p.z();
1289  }
1290  };
1291  void merge(const CBox &b)
1292  {
1293  if(initd){
1294  CPoint p(p1);
1295  p1.x((b.p1.x() > p1.x() ? p.x() : b.p1.x()));
1296  p1.y((b.p1.y() > p1.y() ? p.y() : b.p1.y()));
1297  p1.z((b.p1.z() > p1.z() ? p.z() : b.p1.z()));
1298  p = p2;
1299  p2.x(b.p2.x() < p2.x() ? p.x() : b.p2.x());
1300  p2.y(b.p2.y() < p2.y() ? p.y() : b.p2.y());
1301  p2.z(b.p2.z() < p2.z() ? p.z() : b.p2.z());
1302  }
1303  else {
1304  p1 = b.p1;
1305  p2 = b.p2;
1306  initd = true;
1307  }
1308  };
1309  bool collide(const CBox &b) const
1310  {
1311  if(this->empty() || b.empty())
1312  return(false);
1313  return(!(b.p2.x() < p1.x() || b.p1.x() > p2.x()) &&
1314  !(b.p2.y() < p1.y() || b.p1.y() > p2.y()) &&
1315  !(b.p2.z() < p1.z() || b.p1.z() > p2.z()));
1316  };
1317  CBox intersect(const CBox &b) const
1318  {
1319  CBox retval;
1320  if(collide(b)){
1321  retval.p1.x(b.p1.x() > p1.x() ? b.p1.x() : p1.x());
1322  retval.p1.y(b.p1.y() > p1.y() ? b.p1.y() : p1.y());
1323  retval.p1.z(b.p1.z() > p1.z() ? b.p1.z() : p1.z());
1324  retval.p2.x(b.p2.x() < p2.x() ? b.p2.x() : p2.x());
1325  retval.p2.y(b.p2.y() < p2.y() ? b.p2.y() : p2.y());
1326  retval.p2.z(b.p2.z() < p2.z() ? b.p2.z() : p2.z());
1327  }
1328  return(retval);
1329  };
1330  };
1331 
1332  class CPlane {
1333  protected:
1336  public:
1337  CPlane(){};
1338  CPlane(const CPoint &p1,const CPoint &p2,const CPoint &p3)
1339  : p(p1)
1340  {
1341  double A = p1.y()*(p2.z() - p3.z()) + p2.y()*(p3.z() - p1.z()) +
1342  p3.y()*(p1.z() - p2.z());
1343  double B = p1.z()*(p2.x() - p3.x()) + p2.z()*(p3.x() - p1.x()) +
1344  p3.z()*(p1.x() - p2.x());
1345  double C = p1.x()*(p2.y() - p3.y()) + p2.x()*(p3.y() - p1.y()) +
1346  p3.x()*(p1.y() - p2.y());
1347  // double D = -1.0 * ( p1.x()*(p2.y()*p3.z() - p3.y()*p2.z()) +
1348  // p2.x()*(p3.y()*p1.z() - p1.y()*p3.z()) +
1349  // p3.x()*(p1.y()*p2.z() - p2.y()*p1.z()) );
1350 
1351  n.x(A).y(B).z(C);
1352  n.normalize();
1353  };
1354  CPlane(const CVector &N,const CPoint &P)
1355  : n(N.unit()),p(P)
1356  {};
1357  CPlane(const CPlane &plane)
1358  : n(plane.n),p(plane.p)
1359  {};
1360  CPlane(const std::vector<CPoint> &vec)
1361  : p(vec[0])
1362  {
1363  double A = vec[0].y()*(vec[1].z() - vec[2].z()) +
1364  vec[1].y()*(vec[2].z() - vec[0].z()) +
1365  vec[2].y()*(vec[0].z() - vec[1].z());
1366  double B = vec[0].z()*(vec[1].x() - vec[2].x()) +
1367  vec[1].z()*(vec[2].x() - vec[0].x()) +
1368  vec[2].z()*(vec[0].x() - vec[1].x());
1369  double C = vec[0].x()*(vec[1].y() - vec[2].y()) +
1370  vec[1].x()*(vec[2].y() - vec[0].y()) +
1371  vec[2].x()*(vec[0].y() - vec[1].y());
1372  // double D = -1.0 * ( p1.x()*(p2.y()*p3.z() - p3.y()*p2.z()) +
1373  // p2.x()*(p3.y()*p1.z() - p1.y()*p3.z()) +
1374  // p3.x()*(p1.y()*p2.z() - p2.y()*p1.z()) );
1375 
1376  n.x(A).y(B).z(C);
1377  n.normalize();
1378  } ;
1379  CPlane &operator=(const CPlane &plane)
1380  {
1381  n = plane.n;
1382  p = plane.p;
1383  return(*this);
1384  };
1385  double A() const { return(n.x()); };
1386  double B() const { return(n.y()); };
1387  double C() const { return(n.z()); };
1388  double D() const
1389  {
1390  return( -1.0 * ( n.x()*p.x() + n.y()*p.y() + n.z()*p.z()));
1391  };
1392  CVector &normal() { return(n); };
1393  const CVector &normal() const { return(n); };
1394  CPoint &point() { return(p); };
1395  const CPoint &point() const { return(p); };
1396  bool contains_point(const CPoint &P) const
1397  {
1398  return(fabs(n.x()*P.x() + n.y()*P.y() + n.z()*P.z() + D()) <= TOL);
1399  };
1400  bool operator==(const CPlane &plane) const
1401  {
1402  return((plane.n.unit() == n.unit()) && contains_point(plane.p));
1403  };
1404  };
1405 
1406  class C3Plane {
1407  protected:
1410  public:
1411  C3Plane(){};
1412  C3Plane(const C3Point &p1,const C3Point &p2,const C3Point &p3)
1413  : p(p1)
1414  {
1415  double A = p1.y()*(p2.z() - p3.z()) + p2.y()*(p3.z() - p1.z()) +
1416  p3.y()*(p1.z() - p2.z());
1417  double B = p1.z()*(p2.x() - p3.x()) + p2.z()*(p3.x() - p1.x()) +
1418  p3.z()*(p1.x() - p2.x());
1419  double C = p1.x()*(p2.y() - p3.y()) + p2.x()*(p3.y() - p1.y()) +
1420  p3.x()*(p1.y() - p2.y());
1421  // double D = -1.0 * ( p1.x()*(p2.y()*p3.z() - p3.y()*p2.z()) +
1422  // p2.x()*(p3.y()*p1.z() - p1.y()*p3.z()) +
1423  // p3.x()*(p1.y()*p2.z() - p2.y()*p1.z()) );
1424 
1425  n.x(A).y(B).z(C);
1426  n.Normalize();
1427  };
1428  C3Plane(const C3Vector &N,const C3Point &P)
1429  : n(N.Unit()),p(P)
1430  {};
1431  C3Plane(const C3Plane &plane)
1432  : n(plane.n),p(plane.p)
1433  {};
1434  C3Plane(const std::vector<C3Point> &vec)
1435  : p(vec[0])
1436  {
1437  double A = vec[0].y()*(vec[1].z() - vec[2].z()) +
1438  vec[1].y()*(vec[2].z() - vec[0].z()) +
1439  vec[2].y()*(vec[0].z() - vec[1].z());
1440  double B = vec[0].z()*(vec[1].x() - vec[2].x()) +
1441  vec[1].z()*(vec[2].x() - vec[0].x()) +
1442  vec[2].z()*(vec[0].x() - vec[1].x());
1443  double C = vec[0].x()*(vec[1].y() - vec[2].y()) +
1444  vec[1].x()*(vec[2].y() - vec[0].y()) +
1445  vec[2].x()*(vec[0].y() - vec[1].y());
1446  // double D = -1.0 * ( p1.x()*(p2.y()*p3.z() - p3.y()*p2.z()) +
1447  // p2.x()*(p3.y()*p1.z() - p1.y()*p3.z()) +
1448  // p3.x()*(p1.y()*p2.z() - p2.y()*p1.z()) );
1449 
1450  n.x(A).y(B).z(C);
1451  n.Normalize();
1452  } ;
1453  C3Plane &operator=(const C3Plane &plane)
1454  {
1455  n = plane.n;
1456  p = plane.p;
1457  return(*this);
1458  };
1459  double A() const { return(n.x()); };
1460  double B() const { return(n.y()); };
1461  double C() const { return(n.z()); };
1462  double D() const
1463  {
1464  return( -1.0 * ( n.x()*p.x() + n.y()*p.y() + n.z()*p.z()));
1465  };
1466  C3Vector &normal() { return(n); };
1467  const C3Vector &normal() const { return(n); };
1468  C3Point &point() { return(p); };
1469  const C3Point &point() const { return(p); };
1470  bool contains_point(const C3Point &P) const
1471  {
1472  return(fabs(n.x()*P.x() + n.y()*P.y() + n.z()*P.z() + D()) <= TOL);
1473  };
1474  bool operator==(const C3Plane &plane) const
1475  {
1476  return((plane.n.Unit() == n.Unit()) && contains_point(plane.p));
1477  };
1478  };
1479 
1480  template<typename PointContainer>
1481  C3Point C3Centroid(const PointContainer &pc)
1482  {
1483  double x = 0.0;
1484  double y = 0.0;
1485  double z = 0.0;
1486  double np = 1.0/static_cast<double>(pc.size());
1487  typename PointContainer::const_iterator pi = pc.begin();
1488  while(pi != pc.end()){
1489  x += (*pi)->x();
1490  y += (*pi)->y();
1491  z += (*pi)->z();
1492  pi++;
1493  }
1494  x *= np;
1495  y *= np;
1496  z *= np;
1497  return(C3Point(x,y,z));
1498  };
1499 
1500  template<typename PointContainer>
1501  CPoint Centroid(const PointContainer &pc)
1502  {
1503  double x = 0.0;
1504  double y = 0.0;
1505  double z = 0.0;
1506  double np = 1.0/static_cast<double>(pc.size());
1507  typename PointContainer::const_iterator pi = pc.begin();
1508  while(pi != pc.end()){
1509  x += pi->x();
1510  y += pi->y();
1511  z += pi->z();
1512  pi++;
1513  }
1514  x *= np;
1515  y *= np;
1516  z *= np;
1517  return(CPoint(x,y,z));
1518  };
1519 
1520  class CFacet : public std::vector<CPoint>
1521  {
1522  public:
1523  CFacet(){};
1524  CFacet(const CPoint &P1,const CPoint &P2,const CPoint &P3)
1525  {
1526  this->resize(3);
1527  (*this)[0] = P1;
1528  (*this)[1] = P2;
1529  (*this)[2] = P3;
1530  };
1531  CFacet(const CPoint &P1,const CPoint &P2,const CPoint &P3,
1532  const CPoint &P4)
1533  {
1534  this->resize(4);
1535  (*this)[0] = P1;
1536  (*this)[1] = P2;
1537  (*this)[2] = P3;
1538  (*this)[3] = P4;
1539  };
1540  CFacet(const std::vector<CPoint> &v)
1541  {
1542  std::vector<CPoint>::const_iterator pi = v.begin();
1543  while(pi != v.end())
1544  this->push_back(*pi++);
1545  };
1547  {
1548  std::vector<CPoint>::const_iterator fi = face.begin();
1549  while(fi != face.end())
1550  this->push_back(*fi++);
1551  };
1552  CVector normal() const
1553  {
1554  CVector v1((*this)[0],(*this)[1]);
1555  CVector v2((*this)[0],(*this)[2]);
1556  return(.5*(v1%v2));
1557  };
1559  {
1560  return(Centroid(*this));
1561  };
1563  {
1564  this->clear();
1565  std::vector<CPoint>::const_iterator fi = face.begin();
1566  while(fi != face.end())
1567  this->push_back(*fi++);
1568  return(*this);
1569  };
1570  bool operator==(const CFacet &face) const
1571  {
1572  std::vector<CPoint>::const_iterator li = this->begin();
1573  std::vector<CPoint>::const_iterator fi = face.begin();
1574  if(this->size() != face.size()) return false;
1575  while(li != this->end())
1576  if(!(*li++ == *fi++))
1577  return(false);
1578  return(true);
1579  };
1580  bool contains_point(const CPoint &P)
1581  {
1582  CPlane plane((*this)[0],(*this)[1],(*this)[2]);
1583  if(!(plane.contains_point(P)))
1584  return false;
1585  std::vector<CPoint>::const_iterator fi = this->begin();
1586  CVector v1(P,*fi);
1587  CVector vp(v1);
1588  fi++;
1589  double angle = 0.0;
1590  while(fi != this->end()){
1591  CVector v(P,(*fi));
1592  angle += acos(v*vp);
1593  vp = v;
1594  fi++;
1595  }
1596  angle += acos(vp*v1);
1597  return((fabs(angle) - 2*PI) <= TOL);
1598  };
1599 
1600 
1601  };
1602 
1603 
1604  class C3Facet : public std::vector<const C3Point *>
1605  {
1606  private:
1607  bool _mydata;
1608  public:
1610  {
1611  _mydata = false;
1612  };
1613  C3Facet(const C3Point *P1,const C3Point *P2,const C3Point *P3)
1614  {
1615  _mydata = false;
1616  this->resize(3);
1617  (*this)[0] = P1;
1618  (*this)[1] = P2;
1619  (*this)[2] = P3;
1620  };
1621  C3Facet(const C3Point *P1,const C3Point *P2,const C3Point *P3,const C3Point *P4)
1622  {
1623  _mydata = false;
1624  this->resize(4);
1625  (*this)[0] = P1;
1626  (*this)[1] = P2;
1627  (*this)[2] = P3;
1628  (*this)[3] = P4;
1629  };
1630  C3Facet(const C3Point &P1,const C3Point &P2,const C3Point &P3)
1631  {
1632  _mydata = true;
1633  this->resize(3);
1634  (*this)[0] = _copycreate_point(P1);
1635  (*this)[1] = _copycreate_point(P2);
1636  (*this)[2] = _copycreate_point(P3);
1637  };
1638  C3Facet(const C3Point &P1,const C3Point &P2,const C3Point &P3,
1639  const C3Point &P4)
1640  {
1641  _mydata = true;
1642  this->resize(4);
1643  (*this)[0] = _copycreate_point(P1);
1644  (*this)[1] = _copycreate_point(P2);
1645  (*this)[2] = _copycreate_point(P3);
1646  (*this)[3] = _copycreate_point(P4);
1647  };
1648  C3Facet(const std::vector<const C3Point *> &v)
1649  {
1650  std::vector<const C3Point *>::const_iterator pi = v.begin();
1651  while(pi != v.end())
1652  this->push_back(*pi++);
1653  };
1654 // C3Facet(const std::vector<const C3Point> &v)
1655 // {
1656 // std::vector<const C3Point>::const_iterator pi = v.begin();
1657 // while(pi != v.end())
1658 // this->push_back(_copycreate_point(*pi++));
1659 // };
1661  {
1662  C3Facet::const_iterator fi = face.begin();
1663  while(fi != face.end())
1664  this->push_back(*fi++);
1665  };
1667  {
1668  C3Vector v1(*((*this)[0]),*((*this)[1]));
1669  C3Vector v2(*((*this)[0]),*((*this)[2]));
1670  return(.5*(v1%v2));
1671  };
1673  {
1674  return(C3Centroid(*this));
1675  };
1677  {
1678  this->clear();
1679  C3Facet::const_iterator fi = face.begin();
1680  while(fi != face.end())
1681  this->push_back(*fi++);
1682  return(*this);
1683  };
1684  bool operator==(const C3Facet &face) const
1685  {
1686  C3Facet::const_iterator li = this->begin();
1687  C3Facet::const_iterator fi = face.begin();
1688  if(this->size() != face.size()) return false;
1689  while(li != this->end())
1690  if(!(*(*li++) == *(*fi++)))
1691  return(false);
1692  return(true);
1693  };
1694 // bool contains_point(const C3Point &P)
1695 // {
1696 // CPlane plane(*(*this)[0],*(*this)[1],*(*this)[2]);
1697 // if(!(plane.contains_point(P)))
1698 // return false;
1699 // std::vector<CPoint>::const_iterator fi = this->begin();
1700 // CVector v1(P,*fi);
1701 // CVector vp(v1);
1702 // fi++;
1703 // double angle = 0.0;
1704 // while(fi != this->end()){
1705 // CVector v(P,(*fi));
1706 // angle += acos(v*vp);
1707 // vp = v;
1708 // fi++;
1709 // }
1710 // angle += acos(vp*v1);
1711 // return((fabs(angle) - 2*PI) <= TOL);
1712 // };
1713  private:
1715  {
1716  C3Point *rp = new C3Point;
1717  rp->Copy(p);
1718  return(rp);
1719  };
1721  {
1722  C3Point *rp = new C3Point;
1723  return(rp);
1724  };
1725 
1726  };
1727 
1728  void
1729  Transpose(CVector matrix[]);
1730  void
1731  Transpose_2x3(CVector matrix[],double tpose[][2]);
1732 
1733 
1734  double
1735  Distance(const CPoint &p,const CLine &l);
1736 
1737 }
1738 #endif // GeoPrimitives
/brief Cartesian 3 Vector
bool operator>(const CPoint &p) const
const CPoint & min() const
CPoint & y(double i)
CBox & operator=(const CBox &b)
C3Point * _copycreate_point(const C3Point &p)
const double & operator[](unsigned int i) const
const double PI
Definition: GeoPrimitives.H:18
bool operator==(const CPlane &plane) const
C3Vector Unit() const
bool operator<=(const CPoint &p) const
C3Vector operator+(const C3Vector &v2) const
CVector & operator%=(const CVector &v2)
friend double Distance(const CPoint &p, const GeoPrim::CLine &l)
CVector operator%(const CVector &v2) const
CPoint & init()
Definition: GeoPrimitives.H:52
CBox(const CPoint &ip1, const CPoint &ip2)
C3Vector & Init(const double *a)
CLineSegment(const CPoint &pb, const CPoint &pe)
const C3Point & point() const
double norm() const
Definition: GeoPrimitives.H:85
void AddPoint(const CPoint &p)
CPoint centroid() const
CPoint(double ix, double iy, double iz=0.0)
Definition: GeoPrimitives.H:34
void init(const double *points, unsigned int n)
CVector(const CPoint &p)
double C() const
friend double Distance(const CPoint &p, const CLine &l)
Definition: face.h:90
const NT & d
bool operator<(const CVector &v) const
bool operator<(const CPoint &p) const
Definition: GeoPrimitives.H:99
const CVector & normal() const
C3Vector & Init(const C3Vector &v)
const CPoint & P2() const
void int int REAL REAL * y
Definition: read.cpp:74
double norm() const
double B() const
double y() const
friend std::istream & operator>>(std::istream &iSt, CPoint &p)
Definition: GeoPrimitives.C:69
CVector(const CPoint &p1, const CPoint &p2)
C3Plane(const C3Vector &N, const C3Point &P)
C3Vector & normal()
double Norm() const
const CPoint & point1() const
double z() const
double y() const
CVector(const CVector &v)
C3Vector(double ix, double iy, double iz=0.0)
C3Vector & operator+=(const C3Vector &v2)
NT p1
C3Point & point()
CVector & init()
KD_tree::Box box
Definition: Overlay_0d.C:47
const CPoint & point() const
bool operator>=(const C3Vector &v) const
CVector & init(const double *a)
double B() const
bool operator==(const CVector &v) const
bool operator>(const CBox &b) const
C3Plane & operator=(const C3Plane &plane)
CVector & operator-=(const CVector &v2)
C3Vector operator-(const C3Vector &v2) const
C3Vector(const C3Vector &p1, const C3Vector &p2)
C3Vector & Init(const C3Vector &p1, const C3Vector &p2)
double operator*(const C3Vector &v2) const
Dot Product.
CLineSegment & point1(const CPoint &p)
CPoint & set(double ix, double iy, double iz)
Definition: points.h:30
CPoint & reset()
bool contains(const double *p) const
CVector & init(const CPoint &p1, const CPoint &p2)
CPlane(const CVector &N, const CPoint &P)
bool contains_point(const CPoint &P) const
CVector operator*(double num) const
C3Vector Normal() const
CVector & operator+=(const CPoint &p)
double z() const
C3Facet(const C3Point &P1, const C3Point &P2, const C3Point &P3, const C3Point &P4)
C3Facet & operator=(const C3Facet &face)
double sqrt(double d)
Definition: double.h:73
bool contains(const CPoint &p) const
double D() const
CPoint(const CPoint &in)
Definition: GeoPrimitives.H:46
C3Vector(double *a)
friend std::istream & operator>>(std::istream &, C3Vector &)
CVector unit() const
bool operator!=(const CPoint &p) const
Definition: GeoPrimitives.H:95
CVector & operator*=(double num)
CVector(double ix, double iy, double iz=0.0)
bool operator<=(const CVector &v) const
CFacet(const CPoint &P1, const CPoint &P2, const CPoint &P3, const CPoint &P4)
CPoint & operator*=(double num)
C3Point C3Centroid(const PointContainer &pc)
*********************************************************************Illinois Open Source License ****University of Illinois NCSA **Open Source License University of Illinois All rights reserved ****Developed free of to any person **obtaining a copy of this software and associated documentation to deal with the Software without including without limitation the rights to and or **sell copies of the and to permit persons to whom the **Software is furnished to do subject to the following this list of conditions and the following disclaimers ****Redistributions in binary form must reproduce the above **copyright this list of conditions and the following **disclaimers in the documentation and or other materials **provided with the distribution ****Neither the names of the Center for Simulation of Advanced the University of nor the names of its **contributors may be used to endorse or promote products derived **from this Software without specific prior written permission ****THE SOFTWARE IS PROVIDED AS WITHOUT WARRANTY OF ANY **EXPRESS OR INCLUDING BUT NOT LIMITED TO THE WARRANTIES **OF FITNESS FOR A PARTICULAR PURPOSE AND **NONINFRINGEMENT IN NO EVENT SHALL THE CONTRIBUTORS OR **COPYRIGHT HOLDERS BE LIABLE FOR ANY DAMAGES OR OTHER WHETHER IN AN ACTION OF TORT OR **ARISING OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE **USE OR OTHER DEALINGS WITH THE SOFTWARE v
Definition: roccomf90.h:20
CPoint & point()
CBox(const std::vector< CPoint > &pv)
double x() const
C3Vector & operator-=(const C3Vector &v2)
double & operator[](unsigned int i)
CPoint operator*(double num) const
const double TOL
Definition: GeoPrimitives.H:17
CVector operator+(const CVector &v2) const
CFacet(const std::vector< CPoint > &v)
double mag() const
CVector normal() const
CPoint & x(double i)
double mag2() const
const CPoint & point2() const
CLine(const CPoint &p1, const CPoint &p2)
double C() const
C3Vector(const C3Vector &v)
double size() const
C3Vector & Copy(const C3Vector &v)
C3Vector(const GeoPrim::CVector &inv)
CVector & init(const CVector &v)
bool operator==(const C3Plane &plane) const
double length() const
CPoint & operator-=(const CPoint &p)
C3Point * _create_point()
void int int int REAL REAL REAL * z
Definition: write.cpp:76
CPoint operator-(const CPoint &p) const
CVector & init(double ix, double iy, double iz)
bool operator==(const CLine &l) const
bool operator==(const CPoint &p) const
Definition: GeoPrimitives.H:89
double & operator[](unsigned int i)
CVector & init(const CPoint &p)
CVector & z(double i)
CPoint & point()
friend std::ostream & operator<<(std::ostream &, const C3Vector &)
void SetData(double *d)
CVector & operator=(const CVector &v2)
const CVector & slope() const
const double & operator[](unsigned int i) const
CVector & operator+=(const CVector &v2)
C3Vector & z(double i)
C3Vector operator%(const C3Vector &v2) const
Cross Product.
blockLoc i
Definition: read.cpp:79
double angle(Vector_3< double > v1, Vector_3< double > v2)
Compute the angle between two vectors.
Definition: geometry.C:61
CPoint(const double *p)
Definition: GeoPrimitives.H:40
CBox(const double *points, unsigned int n)
CPoint Centroid(const PointContainer &pc)
void int int REAL * x
Definition: read.cpp:74
const CPoint & point() const
C3Vector & Clear()
C3Vector operator*(double num) const
Scaling.
CLineSegment & point2(const CPoint &p)
bool contains_point(const CPoint &P)
double operator*(const CVector &v2) const
double A() const
CVector slope() const
const NT & n
CBox(const CBox &box)
CFacet(const CFacet &face)
CImg< _cimg_Tfloat > atan(const CImg< T > &instance)
Definition: CImg.h:6061
double x() const
CPoint & P1()
C3Vector & Init(double ix, double iy, double iz)
const C3Vector & normal() const
CLine(const CLine &l)
const double & x() const
bool operator==(const C3Facet &face) const
CLine(const CPoint &p1, const CVector &v1)
friend std::istream & operator>>(std::istream &, CVector &)
Definition: GeoPrimitives.C:97
CPoint & min()
friend CVector operator*(double, const CVector &)
CFacet & operator=(const CFacet &face)
bool operator<(const CBox &b) const
C3Plane(const std::vector< C3Point > &vec)
const double & z() const
CPoint & init(const double *p)
Definition: GeoPrimitives.H:66
bool operator>=(const CPoint &p) const
void Transpose(CVector matrix[])
Definition: GeoPrimitives.C:11
CPoint & copy(const CPoint &p)
Definition: GeoPrimitives.H:80
friend CPoint operator*(double, const CPoint &p)
C3Vector & operator%=(const C3Vector &v2)
C3Vector & y(double i)
C3Facet(const C3Point &P1, const C3Point &P2, const C3Point &P3)
const double & y() const
friend C3Vector operator*(double, const C3Vector &)
C3Facet(const C3Point *P1, const C3Point *P2, const C3Point *P3)
CVector & copy(const CVector &v2)
double D() const
CVector & operator=(const CPoint &p)
CPoint & init(double ix, double iy, double iz=0.0)
Definition: GeoPrimitives.H:59
C3Vector & Normalize()
bool operator==(const CBox &b) const
CVector & normalize()
CVector & slope()
C3Vector(const CPoint &inp)
CPoint & operator=(const CPoint &p)
Definition: GeoPrimitives.H:73
C3Vector & Init()
CPlane(const std::vector< CPoint > &vec)
CBox around(const CPoint &p) const
CPoint & operator+=(const CPoint &p)
C3Point Centroid() const
CFacet(const CPoint &P1, const CPoint &P2, const CPoint &P3)
bool has_point(const CPoint &p2) const
const double pi
CVector operator-(const CVector &v2) const
friend std::ostream & operator<<(std::ostream &, const CBox &)
Definition: GeoPrimitives.C:55
bool has_point(const CPoint &p3) const
void inv(Matrix3D &Ainv, const Matrix3D &A)
bool operator<(const C3Vector &v) const
CPlane & operator=(const CPlane &plane)
bool operator>(const CVector &v) const
bool operator>(const C3Vector &v) const
C3Facet(const C3Point *P1, const C3Point *P2, const C3Point *P3, const C3Point *P4)
bool contains_point(const C3Point &P) const
bool operator>=(const CVector &v) const
void merge(const CBox &b)
C3Vector & x(double i)
CBox intersect(const CBox &b) const
CVector & normal()
C3Plane(const C3Point &p1, const C3Point &p2, const C3Point &p3)
CPoint operator+(const CPoint &p) const
friend std::ostream & operator<<(std::ostream &oSt, const CPoint &p)
Definition: GeoPrimitives.C:62
CImg< _cimg_Tfloat > acos(const CImg< T > &instance)
Definition: CImg.h:6051
CPlane(const CPlane &plane)
double Mag2() const
C3Vector(const double *a)
CVector & x(double i)
CLine(const CVector &v1)
CVector(const double *a)
bool collide(const CBox &b) const
CPoint & P2()
double & operator[](unsigned int i)
C3Vector C3Point
friend std::ostream & operator<<(std::ostream &, const CVector &)
Definition: GeoPrimitives.C:90
double A() const
C3Vector & operator*=(double num)
C3Facet(const C3Facet &face)
double Distance(const CPoint &p) const
double Mag() const
C3Facet(const std::vector< const C3Point * > &v)
CLineSegment(const CPoint &p)
bool operator==(const C3Vector &v) const
CLine & move(const CPoint &p1)
double Distance(const CPoint &p, const CLine &l)
Definition: GeoPrimitives.C:35
C3Vector & operator=(const C3Vector &v2)
void Transpose_2x3(CVector matrix[], double tpose[][2])
Definition: GeoPrimitives.C:24
const CPoint & max() const
C3Plane(const C3Plane &plane)
const double & operator[](unsigned int i) const
bool empty() const
CPoint & z(double i)
CVector & y(double i)
const CPoint & P1() const
CPlane(const CPoint &p1, const CPoint &p2, const CPoint &p3)
CPoint & max()
bool operator==(const CFacet &face) const
bool operator<=(const C3Vector &v) const