cryph utilities [subset]  2.0
Subset of the full cryph package of mathematical utilities for points, vectors, and matrices
AffVector.h
Go to the documentation of this file.
1 
7 #ifndef AFFVECTOR_H
8 #define AFFVECTOR_H
9 
10 #include <math.h>
11 #include <iostream>
12 
13 namespace cryph
14 {
15 class AffPoint;
16 
17 // indices for extracting components from vectors
18 
19 const int DX = 0;
20 const int DY = 1;
21 const int DZ = 2;
22 const int DW = 3;
23 
24 class AffVector
25 {
26 public:
28  AffVector();
29 
33  AffVector(const AffVector& v);
34 
38  AffVector(const AffPoint& p);
39 
45  AffVector(double Dx, double Dy, double Dz=0.0);
46 
50  AffVector(const double xyz[]);
51 
55  AffVector(const float xyz[]);
56 
58  virtual ~AffVector();
59 
64  AffVector operator=(const AffVector& rhs);
65 
70  AffVector operator+=(const AffVector& rhs);
71 
76  AffVector operator-=(const AffVector& rhs);
77 
82  AffVector operator*=(double f);
83 
88  AffVector operator/=(double f);
89 
94  double operator[](int index) const;
95 
100  AffVector operator+(const AffVector& v2) const
101  { return AffVector(dx+v2.dx , dy+v2.dy , dz+v2.dz); }
102 
107  AffVector operator-(const AffVector& v2) const
108  { return AffVector(dx-v2.dx , dy-v2.dy , dz-v2.dz); }
109 
113  AffVector operator-() const { return AffVector(-dx, -dy, -dz); }
114 
119  AffVector operator*(double f) const
120  { return AffVector(f*dx , f*dy , f*dz); }
121 
126  AffVector operator/(double f) const
127  { return AffVector(dx/f , dy/f , dz/f); }
128 
132  void arbitraryNormal(AffVector& normal) const;
133 
139  void assign(double dxx, double dyy, double dzz);
140 
145  AffVector cross(const AffVector& rhs) const;
146 
155  void decompose(const AffVector& arbitraryVector,
156  AffVector& parallel, AffVector& perpendicular) const;
157 
162  double dot(const AffVector& rhs) const
163  { return dx*rhs.dx + dy*rhs.dy + dz*rhs.dz; }
164 
166  double length() const { return sqrt(lengthSquared()); }
167 
169  double lengthSquared() const { return dx*dx + dy*dy + dz*dz; }
170 
176  double maxAbsComponent(int& componentIndex) const;
177 
183  double minAbsComponent(int& componentIndex) const;
184 
188  double normalize();
189 
196  double normalizeToCopy(AffVector& normalizedCopy) const;
197 
202  bool parallelTo(const AffVector& v) const;
203 
217  void swizzle(char xyz[3]);
218 
239  double* vComponents(double* components, int offset=0) const;
240 
262  double* vComponents(double components[][3], int offset=0) const;
263 
284  float* vComponents(float* components, int offset=0) const;
285 
307  float* vComponents(float components[][3], int offset=0) const;
308 
321  static void coordinateSystemFromUW(AffVector& U, AffVector& V,
322  AffVector& W);
323 
336  static void coordinateSystemFromVW(AffVector& U, AffVector& V,
337  AffVector& W);
338 
344  static AffVector cross(const AffVector& v1, const AffVector& v2);
345 
351  static double dot(const AffVector& v1, const AffVector& v2)
352  { return v1.dx*v2.dx + v1.dy*v2.dy + v1.dz*v2.dz; }
353 
354  static const AffVector xu;
355  static const AffVector yu;
356  static const AffVector zu;
357  static const AffVector zeroVector;
359  // The vector components are public, but it is best to use the
360  // other public methods whenever possible. Only use direct access
361  // to these variables for ease of overwriting some specific
362  // component.
363  double dx;
364  double dy;
365  double dz;
366 };
367 
368 std::ostream& operator<<(std::ostream& os, const AffVector& v);
369 std::istream& operator>>(std::istream& is, AffVector& v);
370 
371 static AffVector operator*(double f, const AffVector& v)
372  { return AffVector(f*v[DX] , f*v[DY] , f*v[DZ]); }
373 }
374 
375 #endif
double normalizeToCopy(AffVector &normalizedCopy) const
Definition: AffVector.c++:255
virtual ~AffVector()
Definition: AffVector.c++:49
double normalize()
Definition: AffVector.c++:245
void swizzle(char xyz[3])
Definition: AffVector.c++:343
Definition: AffPoint.c++:12
double operator[](int index) const
Definition: AffVector.c++:298
AffVector operator+=(const AffVector &rhs)
Definition: AffVector.c++:267
static const AffVector xu
Definition: AffVector.h:354
AffVector cross(const AffVector &rhs) const
Definition: AffVector.c++:192
AffVector operator/=(double f)
Definition: AffVector.c++:288
void decompose(const AffVector &arbitraryVector, AffVector &parallel, AffVector &perpendicular) const
Definition: AffVector.c++:205
static const AffVector zeroVector
Definition: AffVector.h:357
static void coordinateSystemFromVW(AffVector &U, AffVector &V, AffVector &W)
Definition: AffVector.c++:152
double dy
Definition: AffVector.h:364
double * vComponents(double *components, int offset=0) const
Definition: AffVector.c++:364
AffVector operator*(double f) const
Definition: AffVector.h:119
void assign(double dxx, double dyy, double dzz)
Definition: AffVector.c++:118
AffVector operator=(const AffVector &rhs)
Definition: AffVector.c++:261
double dx
Definition: AffVector.h:363
AffVector operator-=(const AffVector &rhs)
Definition: AffVector.c++:273
bool parallelTo(const AffVector &v) const
Definition: AffVector.c++:334
Definition: AffVector.h:24
double dot(const AffVector &rhs) const
Definition: AffVector.h:162
static double dot(const AffVector &v1, const AffVector &v2)
Definition: AffVector.h:351
static void coordinateSystemFromUW(AffVector &U, AffVector &V, AffVector &W)
Definition: AffVector.c++:125
static const AffVector yu
Definition: AffVector.h:355
double dz
Definition: AffVector.h:365
AffVector operator-(const AffVector &v2) const
Definition: AffVector.h:107
AffVector operator-() const
Definition: AffVector.h:113
AffVector operator+(const AffVector &v2) const
Definition: AffVector.h:100
void arbitraryNormal(AffVector &normal) const
Definition: AffVector.c++:53
AffVector operator/(double f) const
Definition: AffVector.h:126
double length() const
Definition: AffVector.h:166
double lengthSquared() const
Definition: AffVector.h:169
static const AffVector zu
Definition: AffVector.h:356
AffVector()
Definition: AffVector.c++:25
double minAbsComponent(int &componentIndex) const
Definition: AffVector.c++:230
double maxAbsComponent(int &componentIndex) const
Definition: AffVector.c++:215
Definition: AffPoint.h:25
AffVector operator*=(double f)
Definition: AffVector.c++:279