cryph utilities [subset]
2.0
Subset of the full cryph package of mathematical utilities for points, vectors, and matrices
|
Public Member Functions | |
AffPoint () | |
AffPoint (const AffPoint &P) | |
AffPoint (const AffVector &v) | |
AffPoint (double xx, double yy, double zz=0.0) | |
AffPoint (const double P[]) | |
AffPoint (const float P[]) | |
virtual | ~AffPoint () |
AffPoint | operator= (const AffPoint &rhs) |
AffPoint | operator+= (const AffVector &rhs) |
AffPoint | operator+= (const AffPoint &rhs) |
AffPoint | operator-= (const AffVector &rhs) |
AffPoint | operator*= (double f) |
AffPoint | operator/= (double f) |
double | operator[] (int index) const |
AffPoint | operator+ (const AffPoint &p2) const |
AffPoint | operator* (double f) const |
AffPoint | operator/ (double f) const |
AffVector | operator- (const AffPoint &p2) const |
AffPoint | operator+ (const AffVector &v2) const |
AffPoint | operator- (const AffVector &v2) const |
double * | aCoords (double *coords, int offset=0) const |
double * | aCoords (double coords[][3], int offset=0) const |
float * | aCoords (float *coords, int offset=0) const |
float * | aCoords (float coords[][3], int offset=0) const |
void | assign (double xx, double yy, double zz) |
void | barycentricCoords (const AffPoint &P1, const AffPoint &P2, const AffPoint &P3, double &b1, double &b2, double &b3) const |
void | barycentricCoords (const AffPoint &P1, const AffPoint &P2, double &b1, double &b2) const |
bool | coincidentWith (const AffPoint &p) const |
double | distanceFromLine (const AffPoint &B, const AffVector &u) const |
double | distanceFromOrigin () const |
double | distanceSquaredFromLine (const AffPoint &B, const AffVector &u) const |
double | distanceSquaredFromOrigin () const |
double | distanceSquaredTo (const AffPoint &p) const |
double | distanceTo (const AffPoint &p) const |
double | normalize () |
double * | pCoords (double *coords, double w, int offset=0) const |
float * | pCoords (float *coords, float w, int offset=0) const |
void | swizzle (char xyz[3]) |
void | toCylindrical (double &r, double &theta, double &z) const |
void | toSpherical (double &rho, double &theta, double &phi) const |
Static Public Member Functions | |
static AffPoint | centroid (const AffPoint p[], int nPoints) |
static AffPoint | fromBarycentricCoords (const AffPoint &P1, const AffPoint &P2, const AffPoint &P3, double b1, double b2, double b3) |
static AffPoint | fromBarycentricCoords (const AffPoint &P1, const AffPoint &P2, double b1, double b2) |
static AffPoint | fromCylindrical (double r, double theta, double z) |
static AffPoint | fromSpherical (double rho, double theta, double phi) |
static double | getCoincidenceTolerance () |
static double | maxOffsetInDirection (const AffPoint &ref, const AffVector &dir, const AffPoint buf[], int bufSize, int &index1, int &index2) |
static double | ratio (const AffPoint &a, const AffPoint &b, const AffPoint &c) |
static void | setCoincidenceTolerance (double tol) |
Public Attributes | |
double | x |
double | y |
double | z |
Static Public Attributes | |
static const AffPoint | origin = AffPoint(0.0 , 0.0 , 0.0) |
static const AffPoint | xAxisPoint = AffPoint(1.0 , 0.0 , 0.0) |
static const AffPoint | yAxisPoint = AffPoint(0.0 , 1.0 , 0.0) |
static const AffPoint | zAxisPoint = AffPoint(0.0 , 0.0 , 1.0) |
cryph::AffPoint::AffPoint | ( | ) |
Default constructor creates a point at the origin.
cryph::AffPoint::AffPoint | ( | const AffPoint & | P | ) |
The copy constructor.
P | [INPUT ONLY] the point whose coordinates are to initialize "this" |
cryph::AffPoint::AffPoint | ( | const AffVector & | v | ) |
Construct a point from a vector (i.e., "this" point = origin + v)
v | [INPUT ONLY] a vector |
cryph::AffPoint::AffPoint | ( | double | xx, |
double | yy, | ||
double | zz = 0.0 |
||
) |
Creates a point at the specified location.
xx | [INPUT ONLY] the x coordinate |
yy | [INPUT ONLY] the y coordinate |
zz | [INPUT ONLY] the z coordinate (defaults to 0.0) |
cryph::AffPoint::AffPoint | ( | const double | P[] | ) |
Construct from a double array
P | [INPUT ONLY] an array assumed to be of length 3 holding (x, y, z) |
cryph::AffPoint::AffPoint | ( | const float | P[] | ) |
Construct from a float array
P | [INPUT ONLY] an array assumed to be of length 3 holding (x, y, z) |
|
virtual |
The destructor
double * cryph::AffPoint::aCoords | ( | double * | coords, |
int | offset = 0 |
||
) | const |
Extract the coordinates of "this" point into an array of double, starting at the given offset. Among other things, this method is useful for interfacing with OpenGL, especially routines like glBufferData. For example, a caller can allocate an array of an appropriate size, then loop over an array of AffPoint instances, invoking the aCoords method as follows:
double* buf = new double[3*NUM_POINTS]; for (int i=0 ; i<NUM_POINTS ; i++) affPointArray[i].aCoords(buf, 3*i); glBufferData(GL_ARRAY_BUFFER, 3*NUM_POINTS*sizeof(double), buf, GL_STATIC_DRAW); delete [] buf;
coords | [OUTPUT ONLY] the array into which the (x, y, z) coordinates of "this" point are to be copied. Must be at least (offset+3) positions long. |
offset | [INPUT ONLY] the starting location in coords where the coordinates are to be placed (defaults to 0) |
double * cryph::AffPoint::aCoords | ( | double | coords[][3], |
int | offset = 0 |
||
) | const |
Extract the coordinates of "this" point into an array of "dvec3" (a built-in GLSL data type essentially equivalent to "typedef double dvec[3];"), starting at the given offset. Among other things, this method is useful for interfacing with OpenGL, especially routines like glBufferData. For example, a caller can allocate an array of an appropriate size, then loop over an array of AffPoint instances, invoking the aCoords method as follows:
dvec3* buf = new dvec3[NUM_POINTS]; // assuming the "typedef" above for (int i=0 ; i<NUM_POINTS ; i++) affPointArray[i].aCoords(buf, i); glBufferData(GL_ARRAY_BUFFER, NUM_POINTS*sizeof(dvec3), buf, GL_STATIC_DRAW); delete [] buf;
coords | [OUTPUT ONLY] the array into which the (x, y, z) coordinates of "this" point are to be copied. Must be at least (offset+1) positions long. |
offset | [INPUT ONLY] the starting location in coords where the coordinates are to be placed (defaults to 0) |
float * cryph::AffPoint::aCoords | ( | float * | coords, |
int | offset = 0 |
||
) | const |
Extract the coordinates of "this" point into an array of float, starting at the given offset. Among other things, this method is useful for interfacing with OpenGL, especially routines like glBufferData. For example, a caller can allocate an array of an appropriate size, then loop over an array of AffPoint instances, invoking the aCoords method as follows:
float* buf = new float[3*NUM_POINTS]; for (int i=0 ; i<NUM_POINTS ; i++) affPointArray[i].aCoords(buf, 3*i); glBufferData(GL_ARRAY_BUFFER, 3*NUM_POINTS*sizeof(float), buf, GL_STATIC_DRAW); delete [] buf;
coords | [OUTPUT ONLY] the array into which the (x, y, z) coordinates of "this" point are to be copied. Must be at least (offset+3) positions long. |
offset | [INPUT ONLY] the starting location in coords where the coordinates are to be placed (defaults to 0) |
float * cryph::AffPoint::aCoords | ( | float | coords[][3], |
int | offset = 0 |
||
) | const |
Extract the coordinates of "this" point into an array of "vec3" (a built-in GLSL data type essentially equivalent to "typedef float vec[3];"), starting at the given offset. Among other things, this method is useful for interfacing with OpenGL, especially routines like glBufferData. For example, a caller can allocate an array of an appropriate size, then loop over an array of AffPoint instances, invoking the aCoords method as follows:
vec3* buf = new vec3[NUM_POINTS]; // assuming the "typedef" above for (int i=0 ; i<NUM_POINTS ; i++) affPointArray[i].aCoords(buf, i); glBufferData(GL_ARRAY_BUFFER, NUM_POINTS*sizeof(vec3), buf, GL_STATIC_DRAW); delete [] buf;
coords | [OUTPUT ONLY] the array into which the (x, y, z) coordinates of "this" point are to be copied. Must be at least (offset+1) positions long. |
offset | [INPUT ONLY] the starting location in coords where the coordinates are to be placed (defaults to 0) |
void cryph::AffPoint::assign | ( | double | xx, |
double | yy, | ||
double | zz | ||
) |
Reset the (x, y, z) coordinates of "this" point
xx | [INPUT ONLY] the new x coordinate |
yy | [INPUT ONLY] the new y coordinate |
zz | [INPUT ONLY] the new z coordinate |
void cryph::AffPoint::barycentricCoords | ( | const AffPoint & | P1, |
const AffPoint & | P2, | ||
const AffPoint & | P3, | ||
double & | b1, | ||
double & | b2, | ||
double & | b3 | ||
) | const |
Compute the Barycentric coordinates (b1, b2, b3) of "this" point with respect to the three given reference points, P1, P2, and P3. We assume "this" point lies in the plane determined by the points P1, P2, and P3. On return, b1, b2, and b3 will have been computed such that: (i) b1 + b2 + b3 = 1, (ii) "this" point = b1*P1 + b2*P2 + b3*P3, and (iii) none of "this" point, P1, P2, or P3 will have been changed. Furthermore, if "this" point lies in the triangle P1-P2-P3, then b1>=0, b2>=0, and b3>=0.
P1 | [INPUT ONLY] the first reference point |
P2 | [INPUT ONLY] the second reference point |
P3 | [INPUT ONLY] the third reference point |
b1 | [OUTPUT ONLY] b1 the returned Barycentric coordinate (associated with P1) |
b2 | [OUTPUT ONLY] b2 the returned Barycentric coordinate (associated with P2) |
b3 | [OUTPUT ONLY] b3 the returned Barycentric coordinate (associated with P3) |
void cryph::AffPoint::barycentricCoords | ( | const AffPoint & | P1, |
const AffPoint & | P2, | ||
double & | b1, | ||
double & | b2 | ||
) | const |
Compute the Barycentric coordinates (b1, b2) of "this" point with respect to the two given reference points, P1 and P2. We assume "this" point lies on the line determined by the points P1 and P2. On return, b1 and b2 will have been computed such that: (i) b1 + b2 = 1, (ii) "this" point = b1*P1 + b2*P2, and (iii) none of "this" point, P1, or P2 will have been changed. Furthermore, if ("this" point lies between P1 and P2 on the line, then b1>=0 and b2>=0.
P1 | [INPUT ONLY] the first reference point |
P2 | [INPUT ONLY] the second reference point |
b1 | [OUTPUT ONLY] the returned Barycentric coordinate (associated with P1) |
b2 | [OUTPUT ONLY] the returned Barycentric coordinate (associated with P2) |
bool cryph::AffPoint::coincidentWith | ( | const AffPoint & | p | ) | const |
Determine whether "this" point is coincident with P within the current coincidence tolerance
P | [INPUT ONLY] the point to be compared with "this" point |
Compute and return the distance from "this" point to the given line
B | [INPUT ONLY] a point on the line |
u | [INPUT ONLY] a vector along the line |
double cryph::AffPoint::distanceFromOrigin | ( | ) | const |
Compute the distance from "this" point to the origin
Compute and return the distance squared from "this" point to the given line
B | [INPUT ONLY] a point on the line |
u | [INPUT ONLY] a vector along the line |
double cryph::AffPoint::distanceSquaredFromOrigin | ( | ) | const |
Compute the square of the distance from "this" point to the origin
double cryph::AffPoint::distanceSquaredTo | ( | const AffPoint & | p | ) | const |
Compute the square of the distance from "this" point to the given point
P | [INPUT ONLY] the point whose distance squared from "this" point we seek |
double cryph::AffPoint::distanceTo | ( | const AffPoint & | p | ) | const |
Compute the distance from "this" point to the given point
P | [INPUT ONLY] the point whose distance from "this" point we seek |
|
inlinestatic |
Compute and return the point whose barycentric coordinates are (b1, b2, b3) with respect to the reference points P1, P2, and P3
P1 | [INPUT ONLY] the first input reference point |
P2 | [INPUT ONLY] the second input reference point |
P3 | [INPUT ONLY] the third input reference point |
b1 | [INPUT ONLY] the Barycentric coordinate for P1 |
b2 | [INPUT ONLY] the Barycentric coordinate for P2 |
b3 | [INPUT ONLY] the Barycentric coordinate for P3 |
|
inlinestatic |
Compute and return the point whose barycentric coordinates are (b1, b2) with respect to the reference points P1 and P2
P1 | [INPUT ONLY] the first input reference point |
P2 | [INPUT ONLY] the second input reference point |
b1 | [INPUT ONLY] the Barycentric coordinate for P1 |
b2 | [INPUT ONLY] the Barycentric coordinate for P2 |
|
inlinestatic |
Compute and return the point with the given cylindrical coordinates
r | [INPUT ONLY] the radial cylindrical coordinate |
theta | [INPUT ONLY] the theta cylindrical coordinate |
z | [INPUT ONLY] the z coordinate |
|
inlinestatic |
Compute and return the point with the given spherical coordinates
rho | [INPUT ONLY] the distance from the origin to the desired point |
theta | [INPUT ONLY] the desired theta |
phi | [INPUT ONLY] the desired phi |
|
inlinestatic |
Get the current point coincidence tolerance.
|
static |
Find the point in the given buffer of points that is farthest away away in the given direction. If that point is 'P', the function return value is "(P-ref).dir". If there is exactly one such farthest point, then the indices index1 and index2 will both contain the index of 'P' in 'buf'. If several points tie, then index1 and index2 are the indices of the first succession of adjacent points all at that offset. If there are multiple sets of adjacent tieing points, only the indices of the first are returned.
ref | [INPUT ONLY] a reference point used to compute distances |
dir | [INPUT ONLY] a vector which, along with 'ref', define a plane away from which distances are measured. |
buf | [INPUT ONLY] the array of points to be analyzed |
bufSize | [INPUT ONLY] the number of points in 'buf' |
index1 | [OUTPUT ONLY] as described above |
index2 | [OUTPUT ONLY] as described above |
double cryph::AffPoint::normalize | ( | ) |
Move "this" point along the line through the origin until it lies on the unit sphere centered at the origin.
|
inline |
AffPoint cryph::AffPoint::operator*= | ( | double | f | ) |
Scales the coordinates of "this" point by f
f | [INPUT ONLY] the scale factor |
Adds "this" point to p2 and returns the result as an AffPoint
p2 | [INPUT ONLY] the point to add |
|
inline |
AffPoint cryph::AffPoint::operator/= | ( | double | f | ) |
Divides the coordinates of "this" point by f (i.e., scales by 1/f)
f | [INPUT ONLY] the divisor |
Assigns the coordinates of rhs to "this" point
rhs | [INPUT ONLY] a const reference to an AffPoint |
double cryph::AffPoint::operator[] | ( | int | index | ) | const |
Returns x (if index = 0); y (if index is 1); z (if index is 2) The returned value cannot be used as an l-value.
index | [INPUT ONLY] the desired coordinate |
double * cryph::AffPoint::pCoords | ( | double * | coords, |
double | w, | ||
int | offset = 0 |
||
) | const |
Extract the coordinates of "this" point into an array of double, starting at the given offset. While doing so, embed each point in projective space using the given w coordinate. Among other things, this method is useful for interfacing with OpenGL, especially routines like glBufferData. For example, a caller can allocate an array of an appropriate size, then loop over an array of AffPoint instances, invoking the pCoords method as follows:
double* buf = new double[4*NUM_POINTS]; for (int i=0 ; i<NUM_POINTS ; i++) affPointArray[i].pCoords(buf, 4*i); glBufferData(GL_ARRAY_BUFFER, 4*NUM_POINTS*sizeof(double), buf, GL_STATIC_DRAW); delete [] buf;
coords | [OUTPUT ONLY] the array into which the (x, y, z, w) projective space coordinates of "this" point are to be copied. Must be at least (offset+4) positions long. |
offset | [INPUT ONLY] the starting location in coords where the coordinates are to be placed (defaults to 0) |
float * cryph::AffPoint::pCoords | ( | float * | coords, |
float | w, | ||
int | offset = 0 |
||
) | const |
Extract the coordinates of "this" point into an array of float, starting at the given offset. While doing so, embed each point in projective space using the given w coordinate. Among other things, this method is useful for interfacing with OpenGL, especially routines like glBufferData. For example, a caller can allocate an array of an appropriate size, then loop over an array of AffPoint instances, invoking the pCoords method as follows:
float* buf = new float[4*NUM_POINTS]; for (int i=0 ; i<NUM_POINTS ; i++) affPointArray[i].pCoords(buf, 4*i); glBufferData(GL_ARRAY_BUFFER, 4*NUM_POINTS*sizeof(float), buf, GL_STATIC_DRAW); delete [] buf;
coords | [OUTPUT ONLY] the array into which the (x, y, z, w) projective space coordinates of "this" point are to be copied. Must be at least (offset+4) positions long. |
offset | [INPUT ONLY] the starting location in coords where the coordinates are to be placed (defaults to 0) |
Compute the unit vector uHat from (c-a). Then compute and return ratio(a,b,c) as defined by Farin.
a | [INPUT ONLY] first point |
b | [INPUT ONLY] middle point |
c | [INPUT ONLY] last point |
|
static |
Set the current point coincidence tolerance.
tol | [INPUT ONLY] the desired point coincidence tolerance |
void cryph::AffPoint::swizzle | ( | char | xyz[3] | ) |
A method inspired by OpenGL's GLSL's swizzle operation. If the i-th character of xyz is 'X', then the x coordinate of "this" point is placed into the i-th coordinate of "this" point. If instead it is 'x', then negative of the x coordinate of "this" point is placed into the i-th coordinate of "this" point. Characters 'y', 'Y', 'z', 'Z' behave similarly. Any other character is simply ignored. Some examples:
cryph::AffPoint ap(1.0, 2.0, 3.0); ap.swizzle("Zxy"); // ap is now (3.0, -1.0, -2.0) ap.swizzle("dzy"); // ap is now (3.0, 2.0, 1.0) ap.swizzle("xxY"); // ap is now (3.0, 3.0, 2.0)
xyz | [INPUT ONLY] an array of char of length 3 interpreted as explained and illustrated above |
void cryph::AffPoint::toCylindrical | ( | double & | r, |
double & | theta, | ||
double & | z | ||
) | const |
Compute and return the cylindrical coordinates of "this" point
r | [OUTPUT ONLY] the output computed r coordinate |
theta | [OUTPUT ONLY] the output computed theta coordinate |
z | [OUTPUT ONLY] the output computed z coordinate (same is this->z). |
void cryph::AffPoint::toSpherical | ( | double & | rho, |
double & | theta, | ||
double & | phi | ||
) | const |
Compute and return the spherical coordinates of "this" point.
rho | [OUTPUT ONLY] the output computed distance from the origin to "this" point |
theta | [OUTPUT ONLY] the output computed angle in the xy-plane from the positive x-axis to the projection of the vector ("this" - origin) onto the xy-plane. Value will be: -PI <= theta <= PI. |
phi | [OUTPUT ONLY] the output computed angle from the positive z-axis to the vector ("this" - origin). Value will be: 0 <= phi <= PI. |
double cryph::AffPoint::x |
x coordinate
double cryph::AffPoint::y |
y coordinate
double cryph::AffPoint::z |
z coordinate