CVector3d.h
Go to the documentation of this file.
1 //==============================================================================
2 /*
3  Software License Agreement (BSD License)
4  Copyright (c) 2003-2016, CHAI3D.
5  (www.chai3d.org)
6 
7  All rights reserved.
8 
9  Redistribution and use in source and binary forms, with or without
10  modification, are permitted provided that the following conditions
11  are met:
12 
13  * Redistributions of source code must retain the above copyright
14  notice, this list of conditions and the following disclaimer.
15 
16  * Redistributions in binary form must reproduce the above
17  copyright notice, this list of conditions and the following
18  disclaimer in the documentation and/or other materials provided
19  with the distribution.
20 
21  * Neither the name of CHAI3D nor the names of its contributors may
22  be used to endorse or promote products derived from this software
23  without specific prior written permission.
24 
25  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
28  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
29  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
30  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
31  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
33  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
35  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36  POSSIBILITY OF SUCH DAMAGE.
37 
38  \author <http://www.chai3d.org>
39  \author Francois Conti
40  \author Dan Morris
41  \version 3.2.0 $Rev: 1890 $
42 */
43 //==============================================================================
44 
45 //------------------------------------------------------------------------------
46 #ifndef CVector3dH
47 #define CVector3dH
48 //------------------------------------------------------------------------------
49 #include "system/CString.h"
50 #include "system/CGlobals.h"
51 #include "math/CConstants.h"
52 //------------------------------------------------------------------------------
53 #include <locale>
54 #include <ostream>
55 #include <cmath>
56 #include <string>
57 #include <sstream>
58 //------------------------------------------------------------------------------
59 
60 //------------------------------------------------------------------------------
61 namespace chai3d {
62 //------------------------------------------------------------------------------
63 
64 //==============================================================================
72 //==============================================================================
73 
74 //==============================================================================
87 //==============================================================================
88 struct cVector3d
89 {
90  //--------------------------------------------------------------------------
91  // CONSTRUCTOR & DESTRUCTOR:
92  //--------------------------------------------------------------------------
93 
94 public:
95 
96  //--------------------------------------------------------------------------
100  //--------------------------------------------------------------------------
102 
103 
104  //--------------------------------------------------------------------------
117  //--------------------------------------------------------------------------
118  cVector3d(const double a_x, const double a_y, const double a_z)
119  {
120  (*this)(0) = a_x;
121  (*this)(1) = a_y;
122  (*this)(2) = a_z;
123  }
124 
125 
126  //--------------------------------------------------------------------------
137  //--------------------------------------------------------------------------
138  cVector3d (const cVector3d &a_vector)
139  {
140  (*this)(0) = a_vector(0);
141  (*this)(1) = a_vector(1);
142  (*this)(2) = a_vector(2);
143  }
144 
145 
146 #ifdef C_USE_EIGEN
147 
148  //--------------------------------------------------------------------------
159  //--------------------------------------------------------------------------
160  cVector3d (const Eigen::Vector3d &a_vector)
161  {
162  (*this)(0) = a_vector(0);
163  (*this)(1) = a_vector(1);
164  (*this)(2) = a_vector(2);
165  }
166 
167 #endif
168 
169 
170  //--------------------------------------------------------------------------
181  //--------------------------------------------------------------------------
182  cVector3d(const char* a_string)
183  {
184  set(a_string);
185  }
186 
187 
188  //--------------------------------------------------------------------------
198  //--------------------------------------------------------------------------
199  cVector3d(const std::string& a_string)
200  {
201  set(a_string);
202  }
203 
204 
205  //--------------------------------------------------------------------------
206  // PUBLIC METHODS
207  //--------------------------------------------------------------------------
208 
209 #ifdef C_USE_EIGEN
210 
212  Eigen::Vector3d eigen()
213  {
214  return (Eigen::Vector3d((*this)(0), (*this)(1), (*this)(2)));
215  }
216 
217 #endif
218 
220  inline double x() const
221  {
222  return((*this)(0));
223  }
224 
226  inline double y() const
227  {
228  return((*this)(1));
229  }
230 
232  inline double z() const
233  {
234  return((*this)(2));
235  }
236 
238  inline void x(const double a_value)
239  {
240  (*this)(0) = a_value;
241  }
242 
244  inline void y(const double a_value)
245  {
246  (*this)(1) = a_value;
247  }
248 
250  inline void z(const double a_value)
251  {
252  (*this)(2) = a_value;
253  }
254 
256  inline void zero()
257  {
258  (*this)(0) = 0.0;
259  (*this)(1) = 0.0;
260  (*this)(2) = 0.0;
261  }
262 
263 
264  //--------------------------------------------------------------------------
276  //--------------------------------------------------------------------------
277  inline double get(const unsigned int& a_component) const
278  {
279  return ((const double*)(this))[a_component];
280  }
281 
282 
283  //--------------------------------------------------------------------------
297  //--------------------------------------------------------------------------
298  inline void set(const double& a_x, const double& a_y, const double& a_z)
299  {
300  (*this)(0) = a_x;
301  (*this)(1) = a_y;
302  (*this)(2) = a_z;
303  }
304 
305 
306  //--------------------------------------------------------------------------
326  //--------------------------------------------------------------------------
327  inline bool set(const char* a_initStr)
328  {
329  // sanity check
330  if (a_initStr == 0) return (false);
331 
332  // look for a valid-format string. ignore leading whitespace and ('s
333  const char* curpos = a_initStr;
334  while( (*curpos != '\0') &&
335  (*curpos == ' ' || *curpos == '\t' || *curpos == '('))
336  {
337  curpos++;
338  }
339 
340  // parse data
341  double ax, ay, az;
342  std::string str = a_initStr;
343  std::locale loc;
344  for (int j=0; j<(int)(str.length()); j++) if (!std::isdigit(str[j], loc) && str[j] != '.') str[j] = ' ';
345  std::istringstream is(str);
346  if (!(is >> ax && !is.fail())) return (false);
347  if (!(is >> ay && !is.fail())) return (false);
348  if (!(is >> az && !is.fail())) return (false);
349 
350  // copy the values we found
351  (*this)(0) = ax;
352  (*this)(1) = ay;
353  (*this)(2) = az;
354 
355  // return result
356  return (true);
357  }
358 
359 
360  //--------------------------------------------------------------------------
380  //--------------------------------------------------------------------------
381  inline bool set(const std::string& a_initStr)
382  {
383  return ( set(a_initStr.c_str()) );
384  }
385 
386 
387  //--------------------------------------------------------------------------
402  //--------------------------------------------------------------------------
403  inline void copyto(cVector3d& a_destination) const
404  {
405  a_destination(0) = (*this)(0);
406  a_destination(1) = (*this)(1);
407  a_destination(2) = (*this)(2);
408  }
409 
410 
411  //--------------------------------------------------------------------------
426  //--------------------------------------------------------------------------
427  inline void copyfrom(const cVector3d &a_source)
428  {
429  (*this)(0) = a_source(0);
430  (*this)(1) = a_source(1);
431  (*this)(2) = a_source(2);
432  }
433 
434 
435  //--------------------------------------------------------------------------
451  //--------------------------------------------------------------------------
452  inline void add(const cVector3d& a_vector)
453  {
454  (*this)(0) = (*this)(0) + a_vector(0);
455  (*this)(1) = (*this)(1) + a_vector(1);
456  (*this)(2) = (*this)(2) + a_vector(2);
457  }
458 
459 
460  //--------------------------------------------------------------------------
478  //--------------------------------------------------------------------------
479  inline void add(const double& a_x,
480  const double& a_y,
481  const double& a_z)
482  {
483  (*this)(0) = (*this)(0) + a_x;
484  (*this)(1) = (*this)(1) + a_y;
485  (*this)(2) = (*this)(2) + a_z;
486  }
487 
488 
489  //--------------------------------------------------------------------------
507  //--------------------------------------------------------------------------
508  inline void addr(const cVector3d& a_vector,
509  cVector3d& a_result) const
510  {
511  a_result(0) = (*this)(0) + a_vector(0);
512  a_result(1) = (*this)(1) + a_vector(1);
513  a_result(2) = (*this)(2) + a_vector(2);
514  }
515 
516 
517  //--------------------------------------------------------------------------
537  //--------------------------------------------------------------------------
538  inline void addr(const double& a_x,
539  const double& a_y,
540  const double& a_z,
541  cVector3d& a_result) const
542  {
543  a_result(0) = (*this)(0) + a_x;
544  a_result(1) = (*this)(1) + a_y;
545  a_result(2) = (*this)(2) + a_z;
546  }
547 
548 
549  //--------------------------------------------------------------------------
565  //--------------------------------------------------------------------------
566  inline void sub(const cVector3d& a_vector)
567  {
568  (*this)(0) = (*this)(0) - a_vector(0);
569  (*this)(1) = (*this)(1) - a_vector(1);
570  (*this)(2) = (*this)(2) - a_vector(2);
571  }
572 
573 
574  //--------------------------------------------------------------------------
592  //--------------------------------------------------------------------------
593  inline void sub(const double& a_x,
594  const double& a_y,
595  const double& a_z)
596  {
597  (*this)(0) = (*this)(0) - a_x;
598  (*this)(1) = (*this)(1) - a_y;
599  (*this)(2) = (*this)(2) - a_z;
600  }
601 
602 
603  //--------------------------------------------------------------------------
621  //--------------------------------------------------------------------------
622  inline void subr(const cVector3d& a_vector,
623  cVector3d& a_result) const
624  {
625  a_result(0) = (*this)(0) - a_vector(0);
626  a_result(1) = (*this)(1) - a_vector(1);
627  a_result(2) = (*this)(2) - a_vector(2);
628  }
629 
630 
631  //--------------------------------------------------------------------------
651  //--------------------------------------------------------------------------
652  inline void subr(const double& a_x,
653  const double& a_y,
654  const double& a_z,
655  cVector3d &a_result) const
656  {
657  a_result(0) = (*this)(0) - a_x;
658  a_result(1) = (*this)(1) - a_y;
659  a_result(2) = (*this)(2) - a_z;
660  }
661 
662 
663  //--------------------------------------------------------------------------
679  //--------------------------------------------------------------------------
680  inline void mul(const double &a_scalar)
681  {
682  (*this)(0) = a_scalar * (*this)(0);
683  (*this)(1) = a_scalar * (*this)(1);
684  (*this)(2) = a_scalar * (*this)(2);
685  }
686 
687 
688  //--------------------------------------------------------------------------
709  //--------------------------------------------------------------------------
710  inline void mul(const double &a_scalar0,
711  const double &a_scalar1,
712  const double &a_scalar2)
713  {
714  (*this)(0) = a_scalar0 * (*this)(0);
715  (*this)(1) = a_scalar1 * (*this)(1);
716  (*this)(2) = a_scalar2 * (*this)(2);
717  }
718 
719 
720  //--------------------------------------------------------------------------
738  //--------------------------------------------------------------------------
739  inline void mulr(const double& a_scalar,
740  cVector3d& a_result) const
741  {
742  a_result(0) = a_scalar * (*this)(0);
743  a_result(1) = a_scalar * (*this)(1);
744  a_result(2) = a_scalar * (*this)(2);
745  }
746 
747 
748  //--------------------------------------------------------------------------
770  //--------------------------------------------------------------------------
771  inline void mulr(const double &a_scalar0,
772  const double &a_scalar1,
773  const double &a_scalar2,
774  cVector3d& a_result) const
775  {
776  a_result(0) = a_scalar0 * (*this)(0);
777  a_result(1) = a_scalar1 * (*this)(1);
778  a_result(2) = a_scalar2 * (*this)(2);
779  }
780 
781 
782  //--------------------------------------------------------------------------
796  //--------------------------------------------------------------------------
797  inline void mulElement(const cVector3d& a_vector)
798  {
799  (*this)(0)*=a_vector(0);
800  (*this)(1)*=a_vector(1);
801  (*this)(2)*=a_vector(2);
802  }
803 
804 
805  //--------------------------------------------------------------------------
821  //--------------------------------------------------------------------------
822  inline void mulElementr(const cVector3d& a_vector,
823  cVector3d& a_result) const
824  {
825  a_result(0) = (*this)(0)*a_vector(0);
826  a_result(1) = (*this)(1)*a_vector(1);
827  a_result(2) = (*this)(2)*a_vector(2);
828  }
829 
830 
831  //--------------------------------------------------------------------------
847  //--------------------------------------------------------------------------
848  inline void div(const double& a_scalar)
849  {
850  double factor = 1.0 / a_scalar;
851  (*this)(0) = (*this)(0) * factor;
852  (*this)(1) = (*this)(1) * factor;
853  (*this)(2) = (*this)(2) * factor;
854  }
855 
856 
857  //--------------------------------------------------------------------------
875  //--------------------------------------------------------------------------
876  inline void divr(const double& a_scalar,
877  cVector3d& a_result) const
878  {
879  double factor = 1.0 / a_scalar;
880  a_result(0) = (*this)(0) * factor;
881  a_result(1) = (*this)(1) * factor;
882  a_result(2) = (*this)(2) * factor;
883  }
884 
885 
886  //--------------------------------------------------------------------------
899  //--------------------------------------------------------------------------
900  inline void negate()
901  {
902  (*this)(0) = -(*this)(0);
903  (*this)(1) = -(*this)(1);
904  (*this)(2) = -(*this)(2);
905  }
906 
907 
908  //--------------------------------------------------------------------------
924  //--------------------------------------------------------------------------
925  inline void negater(cVector3d& a_result) const
926  {
927  a_result(0) = -(*this)(0);
928  a_result(1) = -(*this)(1);
929  a_result(2) = -(*this)(2);
930  }
931 
932 
933  //--------------------------------------------------------------------------
945  //--------------------------------------------------------------------------
946  inline void cross(const cVector3d& a_vector)
947  {
948  // compute cross product
949  double a = ((*this)(1) * a_vector(2) ) - ((*this)(2) * a_vector(1) );
950  double b = -((*this)(0) * a_vector(2) ) + ((*this)(2) * a_vector(0) );
951  double c = ((*this)(0) * a_vector(1) ) - ((*this)(1) * a_vector(0) );
952 
953  // store result in current vector
954  (*this)(0) = a;
955  (*this)(1) = b;
956  (*this)(2) = c;
957  }
958 
959 
960  //--------------------------------------------------------------------------
974  //--------------------------------------------------------------------------
975  inline void crossr(const cVector3d& a_vector,
976  cVector3d& a_result) const
977  {
978  a_result(0) = ((*this)(1) * a_vector(2) ) - ((*this)(2) * a_vector(1) );
979  a_result(1) = -((*this)(0) * a_vector(2) ) + ((*this)(2) * a_vector(0) );
980  a_result(2) = ((*this)(0) * a_vector(1) ) - ((*this)(1) * a_vector(0) );
981  }
982 
983 
984  //--------------------------------------------------------------------------
997  //--------------------------------------------------------------------------
998  inline double dot(const cVector3d& a_vector) const
999  {
1000  return(((*this)(0) * a_vector(0) ) + ((*this)(1) * a_vector(1) ) + ((*this)(2) * a_vector(2) ));
1001  }
1002 
1003 
1004  //--------------------------------------------------------------------------
1014  //--------------------------------------------------------------------------
1015  inline double length() const
1016  {
1017  return(sqrt(((*this)(0) * (*this)(0)) + ((*this)(1) * (*this)(1)) + ((*this)(2) * (*this)(2))));
1018  }
1019 
1020 
1021  //--------------------------------------------------------------------------
1032  //--------------------------------------------------------------------------
1033  inline double lengthsq() const
1034  {
1035  return(((*this)(0) * (*this)(0)) + ((*this)(1) * (*this)(1)) + ((*this)(2) * (*this)(2)));
1036  }
1037 
1038 
1039  //--------------------------------------------------------------------------
1053  //--------------------------------------------------------------------------
1054  inline void normalize()
1055  {
1056  // compute length of vector
1057  double len = sqrt(((*this)(0) * (*this)(0)) + ((*this)(1) * (*this)(1)) + ((*this)(2) * (*this)(2)));
1058  if (len == 0.0) { return; }
1059  double factor = 1.0 / len;
1060 
1061  // divide current vector by its length
1062  (*this)(0) = (*this)(0) * factor;
1063  (*this)(1) = (*this)(1) * factor;
1064  (*this)(2) = (*this)(2) * factor;
1065  }
1066 
1067 
1068  //--------------------------------------------------------------------------
1085  //--------------------------------------------------------------------------
1086  inline void normalizer(cVector3d& a_result) const
1087  {
1088  // compute length of vector
1089  double len = sqrt(((*this)(0) * (*this)(0)) + ((*this)(1) * (*this)(1)) + ((*this)(2) * (*this)(2)));
1090  double factor = 1.0 / len;
1091 
1092  // divide current vector by its length
1093  a_result(0) = (*this)(0) * factor;
1094  a_result(1) = (*this)(1) * factor;
1095  a_result(2) = (*this)(2) * factor;
1096  }
1097 
1098 
1099  //--------------------------------------------------------------------------
1112  //--------------------------------------------------------------------------
1113  inline void clamp(const double& a_maxLength)
1114  {
1115  double len = sqrt(((*this)(0) * (*this)(0)) + ((*this)(1) * (*this)(1)) + ((*this)(2) * (*this)(2)));
1116  if (a_maxLength == 0)
1117  {
1118  (*this)(0) = 0.0;
1119  (*this)(1) = 0.0;
1120  (*this)(2) = 0.0;
1121  }
1122  else if (len > a_maxLength)
1123  {
1124  double factor = a_maxLength / len;
1125  (*this)(0) = (*this)(0) * factor;
1126  (*this)(1) = (*this)(1) * factor;
1127  (*this)(2) = (*this)(2) * factor;
1128  }
1129  }
1130 
1131 
1132  //--------------------------------------------------------------------------
1145  //--------------------------------------------------------------------------
1146  inline double distance(const cVector3d& a_vector) const
1147  {
1148  // compute distance between both points
1149  double dx = (*this)(0) - a_vector(0) ;
1150  double dy = (*this)(1) - a_vector(1) ;
1151  double dz = (*this)(2) - a_vector(2) ;
1152 
1153  // return result
1154  return(sqrt(dx*dx + dy*dy + dz*dz));
1155  }
1156 
1157 
1158  //--------------------------------------------------------------------------
1171  //--------------------------------------------------------------------------
1172  inline double distancesq(const cVector3d& a_vector) const
1173  {
1174  // compute distance for each element
1175  double dx = (*this)(0) - a_vector(0) ;
1176  double dy = (*this)(1) - a_vector(1) ;
1177  double dz = (*this)(2) - a_vector(2) ;
1178 
1179  // return squared distance
1180  return(dx*dx + dy*dy + dz*dz);
1181  }
1182 
1183 
1184  //--------------------------------------------------------------------------
1200  //--------------------------------------------------------------------------
1201  inline bool equals(const cVector3d& a_vector,
1202  const double a_epsilon = 0.0) const
1203  {
1204  // accelerated path for exact equality
1205  if (a_epsilon == 0.0)
1206  {
1207  if ( ((*this)(0) == a_vector(0) ) && ((*this)(1) == a_vector(1) ) && ((*this)(2) == a_vector(2) ) )
1208  {
1209  return (true);
1210  }
1211  else
1212  {
1213  return (false);
1214  }
1215  }
1216 
1217  if ((fabs(a_vector(0) - (*this)(0)) < a_epsilon) &&
1218  (fabs(a_vector(1) - (*this)(1)) < a_epsilon) &&
1219  (fabs(a_vector(2) - (*this)(2)) < a_epsilon))
1220  {
1221  return (true);
1222  }
1223  else
1224  {
1225  return (false);
1226  }
1227  }
1228 
1229 
1230  //--------------------------------------------------------------------------
1243  //--------------------------------------------------------------------------
1244  inline std::string str(const unsigned int a_precision = 2) const
1245  {
1246  std::string result;
1247  result = (cStr((*this)(0), a_precision) + ", " +
1248  cStr((*this)(1), a_precision) + ", " +
1249  cStr((*this)(2), a_precision));
1250  return (result);
1251  }
1252 
1253 
1254  //--------------------------------------------------------------------------
1255  // OPERATORS:
1256  //--------------------------------------------------------------------------
1257 
1258 public:
1259 
1261  inline void operator/= (const double& a_val)
1262  {
1263  double factor = 1.0 / a_val;
1264  (*this)(0) *= factor;
1265  (*this)(1) *= factor;
1266  (*this)(2) *= factor;
1267  }
1268 
1269 
1271  inline void operator*= (const double& a_val)
1272  {
1273  (*this)(0) *= a_val;
1274  (*this)(1) *= a_val;
1275  (*this)(2) *= a_val;
1276  }
1277 
1278 
1280  inline void operator+= (const cVector3d& a_input)
1281  {
1282  (*this)(0) += a_input(0);
1283  (*this)(1) += a_input(1);
1284  (*this)(2) += a_input(2);
1285  }
1286 
1287 
1289  inline void operator-= (const cVector3d& a_input)
1290  {
1291  (*this)(0) -= a_input(0);
1292  (*this)(1) -= a_input(1);
1293  (*this)(2) -= a_input(2);
1294  }
1295 
1296 
1298  inline double& operator() (const int a_index)
1299  {
1300  return m_data[a_index];
1301  }
1302 
1303 
1305  inline const double& operator() (const int a_index) const
1306  {
1307  return m_data[a_index];
1308  }
1309 
1310 
1311  //--------------------------------------------------------------------------
1312  // PRIVATE MEMBERS
1313  //--------------------------------------------------------------------------
1314 
1315 private:
1316 
1318  double m_data[3];
1319 };
1320 
1321 
1322 //==============================================================================
1323 // OPERATORS:
1324 //==============================================================================
1325 
1326 
1328 inline cVector3d operator*(const cVector3d& a_vector, const double a_scale)
1329 {
1330  return (cVector3d(a_vector(0) * a_scale,
1331  a_vector(1) * a_scale,
1332  a_vector(2) * a_scale));
1333 }
1334 
1335 
1337 inline cVector3d operator*(const double a_scale, const cVector3d& a_vector)
1338 {
1339  return (cVector3d(a_vector(0) * a_scale,
1340  a_vector(1) * a_scale,
1341  a_vector(2) * a_scale));
1342 }
1343 
1344 
1346 inline cVector3d operator/(const cVector3d& a_vector, const double a_scale)
1347 {
1348  return (cVector3d(a_vector(0) / a_scale,
1349  a_vector(1) / a_scale,
1350  a_vector(2) / a_scale));
1351 }
1352 
1353 
1355 inline cVector3d operator+(const cVector3d& a_vector0, const cVector3d& a_vector1)
1356 {
1357  return cVector3d(a_vector0(0) + a_vector1(0),
1358  a_vector0(1) + a_vector1(1),
1359  a_vector0(2) + a_vector1(2));
1360 }
1361 
1362 
1364 inline cVector3d operator-(const cVector3d& a_vector0, const cVector3d& a_vector1)
1365 {
1366  return cVector3d(a_vector0(0) - a_vector1(0),
1367  a_vector0(1) - a_vector1(1),
1368  a_vector0(2) - a_vector1(2));
1369 }
1370 
1371 
1373 inline cVector3d operator-(const cVector3d& a_vector0)
1374 {
1375  return cVector3d(-a_vector0(0),
1376  -a_vector0(1),
1377  -a_vector0(2));
1378 }
1379 
1380 
1382 inline double operator*(const cVector3d& a_vector0, const cVector3d& a_vector1)
1383 {
1384  return (a_vector0(0) * a_vector1(0) +
1385  a_vector0(1) * a_vector1(1) +
1386  a_vector0(2) * a_vector1(2));
1387 }
1388 
1389 
1391 static inline std::ostream &operator << (std::ostream &a_os, cVector3d const& a_vector)
1392 {
1393  a_os << a_vector(0) << ", " << a_vector(1) << ", " << a_vector(2) ;
1394  return (a_os);
1395 }
1396 
1397 
1398 //------------------------------------------------------------------------------
1399 } // namespace chai3d
1400 //------------------------------------------------------------------------------
1401 
1402 //------------------------------------------------------------------------------
1403 #endif
1404 //------------------------------------------------------------------------------
This class implements a 3D vector.
Definition: CVector3d.h:88
std::string str(const unsigned int a_precision=2) const
This method convert this vector into a string.
Definition: CVector3d.h:1244
void operator+=(const cVector3d &a_input)
An overloaded += operator for vector/vector addition.
Definition: CVector3d.h:1280
void operator*=(const double &a_val)
An overloaded *= operator for vector/scalar multiplication.
Definition: CVector3d.h:1271
double distance(const cVector3d &a_vector) const
This method computes the distance between two points.
Definition: CVector3d.h:1146
void normalize()
This method normalizes this vector to length 1.
Definition: CVector3d.h:1054
void zero()
This method clears all vector components with zeros.
Definition: CVector3d.h:256
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:1201
void divr(const double &a_scalar, cVector3d &a_result) const
This method computes the division of this vector with a scalar.
Definition: CVector3d.h:876
double distancesq(const cVector3d &a_vector) const
This method computes the squared value distance between two points.
Definition: CVector3d.h:1172
cQuaternion operator+(const cQuaternion &a_quaternion0, const cQuaternion &a_quaternion1)
An overloaded + operator for quaternion addition.
Definition: CQuaternion.h:658
cVector3d(const double a_x, const double a_y, const double a_z)
Constructor of cVector3d.
Definition: CVector3d.h:118
void div(const double &a_scalar)
This method computes the division of this vector with a scalar.
Definition: CVector3d.h:848
void crossr(const cVector3d &a_vector, cVector3d &a_result) const
This method computes the cross product.
Definition: CVector3d.h:975
void y(const double a_value)
This method sets vector component y.
Definition: CVector3d.h:244
cVector3d operator*(const cMatrix3d &a_matrix, const cVector3d &a_vector)
An overloaded * operator for matrix/vector multiplication.
Definition: CMatrix3d.h:2078
std::string cStr(const bool a_value)
This function converts a boolean into a string.
Definition: CString.cpp:189
void normalizer(cVector3d &a_result) const
This method normalizes this vector to length 1.
Definition: CVector3d.h:1086
double length() const
This method computes the Euclidean norm of this vector.
Definition: CVector3d.h:1015
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:652
void sub(const cVector3d &a_vector)
This method computes the subtraction of this vector with another.
Definition: CVector3d.h:566
void mulr(const double &a_scalar, cVector3d &a_result) const
This method computes the multiplication of this vector with a scalar.
Definition: CVector3d.h:739
void copyfrom(const cVector3d &a_source)
This method copies the content of a vector to this one.
Definition: CVector3d.h:427
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:822
Implements mathematical constants.
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:479
void z(const double a_value)
This method sets vector component z.
Definition: CVector3d.h:250
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:538
Implements option settings for CHAI3D.
Implements utility functions for manipulating strings.
cQuaternion operator-(const cQuaternion &a_quaternion0, const cQuaternion &a_quaternion1)
An overloaded - operator for quaternion subtraction.
Definition: CQuaternion.h:667
void negate()
This method computes the negated vector.
Definition: CVector3d.h:900
void addr(const cVector3d &a_vector, cVector3d &a_result) const
This method computes the addition of this vector with another.
Definition: CVector3d.h:508
void operator-=(const cVector3d &a_input)
An overloaded -= operator for vector/vector subtraction.
Definition: CVector3d.h:1289
double lengthsq() const
This method computes the squared value of the Euclidean norm of this vector.
Definition: CVector3d.h:1033
double & operator()(const int a_index)
An overloaded () operator.
Definition: CVector3d.h:1298
void negater(cVector3d &a_result) const
This method computes the negated vector.
Definition: CVector3d.h:925
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:771
void clamp(const double &a_maxLength)
This method clamps this vector to a maximum desired length.
Definition: CVector3d.h:1113
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:710
void copyto(cVector3d &a_destination) const
This method copies the content of this vector to another.
Definition: CVector3d.h:403
void operator/=(const double &a_val)
An overloaded /= operator for vector/scalar division.
Definition: CVector3d.h:1261
void subr(const cVector3d &a_vector, cVector3d &a_result) const
This method computes the subtraction of this vector with another.
Definition: CVector3d.h:622
void x(const double a_value)
This method sets vector component x.
Definition: CVector3d.h:238
double y() const
This method returns vector component y.
Definition: CVector3d.h:226
double x() const
This method returns vector component x.
Definition: CVector3d.h:220
void mul(const double &a_scalar)
This method computes the multiplication of this vector with a scalar.
Definition: CVector3d.h:680
cVector3d()
Definition: CVector3d.h:101
double dot(const cVector3d &a_vector) const
This method computes the dot product between this vector and another.
Definition: CVector3d.h:998
Definition: CAudioBuffer.cpp:56
cVector3d(const std::string &a_string)
Constructor of cVector3d.
Definition: CVector3d.h:199
void add(const cVector3d &a_vector)
This method computes the addition of this vector with another.
Definition: CVector3d.h:452
void cross(const cVector3d &a_vector)
This method computes the cross product.
Definition: CVector3d.h:946
void mulElement(const cVector3d &a_vector)
This method computes the element-by-element product between this vector and another.
Definition: CVector3d.h:797
cVector3d(const char *a_string)
Constructor of cVector3d.
Definition: CVector3d.h:182
cVector3d(const cVector3d &a_vector)
Constructor of cVector3d.
Definition: CVector3d.h:138
cVector3d operator/(const cVector3d &a_vector, const double a_scale)
An overloaded / operator for vector/scalar division.
Definition: CVector3d.h:1346
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:593
double z() const
This method returns vector component z.
Definition: CVector3d.h:232