cryph utilities [subset]  2.0
Subset of the full cryph package of mathematical utilities for points, vectors, and matrices
AffPoint.h
Go to the documentation of this file.
1 
7 #ifndef AFFPOINT_H
8 #define AFFPOINT_H
9 
10 #include <math.h>
11 #include <iostream>
12 
13 #include "AffVector.h"
14 
15 namespace cryph
16 {
17 
18 // indices for extracting coordinates from points
19 
20 const int X = 0;
21 const int Y = 1;
22 const int Z = 2;
23 const int W = 3;
24 
25 class AffPoint
26 {
27 public:
29  AffPoint();
30 
34  AffPoint(const AffPoint& P);
35 
39  AffPoint(const AffVector& v);
40 
46  AffPoint(double xx, double yy, double zz=0.0);
47 
51  AffPoint(const double P[]);
52 
56  AffPoint(const float P[]);
57 
59  virtual ~AffPoint();
60 
65  AffPoint operator=(const AffPoint& rhs);
66 
71  AffPoint operator+=(const AffVector& rhs);
72 
77  AffPoint operator+=(const AffPoint& rhs);
78 
83  AffPoint operator-=(const AffVector& rhs);
84 
89  AffPoint operator*=(double f);
90 
95  AffPoint operator/=(double f);
96 
102  double operator[](int index) const;
103 
108  AffPoint operator+(const AffPoint& p2) const
109  { return AffPoint(x + p2.x, y + p2.y, z + p2.z); }
110 
115  AffPoint operator*(double f) const
116  { return AffPoint (f*x, f*y, f*z); }
117 
123  AffPoint operator/(double f) const
124  { return AffPoint (x/f, y/f, z/f); }
125 
130  AffVector operator-(const AffPoint& p2) const
131  { return AffVector(x-p2.x, y-p2.y, z-p2.z); }
132 
137  AffPoint operator+(const AffVector& v2) const
138  { return AffPoint(x+v2[DX], y+v2[DY], z+v2[DZ]); }
139 
145  AffPoint operator-(const AffVector& v2) const
146  { return AffPoint(x-v2[DX], y-v2[DY], z-v2[DZ]); }
147 
169  double* aCoords(double* coords, int offset=0) const;
170 
193  double* aCoords(double coords[][3], int offset=0) const;
194 
215  float* aCoords(float* coords, int offset=0) const;
216 
238  float* aCoords(float coords[][3], int offset=0) const;
239 
245  void assign(double xx, double yy, double zz);
246 
263  void barycentricCoords( // in a plane
264  // find the areal Barycentric coordinates
265  // of "this" point with respect to:
266  const AffPoint& P1, const AffPoint& P2, const AffPoint& P3,
267  // returning them in: (b1+b2+b3 = 1)
268  double& b1, double& b2, double& b3) const;
269 
284  void barycentricCoords( // on a line
285  // find the areal Barycentric coordinates of "this"
286  // point with respect to:
287  const AffPoint& P1, const AffPoint& P2,
288  // returning them in: (b1+b2 = 1)
289  double& b1, double& b2) const;
290 
299  bool coincidentWith(const AffPoint& p) const;
300 
306  double distanceFromLine(const AffPoint& B, const AffVector& u) const;
307 
311  double distanceFromOrigin() const;
312 
319  double distanceSquaredFromLine(const AffPoint& B, const AffVector& u) const;
320 
324  double distanceSquaredFromOrigin() const;
325 
330  double distanceSquaredTo(const AffPoint& p) const;
331 
336  double distanceTo(const AffPoint& p) const;
337 
341  double normalize();
342 
365  double* pCoords(double* coords, double w, int offset=0) const;
366 
388  float* pCoords(float* coords, float w, int offset=0) const;
389 
403  void swizzle(char xyz[3]);
404 
411  void toCylindrical(double& r, double& theta, double& z) const;
412 
422  void toSpherical(double& rho, double& theta, double& phi) const;
423 
429  static AffPoint centroid(const AffPoint p[], int nPoints);
430 
442  static AffPoint fromBarycentricCoords( // in a plane
443  const AffPoint& P1, const AffPoint& P2,
444  const AffPoint& P3,
445  double b1, double b2, double b3)
446  { return b1*P1 + b2*P2 + b3*P3; }
447 
457  static AffPoint fromBarycentricCoords( // on a line
458  const AffPoint& P1, const AffPoint& P2,
459  double b1, double b2)
460  { return b1*P1 + b2*P2; }
461 
469  static AffPoint fromCylindrical(double r, double theta, double z)
470  { return AffPoint( r*cos(theta), r*sin(theta), z ); }
471 
478  static AffPoint fromSpherical(double rho, double theta, double phi)
479  { return AffPoint(rho*sin(phi)*cos(theta),
480  rho*sin(phi)*sin(theta), rho*cos(phi) ); }
481 
487  static double getCoincidenceTolerance() { return AffPoint::sCoincidenceTol; }
504  static double maxOffsetInDirection(
505  const AffPoint& ref, const AffVector& dir,
506  const AffPoint buf[], int bufSize,
507  int& index1, int& index2);
508 
516  static double ratio(const AffPoint& a, const AffPoint& b, const AffPoint& c);
522  static void setCoincidenceTolerance(double tol);
523 
524  // ---------- Global constants
525 
526  // Special Points
527  static const AffPoint origin;
528  static const AffPoint xAxisPoint;
529  static const AffPoint yAxisPoint;
530  static const AffPoint zAxisPoint;
532  // The coordinates are public, but it is usually best to use
533  // the public methods, using public access to the following only
534  // for convenient overwriting of the coordinates of a specific point.
535  double x;
536  double y;
537  double z;
539 private:
540  static double sCoincidenceTol;
541 };
542 
543 std::ostream& operator<<(std::ostream& os, const AffPoint& p);
544 std::istream& operator>>(std::istream& is, AffPoint& p);
545 
546 static AffPoint operator*(double f, const AffPoint& p)
547  { return AffPoint(f*p[X], f*p[Y], f*p[Z]); }
548 }
549 
550 #endif
AffPoint operator=(const AffPoint &rhs)
Definition: AffPoint.c++:256
static double maxOffsetInDirection(const AffPoint &ref, const AffVector &dir, const AffPoint buf[], int bufSize, int &index1, int &index2)
Definition: AffPoint.c++:216
double * pCoords(double *coords, double w, int offset=0) const
Definition: AffPoint.c++:329
double distanceSquaredFromLine(const AffPoint &B, const AffVector &u) const
Definition: AffPoint.c++:177
AffPoint operator*=(double f)
Definition: AffPoint.c++:280
double distanceTo(const AffPoint &p) const
Definition: AffPoint.c++:211
AffPoint operator+(const AffVector &v2) const
Definition: AffPoint.h:137
double distanceSquaredFromOrigin() const
Definition: AffPoint.c++:194
Definition: AffPoint.c++:12
double operator[](int index) const
Definition: AffPoint.c++:293
static const AffPoint yAxisPoint
Definition: AffPoint.h:529
static AffPoint fromBarycentricCoords(const AffPoint &P1, const AffPoint &P2, double b1, double b2)
Definition: AffPoint.h:457
double z
Definition: AffPoint.h:537
static AffPoint fromCylindrical(double r, double theta, double z)
Definition: AffPoint.h:469
static double ratio(const AffPoint &a, const AffPoint &b, const AffPoint &c)
Definition: AffPoint.c++:353
bool coincidentWith(const AffPoint &p) const
Definition: AffPoint.c++:162
static const AffPoint origin
Definition: AffPoint.h:527
double distanceFromOrigin() const
Definition: AffPoint.c++:172
double * aCoords(double *coords, int offset=0) const
Definition: AffPoint.c++:55
static AffPoint centroid(const AffPoint p[], int nPoints)
Definition: AffPoint.c++:154
AffPoint()
Definition: AffPoint.c++:27
AffPoint operator*(double f) const
Definition: AffPoint.h:115
AffPoint operator-(const AffVector &v2) const
Definition: AffPoint.h:145
virtual ~AffPoint()
Definition: AffPoint.c++:51
Definition: AffVector.h:24
void toCylindrical(double &r, double &theta, double &z) const
Definition: AffPoint.c++:392
AffPoint operator/=(double f)
Definition: AffPoint.c++:286
static AffPoint fromSpherical(double rho, double theta, double phi)
Definition: AffPoint.h:478
AffPoint operator/(double f) const
Definition: AffPoint.h:123
AffVector operator-(const AffPoint &p2) const
Definition: AffPoint.h:130
static void setCoincidenceTolerance(double tol)
Definition: AffPoint.c++:365
AffPoint operator+=(const AffVector &rhs)
Definition: AffPoint.c++:262
AffPoint operator+(const AffPoint &p2) const
Definition: AffPoint.h:108
void swizzle(char xyz[3])
Definition: AffPoint.c++:371
double distanceSquaredTo(const AffPoint &p) const
Definition: AffPoint.c++:199
AffPoint operator-=(const AffVector &rhs)
Definition: AffPoint.c++:274
double distanceFromLine(const AffPoint &B, const AffVector &u) const
Definition: AffPoint.c++:167
double normalize()
Definition: AffPoint.c++:246
double y
Definition: AffPoint.h:536
double x
Definition: AffPoint.h:535
static const AffPoint xAxisPoint
Definition: AffPoint.h:528
static const AffPoint zAxisPoint
Definition: AffPoint.h:530
void assign(double xx, double yy, double zz)
Definition: AffPoint.c++:95
static double getCoincidenceTolerance()
Definition: AffPoint.h:487
void barycentricCoords(const AffPoint &P1, const AffPoint &P2, const AffPoint &P3, double &b1, double &b2, double &b3) const
Definition: AffPoint.c++:104
static AffPoint fromBarycentricCoords(const AffPoint &P1, const AffPoint &P2, const AffPoint &P3, double b1, double b2, double b3)
Definition: AffPoint.h:442
void toSpherical(double &rho, double &theta, double &phi) const
Definition: AffPoint.c++:399
Definition: AffPoint.h:25