|
cgma
|
#include <CubitVector.hpp>
Public Member Functions | |
| CubitVector () | |
| CubitVector (const double x, const double y, const double z) | |
| CubitVector (const double xyz[3]) | |
| CubitVector (const CubitVector &tail, const CubitVector &head) | |
| CubitVector (const CubitVector ©_from) | |
| CubitVector (const CubitVectorStruct &from) | |
| void | set (const double x, const double y, const double z) |
| void | set (const double xyz[3]) |
| void | set (const CubitVector &tail, const CubitVector &head) |
| void | set (const CubitVector &to_copy) |
| double | x () const |
| double | y () const |
| double | z () const |
| double & | x () |
| double & | y () |
| double & | z () |
| void | get_xyz (double &x, double &y, double &z) const |
| void | get_xyz (double xyz[3]) const |
| double & | r () |
| double & | theta () |
| void | x (const double x) |
| void | y (const double y) |
| void | z (const double z) |
| void | r (const double x) |
| void | theta (const double y) |
| void | xy_to_rtheta () |
| void | rtheta_to_xy () |
| void | scale_angle (double gamma, double) |
| void | blow_out (double gamma, double gamma2=0.0) |
| void | rotate (double angle, double) |
| void | project_to_plane (const CubitVector &planenormal) |
| void | project_to_line_segment (const CubitVector &pt0, const CubitVector &pt1) |
| void | reflect_about_xaxis (double dummy, double) |
| double | normalize () |
| CubitVector & | length (const double new_length) |
| double | length () const |
| double | distance_between (const CubitVector &test_vector) const |
| double | distance_between_squared (const CubitVector &test_vector) const |
| double | distance_from_infinite_line (const CubitVector &point_on_line, const CubitVector &line_direction) const |
| double | distance_from_infinite_line_squared (const CubitVector &point_on_line, const CubitVector &line_direction) const |
| double | length_squared () const |
| double | interior_angle (const CubitVector &otherVector) const |
| double | vector_angle_quick (const CubitVector &vec1, const CubitVector &vec2) |
| double | vector_angle (const CubitVector &vector1, const CubitVector &vector2) const |
| void | perpendicular_z () |
| void | print_me () |
| void | orthogonal_vectors (CubitVector &vector2, CubitVector &vector3) const |
| void | next_point (const CubitVector &direction, double distance, CubitVector &out_point) const |
| CubitBoolean | about_equal (const CubitVector &w, const double relative_tolerance=1.0e-6, const double absolute_tolerance=1.0e-6) const |
| CubitBoolean | within_tolerance (const CubitVector &vectorPtr2, double tolerance) const |
| CubitBoolean | within_scaled_tolerance (const CubitVector &v2, double tol) const |
| CubitVector & | operator+= (const CubitVector &vec) |
| CubitVector & | operator-= (const CubitVector &vec) |
| CubitVector & | operator*= (const CubitVector &vec) |
| CubitVector & | operator*= (const double scalar) |
| CubitVector & | operator/= (const double scalar) |
| CubitVector | operator- () const |
| double | operator[] (int i) const |
| CubitVector & | operator= (const CubitVectorStruct &from) |
| operator CubitVectorStruct () | |
| CubitVector & | operator= (const CubitVector &from) |
Static Public Member Functions | |
| static bool | colinear (const CubitVector &p0, const CubitVector &p1, const CubitVector &p2) |
| static CubitVector | normal (const CubitVector &p0, const CubitVector &p1, const CubitVector &p2) |
| static bool | barycentric_coordinates (const CubitVector &v1, const CubitVector &v2, const CubitVector &v3, const CubitVector &point, double &coord_A, double &coord_B, double &coord_C) |
Static Private Member Functions | |
| static bool | attempt_barycentric_coordinates_adjustment (const CubitVector &v1, const CubitVector &v2, const CubitVector &v3, const CubitVector &point, double &coord_A, double &coord_B, double &coord_C) |
| static bool | private_barycentric_coordinates (bool adjust_on_fail, const CubitVector &v1, const CubitVector &v2, const CubitVector &v3, const CubitVector &point, double &coord_A, double &coord_B, double &coord_C) |
Private Attributes | |
| double | xVal |
| double | yVal |
| double | zVal |
Friends | |
| CubitVector | operator~ (const CubitVector &vec) |
| CubitVector | operator+ (const CubitVector &v1, const CubitVector &v2) |
| CubitVector | operator- (const CubitVector &v1, const CubitVector &v2) |
| CubitVector | operator* (const CubitVector &v1, const CubitVector &v2) |
| CubitVector | operator* (const CubitVector &v1, const double sclr) |
| CubitVector | operator* (const double sclr, const CubitVector &v1) |
| double | operator% (const CubitVector &v1, const CubitVector &v2) |
| CubitVector | operator/ (const CubitVector &v1, const double sclr) |
| int | operator== (const CubitVector &v1, const CubitVector &v2) |
| int | operator!= (const CubitVector &v1, const CubitVector &v2) |
| CubitVector | interpolate (const double param, const CubitVector &v1, const CubitVector &v2) |
Definition at line 25 of file CubitVector.hpp.
| CubitVector::CubitVector | ( | ) | [inline] |
Definition at line 406 of file CubitVector.hpp.
| CubitVector::CubitVector | ( | const double | x, |
| const double | y, | ||
| const double | z | ||
| ) | [inline, explicit] |
Definition at line 417 of file CubitVector.hpp.
| CubitVector::CubitVector | ( | const double | xyz[3] | ) | [inline, explicit] |
Definition at line 423 of file CubitVector.hpp.
| CubitVector::CubitVector | ( | const CubitVector & | tail, |
| const CubitVector & | head | ||
| ) | [inline, explicit] |
| CubitVector::CubitVector | ( | const CubitVector & | copy_from | ) | [inline] |
| CubitVector::CubitVector | ( | const CubitVectorStruct & | from | ) | [inline, explicit] |
| CubitBoolean CubitVector::about_equal | ( | const CubitVector & | w, |
| const double | relative_tolerance = 1.0e-6, |
||
| const double | absolute_tolerance = 1.0e-6 |
||
| ) | const |
Definition at line 414 of file CubitVector.cpp.
{
if ( absolute_tolerance == 0. &&
relative_tolerance == 0. )
{
if ( xVal == w.xVal &&
yVal == w.yVal &&
zVal == w.zVal )
return CUBIT_TRUE;
}
else
{
const CubitVector diff = *this - w;
const double diff_size = diff.length_squared();
const double a_tol_size = absolute_tolerance * absolute_tolerance;
// catches v == w
if ( diff_size <= a_tol_size )
return CUBIT_TRUE;
if ( relative_tolerance > 0. )
{
const CubitVector sum = *this + w;
const double sum_size = sum.length_squared();
const double r_tol_size = relative_tolerance * relative_tolerance;
if ( 4. * diff_size <= sum_size * r_tol_size )
// Q: why this formula?
// A: because if v = 1,0,eps, w = 1,0,0, then
// diff_size = eps^2
// sum_size = about 4.
// and function returns true if eps^2 <= tolerance^2
return CUBIT_TRUE;
}
}
return CUBIT_FALSE;
}
| bool CubitVector::attempt_barycentric_coordinates_adjustment | ( | const CubitVector & | v1, |
| const CubitVector & | v2, | ||
| const CubitVector & | v3, | ||
| const CubitVector & | point, | ||
| double & | coord_A, | ||
| double & | coord_B, | ||
| double & | coord_C | ||
| ) | [static, private] |
Definition at line 685 of file CubitVector.cpp.
{
#if 0
CubitVector v1_adjusted = v1-point;
CubitVector v2_adjusted = v2-point;
CubitVector v3_adjusted = v3-point;
CubitVector origin(0,0,0);
return private_barycentric_coordinates(false,
v1_adjusted, v2_adjusted, v3_adjusted, origin,
coord_A, coord_B, coord_C);
#else
CubitBox bbox(v1);
bbox |= v2;
bbox |= v3;
double dist2 = bbox.diagonal().length();
CubitVector v1_adjusted = v1 / dist2;
CubitVector v2_adjusted = v2 / dist2;
CubitVector v3_adjusted = v3 / dist2;
CubitVector point_adjusted = point / dist2;
return private_barycentric_coordinates(false,
v1_adjusted, v2_adjusted, v3_adjusted, point_adjusted,
coord_A, coord_B, coord_C);
#endif
}
| bool CubitVector::barycentric_coordinates | ( | const CubitVector & | v1, |
| const CubitVector & | v2, | ||
| const CubitVector & | v3, | ||
| const CubitVector & | point, | ||
| double & | coord_A, | ||
| double & | coord_B, | ||
| double & | coord_C | ||
| ) | [static] |
Definition at line 557 of file CubitVector.cpp.
{
return private_barycentric_coordinates(true, v1, v2, v3, point, coord_A, coord_B, coord_C );
}
| void CubitVector::blow_out | ( | double | gamma, |
| double | gamma2 = 0.0 |
||
| ) |
Definition at line 154 of file CubitVector.cpp.
{
// if gamma == 1, then
// map on a circle : r'^2 = sqrt( 1 - (1-r)^2 )
// if gamma ==0, then map back to itself
// in between, linearly interpolate
xy_to_rtheta();
// r() = sqrt( (2. - r()) * r() ) * gamma + r() * (1-gamma);
if(gamma <= 0.0)
{
throw std::invalid_argument( "Gamma must be greater than zero" );
}
// the following limits should really be roundoff-based
if (r() > rmin*1.001 && r() < 1.001) {
r() = rmin + pow(r(), gamma) * (1.0 - rmin);
}
rtheta_to_xy();
}
| bool CubitVector::colinear | ( | const CubitVector & | p0, |
| const CubitVector & | p1, | ||
| const CubitVector & | p2 | ||
| ) | [static] |
Definition at line 719 of file CubitVector.cpp.
{
CubitVector v1 = p1 - p0;
CubitVector v2 = p2 - p0;
v1.normalize();
v2.normalize();
// If the 3 points are collinear, then the cross product of these two
// vectors will yield a null vector (one whose length is zero).
CubitVector norm = v1 * v2;
if(norm.length() <= CUBIT_RESABS)
{
return true;
}
return false;
}
| double CubitVector::distance_between | ( | const CubitVector & | test_vector | ) | const |
| double CubitVector::distance_between_squared | ( | const CubitVector & | test_vector | ) | const |
| double CubitVector::distance_from_infinite_line | ( | const CubitVector & | point_on_line, |
| const CubitVector & | line_direction | ||
| ) | const |
Definition at line 55 of file CubitVector.cpp.
{
return sqrt(distance_from_infinite_line_squared(point_on_line, line_direction));
}
| double CubitVector::distance_from_infinite_line_squared | ( | const CubitVector & | point_on_line, |
| const CubitVector & | line_direction | ||
| ) | const |
Definition at line 61 of file CubitVector.cpp.
{
if (line_direction == CubitVector(0, 0, 0))
return distance_between_squared(point_on_line);
CubitVector v = *this - point_on_line;
double v_dot_d = v % line_direction;
return fabs(v.length_squared() - v_dot_d * v_dot_d / line_direction.length_squared());
}
| void CubitVector::get_xyz | ( | double & | x, |
| double & | y, | ||
| double & | z | ||
| ) | const [inline] |
Definition at line 354 of file CubitVector.hpp.
| void CubitVector::get_xyz | ( | double | xyz[3] | ) | const [inline] |
Definition at line 348 of file CubitVector.hpp.
| double CubitVector::interior_angle | ( | const CubitVector & | otherVector | ) | const |
Definition at line 88 of file CubitVector.cpp.
{
double cosAngle = 0.0, angleRad = 0.0, len1, len2 = 0.0;
if (((len1 = this->length()) > 0) && ((len2 = otherVector.length()) > 0))
cosAngle = (*this % otherVector)/(len1 * len2);
else
{
if(len1<=0||len2<=0)
throw std::invalid_argument ("Length of 'this' or parameter must be > 0");
// assert(len1 > 0);
// assert(len2 > 0);
}
if ((cosAngle > 1.0) && (cosAngle < 1.0001))
{
cosAngle = 1.0;
angleRad = acos(cosAngle);
}
else if (cosAngle < -1.0 && cosAngle > -1.0001)
{
cosAngle = -1.0;
angleRad = acos(cosAngle);
}
else if (cosAngle >= -1.0 && cosAngle <= 1.0)
angleRad = acos(cosAngle);
else
{
if(cosAngle > -1.0001 && cosAngle < 1.0001)
throw std::invalid_argument ("cosAngle must be between -1.0001 and 1.0001");
// assert(cosAngle < 1.0001 && cosAngle > -1.0001);
}
return( (angleRad * 180.) / PI );
}
| CubitVector & CubitVector::length | ( | const double | new_length | ) |
| double CubitVector::length | ( | ) | const [inline] |
| double CubitVector::length_squared | ( | ) | const [inline] |
| void CubitVector::next_point | ( | const CubitVector & | direction, |
| double | distance, | ||
| CubitVector & | out_point | ||
| ) | const |
Definition at line 522 of file CubitVector.cpp.
| CubitVector CubitVector::normal | ( | const CubitVector & | p0, |
| const CubitVector & | p1, | ||
| const CubitVector & | p2 | ||
| ) | [inline, static] |
Definition at line 642 of file CubitVector.hpp.
{
CubitVector edge0( p0, p1 );
CubitVector edge1( p0, p2 );
return edge0 * edge1; // not normalized.
}
| double CubitVector::normalize | ( | ) | [inline] |
| CubitVector::operator CubitVectorStruct | ( | ) | [inline] |
Definition at line 292 of file CubitVector.hpp.
{
CubitVectorStruct to = {xVal, yVal, zVal};
return to;
}
| CubitVector & CubitVector::operator*= | ( | const CubitVector & | vec | ) | [inline] |
| CubitVector & CubitVector::operator*= | ( | const double | scalar | ) | [inline] |
Definition at line 475 of file CubitVector.hpp.
| CubitVector & CubitVector::operator+= | ( | const CubitVector & | vec | ) | [inline] |
Definition at line 374 of file CubitVector.hpp.
| CubitVector CubitVector::operator- | ( | ) | const [inline] |
Definition at line 526 of file CubitVector.hpp.
{
return CubitVector(-xVal, -yVal, -zVal);
}
| CubitVector & CubitVector::operator-= | ( | const CubitVector & | vec | ) | [inline] |
Definition at line 382 of file CubitVector.hpp.
| CubitVector & CubitVector::operator/= | ( | const double | scalar | ) | [inline] |
Definition at line 484 of file CubitVector.hpp.
| CubitVector & CubitVector::operator= | ( | const CubitVectorStruct & | from | ) | [inline] |
| CubitVector & CubitVector::operator= | ( | const CubitVector & | from | ) | [inline] |
| double CubitVector::operator[] | ( | int | i | ) | const [inline] |
Definition at line 531 of file CubitVector.hpp.
| void CubitVector::orthogonal_vectors | ( | CubitVector & | vector2, |
| CubitVector & | vector3 | ||
| ) | const |
Definition at line 452 of file CubitVector.cpp.
{
double x[3];
unsigned short i = 0;
unsigned short imin = 0;
double rmin = 1.0E20;
unsigned short iperm1[3];
unsigned short iperm2[3];
unsigned short cont_flag = 1;
double vec1[3], vec2[3];
double rmag;
// Copy the input vector and normalize it
CubitVector vector1 = *this;
vector1.normalize();
// Initialize perm flags
iperm1[0] = 1; iperm1[1] = 2; iperm1[2] = 0;
iperm2[0] = 2; iperm2[1] = 0; iperm2[2] = 1;
// Get into the array format we can work with
vector1.get_xyz( vec1 );
while (i<3 && cont_flag )
{
if (fabs(vec1[i]) < 1e-6)
{
vec2[i] = 1.0;
vec2[iperm1[i]] = 0.0;
vec2[iperm2[i]] = 0.0;
cont_flag = 0;
}
if (fabs(vec1[i]) < rmin)
{
imin = i;
rmin = fabs(vec1[i]);
}
++i;
}
if (cont_flag)
{
x[imin] = 1.0;
x[iperm1[imin]] = 0.0;
x[iperm2[imin]] = 0.0;
// Determine cross product
vec2[0] = vec1[1] * x[2] - vec1[2] * x[1];
vec2[1] = vec1[2] * x[0] - vec1[0] * x[2];
vec2[2] = vec1[0] * x[1] - vec1[1] * x[0];
// Unitize
rmag = sqrt(vec2[0]*vec2[0] + vec2[1]*vec2[1] + vec2[2]*vec2[2]);
vec2[0] /= rmag;
vec2[1] /= rmag;
vec2[2] /= rmag;
}
// Copy 1st orthogonal vector into CubitVector vector2
vector2.set( vec2 );
// Cross vectors to determine last orthogonal vector
vector3 = vector1 * vector2;
return;
}
| void CubitVector::perpendicular_z | ( | ) | [inline] |
| void CubitVector::print_me | ( | ) |
Definition at line 79 of file CubitVector.cpp.
| bool CubitVector::private_barycentric_coordinates | ( | bool | adjust_on_fail, |
| const CubitVector & | v1, | ||
| const CubitVector & | v2, | ||
| const CubitVector & | v3, | ||
| const CubitVector & | point, | ||
| double & | coord_A, | ||
| double & | coord_B, | ||
| double & | coord_C | ||
| ) | [static, private] |
Definition at line 577 of file CubitVector.cpp.
{
#define DETERM3(p1,q1,p2,q2,p3,q3) ((q3)*((p2)-(p1)) + \
(q2)*((p1)-(p3)) + \
(q1)*((p3)-(p2)))
if ( CubitVector::colinear(v1, v2, v3) )
{
return false;
}
CubitPlane tri_plane;
tri_plane.mk_plane_with_points( v1, v2, v3 );
CubitVector pt = tri_plane.project( point );
double area2;
CubitVector normal = tri_plane.normal();
double tol = CUBIT_RESABS;
CubitVector absnorm( fabs(normal.x()), fabs(normal.y()), fabs(normal.z()) );
// project to the closest coordinate plane so we only have to do this in 2D
if (absnorm.x() >= absnorm.y() && absnorm.x() >= absnorm.z())
{
area2 = DETERM3(v1.y(), v1.z(),
v2.y(), v2.z(),
v3.y(), v3.z());
if (fabs(area2) < tol)
{
if ( adjust_on_fail )
{
return attempt_barycentric_coordinates_adjustment(v1, v2, v3, point,
coord_A, coord_B,
coord_C);
}
return false;
}
coord_A = ( DETERM3( pt.y(), pt.z(),
v2.y(), v2.z(),
v3.y(), v3.z() ) / area2 );
coord_B = ( DETERM3( v1.y(), v1.z(),
pt.y(), pt.z(),
v3.y(), v3.z() ) / area2 );
coord_C = ( DETERM3( v1.y(), v1.z(),
v2.y(), v2.z(),
pt.y(), pt.z() ) / area2 );
}
else if(absnorm.y() >= absnorm.x() && absnorm.y() >= absnorm.z())
{
area2 = DETERM3(v1.x(), v1.z(),
v2.x(), v2.z(),
v3.x(), v3.z());
if (fabs(area2) < tol)
{
if ( adjust_on_fail )
{
return attempt_barycentric_coordinates_adjustment(v1, v2, v3, point,
coord_A, coord_B,
coord_C);
}
return false;
}
coord_A = ( DETERM3( pt.x(), pt.z(),
v2.x(), v2.z(),
v3.x(), v3.z() ) / area2 );
coord_B = ( DETERM3( v1.x(), v1.z(),
pt.x(), pt.z(),
v3.x(), v3.z() ) / area2 );
coord_C = ( DETERM3( v1.x(), v1.z(),
v2.x(), v2.z(),
pt.x(), pt.z() ) / area2 );
}
else
{
area2 = DETERM3(v1.x(), v1.y(),
v2.x(), v2.y(),
v3.x(), v3.y());
if (fabs(area2) < tol)
{
if ( adjust_on_fail )
{
return attempt_barycentric_coordinates_adjustment(v1, v2, v3, point,
coord_A, coord_B,
coord_C);
}
return false;
}
coord_A = ( DETERM3( pt.x(), pt.y(),
v2.x(), v2.y(),
v3.x(), v3.y() ) / area2 );
coord_B = ( DETERM3( v1.x(), v1.y(),
pt.x(), pt.y(),
v3.x(), v3.y() ) / area2 );
coord_C = ( DETERM3( v1.x(), v1.y(),
v2.x(), v2.y(),
pt.x(), pt.y() ) / area2 );
}
return true;
}
| void CubitVector::project_to_line_segment | ( | const CubitVector & | pt0, |
| const CubitVector & | pt1 | ||
| ) |
Definition at line 740 of file CubitVector.cpp.
{
CubitVector v0 = pt1-pt0;
CubitVector v1 = *this-pt0;
double len = v0.normalize();
double dot = v0%v1;
CubitVector close_pt;
if ( dot <= 0 )
close_pt = pt0;
else if ( dot >= len )
close_pt = pt1;
else
close_pt = pt0 + dot *v0;
set(close_pt);
}
| void CubitVector::project_to_plane | ( | const CubitVector & | planenormal | ) |
Definition at line 537 of file CubitVector.cpp.
{
CubitVector tmp = planenormal;
tmp.normalize();
// Cross the vector with the normal to get a vector on the plane
CubitVector planevec = tmp * (*this);
// Cross the vector on the plane with the normal to get the
// projection of the vector on the plane
*this = planevec * tmp;
}
| double & CubitVector::r | ( | ) | [inline] |
Definition at line 360 of file CubitVector.hpp.
{ return xVal; }
| void CubitVector::r | ( | const double | x | ) | [inline] |
Definition at line 370 of file CubitVector.hpp.
{ xVal = xIn; }
| void CubitVector::reflect_about_xaxis | ( | double | dummy, |
| double | |||
| ) |
Definition at line 173 of file CubitVector.cpp.
| void CubitVector::rotate | ( | double | angle, |
| double | |||
| ) |
Definition at line 147 of file CubitVector.cpp.
{
xy_to_rtheta();
theta() += angle;
rtheta_to_xy();
}
| void CubitVector::rtheta_to_xy | ( | ) |
| void CubitVector::scale_angle | ( | double | gamma, |
| double | |||
| ) |
Definition at line 178 of file CubitVector.cpp.
{
const double r_factor = 0.3;
const double theta_factor = 0.6;
xy_to_rtheta();
// if neary 2pi, treat as zero
// some near zero stuff strays due to roundoff
if (theta() > TWO_PI - 0.02)
theta() = 0;
// the above screws up on big sheets - need to overhaul at the sheet level
if ( gamma < 1 )
{
//squeeze together points of short radius so that
//long chords won't cross them
theta() += (CUBIT_PI-theta())*(1-gamma)*theta_factor*(1-r());
//push away from center of circle, again so long chords won't cross
r( (r_factor + r()) / (1 + r_factor) );
//scale angle by gamma
theta() *= gamma;
}
else
{
//scale angle by gamma, making sure points nearly 2pi are treated as zero
double new_theta = theta() * gamma;
if ( new_theta < 2.5 * CUBIT_PI || r() < 0.2)
theta( new_theta );
}
rtheta_to_xy();
}
| void CubitVector::set | ( | const double | x, |
| const double | y, | ||
| const double | z | ||
| ) | [inline] |
Definition at line 437 of file CubitVector.hpp.
| void CubitVector::set | ( | const double | xyz[3] | ) | [inline] |
Definition at line 446 of file CubitVector.hpp.
| void CubitVector::set | ( | const CubitVector & | tail, |
| const CubitVector & | head | ||
| ) | [inline] |
| void CubitVector::set | ( | const CubitVector & | to_copy | ) | [inline] |
Definition at line 469 of file CubitVector.hpp.
{
*this = to_copy;
}
| double & CubitVector::theta | ( | ) | [inline] |
Definition at line 362 of file CubitVector.hpp.
{ return yVal; }
| void CubitVector::theta | ( | const double | y | ) | [inline] |
Definition at line 372 of file CubitVector.hpp.
{ yVal = yIn; }
| double CubitVector::vector_angle | ( | const CubitVector & | vector1, |
| const CubitVector & | vector2 | ||
| ) | const |
Definition at line 294 of file CubitVector.cpp.
{
// This routine does not assume that any of the input vectors are of unit
// length. This routine does not normalize the input vectors.
// Special cases:
// If the normal vector is zero length:
// If a new one can be computed from vectors 1 & 2:
// the normal is replaced with the vector cross product
// else the two vectors are colinear and zero or 2PI is returned.
// If the normal is colinear with either (or both) vectors
// a new one is computed with the cross products
// (and checked again).
// Check for zero length normal vector
CubitVector normal = *this;
double normal_lensq = normal.length_squared();
double len_tol = 0.0000001;
if( normal_lensq <= len_tol )
{
// null normal - make it the normal to the plane defined by vector1
// and vector2. If still null, the vectors are colinear so check
// for zero or 180 angle.
normal = vector1 * vector2;
normal_lensq = normal.length_squared();
if( normal_lensq <= len_tol )
{
double cosine = vector1 % vector2;
if( cosine > 0.0 ) return 0.0;
else return CUBIT_PI;
}
}
//Trap for normal vector colinear to one of the other vectors. If so,
//use a normal defined by the two vectors.
double dot_tol = 0.985;
double dot = vector1 % normal;
if( dot * dot >= vector1.length_squared() * normal_lensq * dot_tol )
{
normal = vector1 * vector2;
normal_lensq = normal.length_squared();
//Still problems if all three vectors were colinear
if( normal_lensq <= len_tol )
{
double cosine = vector1 % vector2;
if( cosine >= 0.0 ) return 0.0;
else return CUBIT_PI;
}
}
else
{
//The normal and vector1 are not colinear, now check for vector2
dot = vector2 % normal;
if( dot * dot >= vector2.length_squared() * normal_lensq * dot_tol )
{
normal = vector1 * vector2;
}
}
// Assume a plane such that the normal vector is the plane's normal.
// Create yAxis perpendicular to both the normal and vector1. yAxis is
// now in the plane. Create xAxis as the perpendicular to both yAxis and
// the normal. xAxis is in the plane and is the projection of vector1
// into the plane.
normal.normalize();
CubitVector yAxis = normal;
yAxis *= vector1;
double y = vector2 % yAxis;
// yAxis memory slot will now be used for xAxis
yAxis *= normal;
double x = vector2 % yAxis;
// assert(x != 0.0 || y != 0.0);
if( x == 0.0 && y == 0.0 )
{
return 0.0;
}
double angle = atan2(y, x);
if (angle < 0.0)
{
angle += TWO_PI;
}
// Sometimes angle was slightly less than zero,
// but adding TWO_PI puts us at exactly TWO_PI.
// More likely on optimized builds.
// "volatile" is to remove false precision
// maintained within the scope of this function
if((*(volatile double*)&angle) >= TWO_PI)
{
angle -= TWO_PI;
}
return angle;
}
| double CubitVector::vector_angle_quick | ( | const CubitVector & | vec1, |
| const CubitVector & | vec2 | ||
| ) |
Definition at line 213 of file CubitVector.cpp.
{
//- compute the angle between two vectors in the plane defined by this vector
// build yAxis and xAxis such that xAxis is the projection of
// vec1 onto the normal plane of this vector
// NOTE: vec1 and vec2 are Vectors from the vertex of the angle along
// the two sides of the angle.
// The angle returned is the right-handed angle around this vector
// from vec1 to vec2.
// NOTE: vector_angle_quick gives exactly the same answer as vector_angle below
// providing this vector is normalized. It does so with two fewer
// cross-product evaluations and two fewer vector normalizations.
// This can be a substantial time savings if the function is called
// a significant number of times (e.g Hexer) ... (jrh 11/28/94)
// NOTE: vector_angle() is much more robust. Do not use vector_angle_quick()
// unless you are very sure of the safety of your input vectors.
CubitVector ry = (*this) * vec1;
CubitVector rx = ry * (*this);
double x = vec2 % rx;
double y = vec2 % ry;
double angle;
if( x == 0.0 && y == 0.0 )
{
return 0.0;
}
angle = atan2(y, x);
if (angle < 0.0)
{
angle += TWO_PI;
}
// Sometimes angle was slightly less than zero,
// but adding TWO_PI puts us at exactly TWO_PI.
// More likely on optimized builds.
// "volatile" is to remove false precision
// maintained within the scope of this function
if((*(volatile double*)&angle) >= TWO_PI)
{
angle -= TWO_PI;
}
return angle;
}
| CubitBoolean CubitVector::within_scaled_tolerance | ( | const CubitVector & | v2, |
| double | tol | ||
| ) | const |
Definition at line 403 of file CubitVector.cpp.
{
if (tol < 0)
tol = -tol;
return (((fabs (xVal - v2.xVal) < tol) || (((xVal > 0) == (v2.xVal > 0)) && fabs(xVal) > tol && fabs(v2.xVal/xVal - 1) < tol)) &&
((fabs (yVal - v2.yVal) < tol) || (((yVal > 0) == (v2.yVal > 0)) && fabs(yVal) > tol && fabs(v2.yVal/yVal - 1) < tol)) &&
((fabs (zVal - v2.zVal) < tol) || (((zVal > 0) == (v2.zVal > 0)) && fabs(zVal) > tol && fabs(v2.zVal/zVal - 1) < tol))
);
}
| CubitBoolean CubitVector::within_tolerance | ( | const CubitVector & | vectorPtr2, |
| double | tolerance | ||
| ) | const |
| double CubitVector::x | ( | void | ) | const [inline] |
Definition at line 336 of file CubitVector.hpp.
{ return xVal; }
| double & CubitVector::x | ( | void | ) | [inline] |
Definition at line 342 of file CubitVector.hpp.
{ return xVal; }
| void CubitVector::x | ( | const double | x | ) | [inline] |
Definition at line 364 of file CubitVector.hpp.
{ xVal = xIn; }
| void CubitVector::xy_to_rtheta | ( | ) |
| double CubitVector::y | ( | void | ) | const [inline] |
Definition at line 338 of file CubitVector.hpp.
{ return yVal; }
| double & CubitVector::y | ( | void | ) | [inline] |
Definition at line 344 of file CubitVector.hpp.
{ return yVal; }
| void CubitVector::y | ( | const double | y | ) | [inline] |
Definition at line 366 of file CubitVector.hpp.
{ yVal = yIn; }
| double CubitVector::z | ( | void | ) | const [inline] |
Definition at line 340 of file CubitVector.hpp.
{ return zVal; }
| double & CubitVector::z | ( | void | ) | [inline] |
Definition at line 346 of file CubitVector.hpp.
{ return zVal; }
| void CubitVector::z | ( | const double | z | ) | [inline] |
Definition at line 368 of file CubitVector.hpp.
{ zVal = zIn; }
| CubitVector interpolate | ( | const double | param, |
| const CubitVector & | v1, | ||
| const CubitVector & | v2 | ||
| ) | [friend] |
Definition at line 634 of file CubitVector.hpp.
{
CubitVector temp = (1.0 - param) * v1;
temp += param * v2;
return temp;
}
| int operator!= | ( | const CubitVector & | v1, |
| const CubitVector & | v2 | ||
| ) | [friend] |
| double operator% | ( | const CubitVector & | v1, |
| const CubitVector & | v2 | ||
| ) | [friend] |
Definition at line 624 of file CubitVector.hpp.
{
return( vector1.xVal * vector2.xVal +
vector1.yVal * vector2.yVal +
vector1.zVal * vector2.zVal );
}
| CubitVector operator* | ( | const CubitVector & | v1, |
| const CubitVector & | v2 | ||
| ) | [friend] |
Definition at line 563 of file CubitVector.hpp.
{
return CubitVector(vector1) *= vector2;
}
| CubitVector operator* | ( | const CubitVector & | v1, |
| const double | sclr | ||
| ) | [friend] |
Definition at line 570 of file CubitVector.hpp.
{
return CubitVector(vector1) *= scalar;
}
| CubitVector operator* | ( | const double | sclr, |
| const CubitVector & | v1 | ||
| ) | [friend] |
Definition at line 577 of file CubitVector.hpp.
{
return CubitVector(vector1) *= scalar;
}
| CubitVector operator+ | ( | const CubitVector & | v1, |
| const CubitVector & | v2 | ||
| ) | [friend] |
Definition at line 541 of file CubitVector.hpp.
{
double xv = vector1.xVal + vector2.xVal;
double yv = vector1.yVal + vector2.yVal;
double zv = vector1.zVal + vector2.zVal;
return CubitVector(xv,yv,zv);
// return CubitVector(vector1) += vector2;
}
| CubitVector operator- | ( | const CubitVector & | v1, |
| const CubitVector & | v2 | ||
| ) | [friend] |
Definition at line 551 of file CubitVector.hpp.
{
double xv = vector1.xVal - vector2.xVal;
double yv = vector1.yVal - vector2.yVal;
double zv = vector1.zVal - vector2.zVal;
return CubitVector(xv,yv,zv);
// return CubitVector(vector1) -= vector2;
}
| CubitVector operator/ | ( | const CubitVector & | v1, |
| const double | sclr | ||
| ) | [friend] |
Definition at line 584 of file CubitVector.hpp.
{
return CubitVector(vector1) /= scalar;
}
| int operator== | ( | const CubitVector & | v1, |
| const CubitVector & | v2 | ||
| ) | [friend] |
| CubitVector operator~ | ( | const CubitVector & | vec | ) | [friend] |
Definition at line 511 of file CubitVector.hpp.
double CubitVector::xVal [private] |
Definition at line 302 of file CubitVector.hpp.
double CubitVector::yVal [private] |
Definition at line 303 of file CubitVector.hpp.
double CubitVector::zVal [private] |
Definition at line 304 of file CubitVector.hpp.