118 cVector3d(
const double a_x,
const double a_y,
const double a_z)
140 cVector3d (
const Eigen::Vector3d &a_vector)
142 (*this)(0) = a_vector(0);
143 (*this)(1) = a_vector(1);
144 (*this)(2) = a_vector(2);
192 Eigen::Vector3d eigen()
194 return (Eigen::Vector3d((*
this)(0), (*
this)(1), (*
this)(2)));
200 inline double x()
const
206 inline double y()
const
212 inline double z()
const
218 inline void x(
const double a_value)
220 (*this)(0) = a_value;
224 inline void y(
const double a_value)
226 (*this)(1) = a_value;
230 inline void z(
const double a_value)
232 (*this)(2) = a_value;
257 inline double get(
const unsigned int& a_component)
const
259 return ((
const double*)(
this))[a_component];
278 inline void set(
const double& a_x,
const double& a_y,
const double& a_z)
307 inline bool set(
const char* a_initStr)
310 if (a_initStr == 0)
return (
false);
313 const char* curpos = a_initStr;
314 while( (*curpos !=
'\0') &&
315 (*curpos ==
' ' || *curpos ==
'\t' || *curpos ==
'('))
322 std::string
str = a_initStr;
324 for (
int j=0; j<(int)(
str.length()); j++)
if (!std::isdigit(
str[j], loc) &&
str[j] !=
'.')
str[j] =
' ';
325 std::istringstream is(
str);
326 if (!(is >> ax && !is.fail()))
return (
false);
327 if (!(is >> ay && !is.fail()))
return (
false);
328 if (!(is >> az && !is.fail()))
return (
false);
361 inline bool set(
const std::string& a_initStr)
363 return (
set(a_initStr.c_str()) );
385 a_destination(0) = (*this)(0);
386 a_destination(1) = (*this)(1);
387 a_destination(2) = (*this)(2);
409 (*this)(0) = a_source(0);
410 (*this)(1) = a_source(1);
411 (*this)(2) = a_source(2);
434 (*this)(0) = (*
this)(0) + a_vector(0);
435 (*this)(1) = (*
this)(1) + a_vector(1);
436 (*this)(2) = (*
this)(2) + a_vector(2);
459 inline void add(
const double& a_x,
463 (*this)(0) = (*
this)(0) + a_x;
464 (*this)(1) = (*
this)(1) + a_y;
465 (*this)(2) = (*
this)(2) + a_z;
491 a_result(0) = (*this)(0) + a_vector(0);
492 a_result(1) = (*this)(1) + a_vector(1);
493 a_result(2) = (*this)(2) + a_vector(2);
518 inline void addr(
const double& a_x,
523 a_result(0) = (*this)(0) + a_x;
524 a_result(1) = (*this)(1) + a_y;
525 a_result(2) = (*this)(2) + a_z;
548 (*this)(0) = (*
this)(0) - a_vector(0);
549 (*this)(1) = (*
this)(1) - a_vector(1);
550 (*this)(2) = (*
this)(2) - a_vector(2);
573 inline void sub(
const double& a_x,
577 (*this)(0) = (*
this)(0) - a_x;
578 (*this)(1) = (*
this)(1) - a_y;
579 (*this)(2) = (*
this)(2) - a_z;
605 a_result(0) = (*this)(0) - a_vector(0);
606 a_result(1) = (*this)(1) - a_vector(1);
607 a_result(2) = (*this)(2) - a_vector(2);
632 inline void subr(
const double& a_x,
637 a_result(0) = (*this)(0) - a_x;
638 a_result(1) = (*this)(1) - a_y;
639 a_result(2) = (*this)(2) - a_z;
660 inline void mul(
const double &a_scalar)
662 (*this)(0) = a_scalar * (*
this)(0);
663 (*this)(1) = a_scalar * (*
this)(1);
664 (*this)(2) = a_scalar * (*
this)(2);
690 inline void mul(
const double &a_scalar0,
691 const double &a_scalar1,
692 const double &a_scalar2)
694 (*this)(0) = a_scalar0 * (*
this)(0);
695 (*this)(1) = a_scalar1 * (*
this)(1);
696 (*this)(2) = a_scalar2 * (*
this)(2);
719 inline void mulr(
const double& a_scalar,
722 a_result(0) = a_scalar * (*this)(0);
723 a_result(1) = a_scalar * (*this)(1);
724 a_result(2) = a_scalar * (*this)(2);
751 inline void mulr(
const double &a_scalar0,
752 const double &a_scalar1,
753 const double &a_scalar2,
756 a_result(0) = a_scalar0 * (*this)(0);
757 a_result(1) = a_scalar1 * (*this)(1);
758 a_result(2) = a_scalar2 * (*this)(2);
779 (*this)(0)*=a_vector(0);
780 (*this)(1)*=a_vector(1);
781 (*this)(2)*=a_vector(2);
805 a_result(0) = (*this)(0)*a_vector(0);
806 a_result(1) = (*this)(1)*a_vector(1);
807 a_result(2) = (*this)(2)*a_vector(2);
828 inline void div(
const double& a_scalar)
830 double factor = 1.0 / a_scalar;
831 (*this)(0) = (*
this)(0) * factor;
832 (*this)(1) = (*
this)(1) * factor;
833 (*this)(2) = (*
this)(2) * factor;
856 inline void divr(
const double& a_scalar,
859 double factor = 1.0 / a_scalar;
860 a_result(0) = (*this)(0) * factor;
861 a_result(1) = (*this)(1) * factor;
862 a_result(2) = (*this)(2) * factor;
882 (*this)(0) = -(*
this)(0);
883 (*this)(1) = -(*
this)(1);
884 (*this)(2) = -(*
this)(2);
907 a_result(0) = -(*this)(0);
908 a_result(1) = -(*this)(1);
909 a_result(2) = -(*this)(2);
929 double a = ((*this)(1) * a_vector(2) ) - ((*
this)(2) * a_vector(1) );
930 double b = -((*this)(0) * a_vector(2) ) + ((*
this)(2) * a_vector(0) );
931 double c = ((*this)(0) * a_vector(1) ) - ((*
this)(1) * a_vector(0) );
958 a_result(0) = ((*this)(1) * a_vector(2) ) - ((*
this)(2) * a_vector(1) );
959 a_result(1) = -((*this)(0) * a_vector(2) ) + ((*
this)(2) * a_vector(0) );
960 a_result(2) = ((*this)(0) * a_vector(1) ) - ((*
this)(1) * a_vector(0) );
980 return(((*
this)(0) * a_vector(0) ) + ((*
this)(1) * a_vector(1) ) + ((*
this)(2) * a_vector(2) ));
997 return(sqrt(((*
this)(0) * (*
this)(0)) + ((*
this)(1) * (*
this)(1)) + ((*
this)(2) * (*
this)(2))));
1015 return(((*
this)(0) * (*
this)(0)) + ((*
this)(1) * (*
this)(1)) + ((*
this)(2) * (*
this)(2)));
1037 double len = sqrt(((*
this)(0) * (*
this)(0)) + ((*
this)(1) * (*
this)(1)) + ((*
this)(2) * (*
this)(2)));
1038 if (len == 0.0) {
return; }
1039 double factor = 1.0 / len;
1042 (*this)(0) = (*
this)(0) * factor;
1043 (*this)(1) = (*
this)(1) * factor;
1044 (*this)(2) = (*
this)(2) * factor;
1069 double len = sqrt(((*
this)(0) * (*
this)(0)) + ((*
this)(1) * (*
this)(1)) + ((*
this)(2) * (*
this)(2)));
1070 double factor = 1.0 / len;
1073 a_result(0) = (*this)(0) * factor;
1074 a_result(1) = (*this)(1) * factor;
1075 a_result(2) = (*this)(2) * factor;
1093 inline void clamp(
const double& a_maxLength)
1095 double len = sqrt(((*
this)(0) * (*
this)(0)) + ((*
this)(1) * (*
this)(1)) + ((*
this)(2) * (*
this)(2)));
1096 if (a_maxLength == 0)
1102 else if (len > a_maxLength)
1104 double factor = a_maxLength / len;
1105 (*this)(0) = (*
this)(0) * factor;
1106 (*this)(1) = (*
this)(1) * factor;
1107 (*this)(2) = (*
this)(2) * factor;
1129 double dx = (*this)(0) - a_vector(0) ;
1130 double dy = (*this)(1) - a_vector(1) ;
1131 double dz = (*this)(2) - a_vector(2) ;
1134 return(sqrt(dx*dx + dy*dy + dz*dz));
1155 double dx = (*this)(0) - a_vector(0) ;
1156 double dy = (*this)(1) - a_vector(1) ;
1157 double dz = (*this)(2) - a_vector(2) ;
1160 return(dx*dx + dy*dy + dz*dz);
1182 const double a_epsilon = 0.0)
const
1185 if (a_epsilon == 0.0)
1187 if ( ((*
this)(0) == a_vector(0) ) && ((*
this)(1) == a_vector(1) ) && ((*
this)(2) == a_vector(2) ) )
1197 if ((fabs(a_vector(0) - (*
this)(0)) < a_epsilon) &&
1198 (fabs(a_vector(1) - (*
this)(1)) < a_epsilon) &&
1199 (fabs(a_vector(2) - (*
this)(2)) < a_epsilon))
1224 inline std::string
str(
const unsigned int a_precision = 2)
const
1227 result = (
cStr((*
this)(0), a_precision) +
", " +
1228 cStr((*
this)(1), a_precision) +
", " +
1229 cStr((*
this)(2), a_precision));
1243 double factor = 1.0 / a_val;
1244 (*this)(0) *= factor;
1245 (*this)(1) *= factor;
1246 (*this)(2) *= factor;
1253 (*this)(0) *= a_val;
1254 (*this)(1) *= a_val;
1255 (*this)(2) *= a_val;
1262 (*this)(0) += a_input(0);
1263 (*this)(1) += a_input(1);
1264 (*this)(2) += a_input(2);
1271 (*this)(0) -= a_input(0);
1272 (*this)(1) -= a_input(1);
1273 (*this)(2) -= a_input(2);
1280 return m_data[a_index];
1287 return m_data[a_index];
1310 return (
cVector3d(a_vector(0) * a_scale,
1311 a_vector(1) * a_scale,
1312 a_vector(2) * a_scale));
1319 return (
cVector3d(a_vector(0) * a_scale,
1320 a_vector(1) * a_scale,
1321 a_vector(2) * a_scale));
1328 return (
cVector3d(a_vector(0) / a_scale,
1329 a_vector(1) / a_scale,
1330 a_vector(2) / a_scale));
1337 return cVector3d(a_vector0(0) + a_vector1(0),
1338 a_vector0(1) + a_vector1(1),
1339 a_vector0(2) + a_vector1(2));
1346 return cVector3d(a_vector0(0) - a_vector1(0),
1347 a_vector0(1) - a_vector1(1),
1348 a_vector0(2) - a_vector1(2));
1364 return (a_vector0(0) * a_vector1(0) +
1365 a_vector0(1) * a_vector1(1) +
1366 a_vector0(2) * a_vector1(2));
1371static inline std::ostream &operator << (std::ostream &a_os, cVector3d
const& a_vector)
1373 a_os << a_vector(0) <<
", " << a_vector(1) <<
", " << a_vector(2) ;
Implements mathematical constants.
Implements option settings for CHAI3D.
Implements utility functions for manipulating strings.
Definition CAudioBuffer.cpp:57
cMatrix3d operator-(const cMatrix3d &a_matrix1, const cMatrix3d &a_matrix2)
An overloaded - operator for matrix/matrix addition.
Definition CMatrix3d.h:2593
std::string cStr(const bool a_value)
This function converts a boolean into a string.
Definition CString.cpp:189
cMatrix3d operator+(const cMatrix3d &a_matrix1, const cMatrix3d &a_matrix2)
An overloaded + operator for matrix/matrix addition.
Definition CMatrix3d.h:2583
cVector3d operator*(const cMatrix3d &a_matrix, const cVector3d &a_vector)
An overloaded * operator for matrix/vector multiplication.
Definition CMatrix3d.h:2554
cVector3d operator/(const cVector3d &a_vector, const double a_scale)
An overloaded / operator for vector/scalar division.
Definition CVector3d.h:1326
This class implements a 3D vector.
Definition CVector3d.h:89
void div(const double &a_scalar)
This method computes the division of this vector with a scalar.
Definition CVector3d.h:828
void addr(const double &a_x, const double &a_y, const double &a_z, cVector3d &a_result) const
This method computes the addition of this vector with another.
Definition CVector3d.h:518
void mul(const double &a_scalar0, const double &a_scalar1, const double &a_scalar2)
This method computes the multiplication of each component of this vector by a set of scalars.
Definition CVector3d.h:690
void normalize()
This method normalizes this vector to length 1.
Definition CVector3d.h:1034
void subr(const double &a_x, const double &a_y, const double &a_z, cVector3d &a_result) const
This method computes the subtraction of this vector with another.
Definition CVector3d.h:632
double distancesq(const cVector3d &a_vector) const
This method computes the squared value distance between two points.
Definition CVector3d.h:1152
cVector3d()
Definition CVector3d.h:101
void normalizer(cVector3d &a_result) const
This method normalizes this vector to length 1.
Definition CVector3d.h:1066
double lengthsq() const
This method computes the squared value of the Euclidean norm of this vector.
Definition CVector3d.h:1013
void mulr(const double &a_scalar, cVector3d &a_result) const
This method computes the multiplication of this vector with a scalar.
Definition CVector3d.h:719
void operator+=(const cVector3d &a_input)
An overloaded += operator for vector/vector addition.
Definition CVector3d.h:1260
double y() const
This method returns vector component y.
Definition CVector3d.h:206
void zero()
This method clears all vector components with zeros.
Definition CVector3d.h:236
double & operator()(const int a_index)
An overloaded () operator.
Definition CVector3d.h:1278
void operator*=(const double &a_val)
An overloaded *= operator for vector/scalar multiplication.
Definition CVector3d.h:1251
double z() const
This method returns vector component z.
Definition CVector3d.h:212
std::string str(const unsigned int a_precision=2) const
This method convert this vector into a string.
Definition CVector3d.h:1224
void operator/=(const double &a_val)
An overloaded /= operator for vector/scalar division.
Definition CVector3d.h:1241
void add(const cVector3d &a_vector)
This method computes the addition of this vector with another.
Definition CVector3d.h:432
void mulElement(const cVector3d &a_vector)
This method computes the element-by-element product between this vector and another.
Definition CVector3d.h:777
bool equals(const cVector3d &a_vector, const double a_epsilon=0.0) const
This method performs an equality test between two vectors.
Definition CVector3d.h:1181
void divr(const double &a_scalar, cVector3d &a_result) const
This method computes the division of this vector with a scalar.
Definition CVector3d.h:856
cVector3d(const double a_x, const double a_y, const double a_z)
Constructor of cVector3d.
Definition CVector3d.h:118
double dot(const cVector3d &a_vector) const
This method computes the dot product between this vector and another.
Definition CVector3d.h:978
double distance(const cVector3d &a_vector) const
This method computes the distance between two points.
Definition CVector3d.h:1126
void set(const double &a_x, const double &a_y, const double &a_z)
This method initializes this vector with components x, y, and z passed as arguments.
Definition CVector3d.h:278
bool set(const std::string &a_initStr)
This method initializes this vector from and input string.
Definition CVector3d.h:361
void mulElementr(const cVector3d &a_vector, cVector3d &a_result) const
This method computes the element-by-element product between this vector and another.
Definition CVector3d.h:802
void crossr(const cVector3d &a_vector, cVector3d &a_result) const
This method computes the cross product.
Definition CVector3d.h:955
void addr(const cVector3d &a_vector, cVector3d &a_result) const
This method computes the addition of this vector with another.
Definition CVector3d.h:488
cVector3d(const char *a_string)
Constructor of cVector3d.
Definition CVector3d.h:162
void cross(const cVector3d &a_vector)
This method computes the cross product.
Definition CVector3d.h:926
double x() const
This method returns vector component x.
Definition CVector3d.h:200
void sub(const double &a_x, const double &a_y, const double &a_z)
This method computes the subtraction of this vector with another.
Definition CVector3d.h:573
bool set(const char *a_initStr)
This method initializes this vector from an input ANSI spring.
Definition CVector3d.h:307
void clamp(const double &a_maxLength)
This method clamps this vector to a maximum desired length.
Definition CVector3d.h:1093
double length() const
This method computes the Euclidean norm of this vector.
Definition CVector3d.h:995
void y(const double a_value)
This method sets vector component y.
Definition CVector3d.h:224
void x(const double a_value)
This method sets vector component x.
Definition CVector3d.h:218
void add(const double &a_x, const double &a_y, const double &a_z)
This method computes the addition of this vector with another.
Definition CVector3d.h:459
void mul(const double &a_scalar)
This method computes the multiplication of this vector with a scalar.
Definition CVector3d.h:660
void z(const double a_value)
This method sets vector component z.
Definition CVector3d.h:230
void sub(const cVector3d &a_vector)
This method computes the subtraction of this vector with another.
Definition CVector3d.h:546
void copyto(cVector3d &a_destination) const
This method copies the content of this vector to another.
Definition CVector3d.h:383
cVector3d(const std::string &a_string)
Constructor of cVector3d.
Definition CVector3d.h:179
double get(const unsigned int &a_component) const
This method returns the i th component of the vector.
Definition CVector3d.h:257
void negate()
This method computes the negated vector.
Definition CVector3d.h:880
void subr(const cVector3d &a_vector, cVector3d &a_result) const
This method computes the subtraction of this vector with another.
Definition CVector3d.h:602
void copyfrom(const cVector3d &a_source)
This method copies the content of a vector to this one.
Definition CVector3d.h:407
void negater(cVector3d &a_result) const
This method computes the negated vector.
Definition CVector3d.h:905
void operator-=(const cVector3d &a_input)
An overloaded -= operator for vector/vector subtraction.
Definition CVector3d.h:1269
void mulr(const double &a_scalar0, const double &a_scalar1, const double &a_scalar2, cVector3d &a_result) const
This method computes the multiplication of each component of this vector by a set of scalars.
Definition CVector3d.h:751