CHAI3D  3.0.0
CVector3d.h
Go to the documentation of this file.
1 //==============================================================================
2 /*
3  Software License Agreement (BSD License)
4  Copyright (c) 2003-2015, 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.0.0 $Rev: 1639 $
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 <ostream>
54 #include <cmath>
55 //------------------------------------------------------------------------------
56 
57 //------------------------------------------------------------------------------
58 namespace chai3d {
59 //------------------------------------------------------------------------------
60 
61 //==============================================================================
69 //==============================================================================
70 
71 //==============================================================================
84 //==============================================================================
85 struct cVector3d
86 {
87  //--------------------------------------------------------------------------
88  // CONSTRUCTOR & DESTRUCTOR:
89  //--------------------------------------------------------------------------
90 
91 public:
92 
93  //--------------------------------------------------------------------------
97  //--------------------------------------------------------------------------
98  cVector3d() {}
99 
100 
101  //--------------------------------------------------------------------------
114  //--------------------------------------------------------------------------
115  cVector3d(const double a_x, const double a_y, const double a_z)
116  {
117  (*this)(0) = a_x;
118  (*this)(1) = a_y;
119  (*this)(2) = a_z;
120  }
121 
122 
123  //--------------------------------------------------------------------------
134  //--------------------------------------------------------------------------
135  cVector3d (const cVector3d &a_vector)
136  {
137  (*this)(0) = a_vector(0);
138  (*this)(1) = a_vector(1);
139  (*this)(2) = a_vector(2);
140  }
141 
142 
143 #ifdef C_USE_EIGEN
144 
145  //--------------------------------------------------------------------------
156  //--------------------------------------------------------------------------
157  cVector3d (const Eigen::Vector3d &a_vector)
158  {
159  (*this)(0) = a_vector(0);
160  (*this)(1) = a_vector(1);
161  (*this)(2) = a_vector(2);
162  }
163 
164 #endif
165 
166 
167  //--------------------------------------------------------------------------
178  //--------------------------------------------------------------------------
179  cVector3d(const char* a_string)
180  {
181  set(a_string);
182  }
183 
184 
185  //--------------------------------------------------------------------------
195  //--------------------------------------------------------------------------
196  cVector3d(const std::string& a_string)
197  {
198  set(a_string);
199  }
200 
201 
202  //--------------------------------------------------------------------------
203  // PUBLIC METHODS
204  //--------------------------------------------------------------------------
205 
206 #ifdef C_USE_EIGEN
207 
209  Eigen::Vector3d eigen()
210  {
211  return (Eigen::Vector3d((*this)(0), (*this)(1), (*this)(2)));
212  }
213 
214 #endif
215 
217  inline double x() const
218  {
219  return((*this)(0));
220  }
221 
223  inline double y() const
224  {
225  return((*this)(1));
226  }
227 
229  inline double z() const
230  {
231  return((*this)(2));
232  }
233 
235  inline void x(const double a_value)
236  {
237  (*this)(0) = a_value;
238  }
239 
241  inline void y(const double a_value)
242  {
243  (*this)(1) = a_value;
244  }
245 
247  inline void z(const double a_value)
248  {
249  (*this)(2) = a_value;
250  }
251 
253  inline void zero()
254  {
255  (*this)(0) = 0.0;
256  (*this)(1) = 0.0;
257  (*this)(2) = 0.0;
258  }
259 
260 
261  //--------------------------------------------------------------------------
273  //--------------------------------------------------------------------------
274  inline double get(const unsigned int& a_component) const
275  {
276  return ((const double*)(this))[a_component];
277  }
278 
279 
280  //--------------------------------------------------------------------------
294  //--------------------------------------------------------------------------
295  inline void set(const double& a_x, const double& a_y, const double& a_z)
296  {
297  (*this)(0) = a_x;
298  (*this)(1) = a_y;
299  (*this)(2) = a_z;
300  }
301 
302 
303  //--------------------------------------------------------------------------
323  //--------------------------------------------------------------------------
324  inline bool set(const char* a_initStr)
325  {
326  // sanity check
327  if (a_initStr == 0) return (false);
328 
329  // look for a valid-format string. ignore leading whitespace and ('s
330  const char* curpos = a_initStr;
331  while( (*curpos != '\0') &&
332  (*curpos == ' ' || *curpos == '\t' || *curpos == '('))
333  {
334  curpos++;
335  }
336 
337  // scan data
338  double ax, ay, az;
339  int result = sscanf(curpos,"%lf%*[ ,\t\n\r]%lf%*[ ,\t\n\r]%lf", &ax, &ay, &az);
340 
341  // make sure the conversion worked
342  if (result != 3) return (false);
343 
344  // copy the values we found
345  (*this)(0) = ax;
346  (*this)(1) = ay;
347  (*this)(2) = az;
348 
349  // return result
350  return (true);
351  }
352 
353 
354  //--------------------------------------------------------------------------
374  //--------------------------------------------------------------------------
375  inline bool set(const std::string& a_initStr)
376  {
377  return ( set(a_initStr.c_str()) );
378  }
379 
380 
381  //--------------------------------------------------------------------------
396  //--------------------------------------------------------------------------
397  inline void copyto(cVector3d& a_destination) const
398  {
399  a_destination(0) = (*this)(0);
400  a_destination(1) = (*this)(1);
401  a_destination(2) = (*this)(2);
402  }
403 
404 
405  //--------------------------------------------------------------------------
420  //--------------------------------------------------------------------------
421  inline void copyfrom(const cVector3d &a_source)
422  {
423  (*this)(0) = a_source(0);
424  (*this)(1) = a_source(1);
425  (*this)(2) = a_source(2);
426  }
427 
428 
429  //--------------------------------------------------------------------------
445  //--------------------------------------------------------------------------
446  inline void add(const cVector3d& a_vector)
447  {
448  (*this)(0) = (*this)(0) + a_vector(0);
449  (*this)(1) = (*this)(1) + a_vector(1);
450  (*this)(2) = (*this)(2) + a_vector(2);
451  }
452 
453 
454  //--------------------------------------------------------------------------
472  //--------------------------------------------------------------------------
473  inline void add(const double& a_x,
474  const double& a_y,
475  const double& a_z)
476  {
477  (*this)(0) = (*this)(0) + a_x;
478  (*this)(1) = (*this)(1) + a_y;
479  (*this)(2) = (*this)(2) + a_z;
480  }
481 
482 
483  //--------------------------------------------------------------------------
501  //--------------------------------------------------------------------------
502  inline void addr(const cVector3d& a_vector,
503  cVector3d& a_result) const
504  {
505  a_result(0) = (*this)(0) + a_vector(0);
506  a_result(1) = (*this)(1) + a_vector(1);
507  a_result(2) = (*this)(2) + a_vector(2);
508  }
509 
510 
511  //--------------------------------------------------------------------------
531  //--------------------------------------------------------------------------
532  inline void addr(const double& a_x,
533  const double& a_y,
534  const double& a_z,
535  cVector3d& a_result) const
536  {
537  a_result(0) = (*this)(0) + a_x;
538  a_result(1) = (*this)(1) + a_y;
539  a_result(2) = (*this)(2) + a_z;
540  }
541 
542 
543  //--------------------------------------------------------------------------
559  //--------------------------------------------------------------------------
560  inline void sub(const cVector3d& a_vector)
561  {
562  (*this)(0) = (*this)(0) - a_vector(0);
563  (*this)(1) = (*this)(1) - a_vector(1);
564  (*this)(2) = (*this)(2) - a_vector(2);
565  }
566 
567 
568  //--------------------------------------------------------------------------
586  //--------------------------------------------------------------------------
587  inline void sub(const double& a_x,
588  const double& a_y,
589  const double& a_z)
590  {
591  (*this)(0) = (*this)(0) - a_x;
592  (*this)(1) = (*this)(1) - a_y;
593  (*this)(2) = (*this)(2) - a_z;
594  }
595 
596 
597  //--------------------------------------------------------------------------
615  //--------------------------------------------------------------------------
616  inline void subr(const cVector3d& a_vector,
617  cVector3d& a_result) const
618  {
619  a_result(0) = (*this)(0) - a_vector(0);
620  a_result(1) = (*this)(1) - a_vector(1);
621  a_result(2) = (*this)(2) - a_vector(2);
622  }
623 
624 
625  //--------------------------------------------------------------------------
645  //--------------------------------------------------------------------------
646  inline void subr(const double& a_x,
647  const double& a_y,
648  const double& a_z,
649  cVector3d &a_result) const
650  {
651  a_result(0) = (*this)(0) - a_x;
652  a_result(1) = (*this)(1) - a_y;
653  a_result(2) = (*this)(2) - a_z;
654  }
655 
656 
657  //--------------------------------------------------------------------------
673  //--------------------------------------------------------------------------
674  inline void mul(const double &a_scalar)
675  {
676  (*this)(0) = a_scalar * (*this)(0);
677  (*this)(1) = a_scalar * (*this)(1);
678  (*this)(2) = a_scalar * (*this)(2);
679  }
680 
681 
682  //--------------------------------------------------------------------------
703  //--------------------------------------------------------------------------
704  inline void mul(const double &a_scalar0,
705  const double &a_scalar1,
706  const double &a_scalar2)
707  {
708  (*this)(0) = a_scalar0 * (*this)(0);
709  (*this)(1) = a_scalar1 * (*this)(1);
710  (*this)(2) = a_scalar2 * (*this)(2);
711  }
712 
713 
714  //--------------------------------------------------------------------------
732  //--------------------------------------------------------------------------
733  inline void mulr(const double& a_scalar,
734  cVector3d& a_result) const
735  {
736  a_result(0) = a_scalar * (*this)(0);
737  a_result(1) = a_scalar * (*this)(1);
738  a_result(2) = a_scalar * (*this)(2);
739  }
740 
741 
742  //--------------------------------------------------------------------------
764  //--------------------------------------------------------------------------
765  inline void mulr(const double &a_scalar0,
766  const double &a_scalar1,
767  const double &a_scalar2,
768  cVector3d& a_result) const
769  {
770  a_result(0) = a_scalar0 * (*this)(0);
771  a_result(1) = a_scalar1 * (*this)(1);
772  a_result(2) = a_scalar2 * (*this)(2);
773  }
774 
775 
776  //--------------------------------------------------------------------------
790  //--------------------------------------------------------------------------
791  inline void mulElement(const cVector3d& a_vector)
792  {
793  (*this)(0)*=a_vector(0);
794  (*this)(1)*=a_vector(1);
795  (*this)(2)*=a_vector(2);
796  }
797 
798 
799  //--------------------------------------------------------------------------
815  //--------------------------------------------------------------------------
816  inline void mulElementr(const cVector3d& a_vector,
817  cVector3d& a_result) const
818  {
819  a_result(0) = (*this)(0)*a_vector(0);
820  a_result(1) = (*this)(1)*a_vector(1);
821  a_result(2) = (*this)(2)*a_vector(2);
822  }
823 
824 
825  //--------------------------------------------------------------------------
841  //--------------------------------------------------------------------------
842  inline void div(const double& a_scalar)
843  {
844  double factor = 1.0 / a_scalar;
845  (*this)(0) = (*this)(0) * factor;
846  (*this)(1) = (*this)(1) * factor;
847  (*this)(2) = (*this)(2) * factor;
848  }
849 
850 
851  //--------------------------------------------------------------------------
869  //--------------------------------------------------------------------------
870  inline void divr(const double& a_scalar,
871  cVector3d& a_result) const
872  {
873  double factor = 1.0 / a_scalar;
874  a_result(0) = (*this)(0) * factor;
875  a_result(1) = (*this)(1) * factor;
876  a_result(2) = (*this)(2) * factor;
877  }
878 
879 
880  //--------------------------------------------------------------------------
893  //--------------------------------------------------------------------------
894  inline void negate()
895  {
896  (*this)(0) = -(*this)(0);
897  (*this)(1) = -(*this)(1);
898  (*this)(2) = -(*this)(2);
899  }
900 
901 
902  //--------------------------------------------------------------------------
918  //--------------------------------------------------------------------------
919  inline void negater(cVector3d& a_result) const
920  {
921  a_result(0) = -(*this)(0);
922  a_result(1) = -(*this)(1);
923  a_result(2) = -(*this)(2);
924  }
925 
926 
927  //--------------------------------------------------------------------------
939  //--------------------------------------------------------------------------
940  inline void cross(const cVector3d& a_vector)
941  {
942  // compute cross product
943  double a = ((*this)(1) * a_vector(2) ) - ((*this)(2) * a_vector(1) );
944  double b = -((*this)(0) * a_vector(2) ) + ((*this)(2) * a_vector(0) );
945  double c = ((*this)(0) * a_vector(1) ) - ((*this)(1) * a_vector(0) );
946 
947  // store result in current vector
948  (*this)(0) = a;
949  (*this)(1) = b;
950  (*this)(2) = c;
951  }
952 
953 
954  //--------------------------------------------------------------------------
968  //--------------------------------------------------------------------------
969  inline void crossr(const cVector3d& a_vector,
970  cVector3d& a_result) const
971  {
972  a_result(0) = ((*this)(1) * a_vector(2) ) - ((*this)(2) * a_vector(1) );
973  a_result(1) = -((*this)(0) * a_vector(2) ) + ((*this)(2) * a_vector(0) );
974  a_result(2) = ((*this)(0) * a_vector(1) ) - ((*this)(1) * a_vector(0) );
975  }
976 
977 
978  //--------------------------------------------------------------------------
991  //--------------------------------------------------------------------------
992  inline double dot(const cVector3d& a_vector) const
993  {
994  return(((*this)(0) * a_vector(0) ) + ((*this)(1) * a_vector(1) ) + ((*this)(2) * a_vector(2) ));
995  }
996 
997 
998  //--------------------------------------------------------------------------
1008  //--------------------------------------------------------------------------
1009  inline double length() const
1010  {
1011  return(sqrt(((*this)(0) * (*this)(0)) + ((*this)(1) * (*this)(1)) + ((*this)(2) * (*this)(2))));
1012  }
1013 
1014 
1015  //--------------------------------------------------------------------------
1026  //--------------------------------------------------------------------------
1027  inline double lengthsq() const
1028  {
1029  return(((*this)(0) * (*this)(0)) + ((*this)(1) * (*this)(1)) + ((*this)(2) * (*this)(2)));
1030  }
1031 
1032 
1033  //--------------------------------------------------------------------------
1047  //--------------------------------------------------------------------------
1048  inline void normalize()
1049  {
1050  // compute length of vector
1051  double len = sqrt(((*this)(0) * (*this)(0)) + ((*this)(1) * (*this)(1)) + ((*this)(2) * (*this)(2)));
1052  if (len == 0.0) { return; }
1053  double factor = 1.0 / len;
1054 
1055  // divide current vector by its length
1056  (*this)(0) = (*this)(0) * factor;
1057  (*this)(1) = (*this)(1) * factor;
1058  (*this)(2) = (*this)(2) * factor;
1059  }
1060 
1061 
1062  //--------------------------------------------------------------------------
1079  //--------------------------------------------------------------------------
1080  inline void normalizer(cVector3d& a_result) const
1081  {
1082  // compute length of vector
1083  double len = sqrt(((*this)(0) * (*this)(0)) + ((*this)(1) * (*this)(1)) + ((*this)(2) * (*this)(2)));
1084  double factor = 1.0 / len;
1085 
1086  // divide current vector by its length
1087  a_result(0) = (*this)(0) * factor;
1088  a_result(1) = (*this)(1) * factor;
1089  a_result(2) = (*this)(2) * factor;
1090  }
1091 
1092 
1093  //--------------------------------------------------------------------------
1106  //--------------------------------------------------------------------------
1107  inline void clamp(const double& a_maxLength)
1108  {
1109  double len = sqrt(((*this)(0) * (*this)(0)) + ((*this)(1) * (*this)(1)) + ((*this)(2) * (*this)(2)));
1110  if (a_maxLength == 0)
1111  {
1112  (*this)(0) = 0.0;
1113  (*this)(1) = 0.0;
1114  (*this)(2) = 0.0;
1115  }
1116  else if (len > a_maxLength)
1117  {
1118  double factor = a_maxLength / len;
1119  (*this)(0) = (*this)(0) * factor;
1120  (*this)(1) = (*this)(1) * factor;
1121  (*this)(2) = (*this)(2) * factor;
1122  }
1123  }
1124 
1125 
1126  //--------------------------------------------------------------------------
1139  //--------------------------------------------------------------------------
1140  inline double distance(const cVector3d& a_vector) const
1141  {
1142  // compute distance between both points
1143  double dx = (*this)(0) - a_vector(0) ;
1144  double dy = (*this)(1) - a_vector(1) ;
1145  double dz = (*this)(2) - a_vector(2) ;
1146 
1147  // return result
1148  return(sqrt(dx*dx + dy*dy + dz*dz));
1149  }
1150 
1151 
1152  //--------------------------------------------------------------------------
1165  //--------------------------------------------------------------------------
1166  inline double distancesq(const cVector3d& a_vector) const
1167  {
1168  // compute distance for each element
1169  double dx = (*this)(0) - a_vector(0) ;
1170  double dy = (*this)(1) - a_vector(1) ;
1171  double dz = (*this)(2) - a_vector(2) ;
1172 
1173  // return squared distance
1174  return(dx*dx + dy*dy + dz*dz);
1175  }
1176 
1177 
1178  //--------------------------------------------------------------------------
1194  //--------------------------------------------------------------------------
1195  inline bool equals(const cVector3d& a_vector,
1196  const double a_epsilon = 0.0) const
1197  {
1198  // accelerated path for exact equality
1199  if (a_epsilon == 0.0)
1200  {
1201  if ( ((*this)(0) == a_vector(0) ) && ((*this)(1) == a_vector(1) ) && ((*this)(2) == a_vector(2) ) )
1202  {
1203  return (true);
1204  }
1205  else
1206  {
1207  return (false);
1208  }
1209  }
1210 
1211  if ((fabs(a_vector(0) - (*this)(0)) < a_epsilon) &&
1212  (fabs(a_vector(1) - (*this)(1)) < a_epsilon) &&
1213  (fabs(a_vector(2) - (*this)(2)) < a_epsilon))
1214  {
1215  return (true);
1216  }
1217  else
1218  {
1219  return (false);
1220  }
1221  }
1222 
1223 
1224  //--------------------------------------------------------------------------
1237  //--------------------------------------------------------------------------
1238  inline std::string str(const unsigned int a_precision = 2) const
1239  {
1240  std::string result;
1241  result = (cStr((*this)(0), a_precision) + ", " +
1242  cStr((*this)(1), a_precision) + ", " +
1243  cStr((*this)(2), a_precision));
1244  return (result);
1245  }
1246 
1247 
1248  //--------------------------------------------------------------------------
1249  // OPERATORS:
1250  //--------------------------------------------------------------------------
1251 
1252 public:
1253 
1255  inline void operator/= (const double& a_val)
1256  {
1257  double factor = 1.0 / a_val;
1258  (*this)(0) *= factor;
1259  (*this)(1) *= factor;
1260  (*this)(2) *= factor;
1261  }
1262 
1263 
1265  inline void operator*= (const double& a_val)
1266  {
1267  (*this)(0) *= a_val;
1268  (*this)(1) *= a_val;
1269  (*this)(2) *= a_val;
1270  }
1271 
1272 
1274  inline void operator+= (const cVector3d& a_input)
1275  {
1276  (*this)(0) += a_input(0);
1277  (*this)(1) += a_input(1);
1278  (*this)(2) += a_input(2);
1279  }
1280 
1281 
1283  inline void operator-= (const cVector3d& a_input)
1284  {
1285  (*this)(0) -= a_input(0);
1286  (*this)(1) -= a_input(1);
1287  (*this)(2) -= a_input(2);
1288  }
1289 
1290 
1292  inline double& operator() (const int a_index)
1293  {
1294  return m_data[a_index];
1295  }
1296 
1297 
1299  inline const double& operator() (const int a_index) const
1300  {
1301  return m_data[a_index];
1302  }
1303 
1304 
1305  //--------------------------------------------------------------------------
1306  // PRIVATE MEMBERS
1307  //--------------------------------------------------------------------------
1308 
1309 private:
1310 
1312  double m_data[3];
1313 };
1314 
1315 
1316 //==============================================================================
1317 // OPERATORS:
1318 //==============================================================================
1319 
1320 
1322 inline cVector3d operator*(const cVector3d& a_vector, const double a_scale)
1323 {
1324  return (cVector3d(a_vector(0) * a_scale,
1325  a_vector(1) * a_scale,
1326  a_vector(2) * a_scale));
1327 }
1328 
1329 
1331 inline cVector3d operator*(const double a_scale, const cVector3d& a_vector)
1332 {
1333  return (cVector3d(a_vector(0) * a_scale,
1334  a_vector(1) * a_scale,
1335  a_vector(2) * a_scale));
1336 }
1337 
1338 
1340 inline cVector3d operator/(const cVector3d& a_vector, const double a_scale)
1341 {
1342  return (cVector3d(a_vector(0) / a_scale,
1343  a_vector(1) / a_scale,
1344  a_vector(2) / a_scale));
1345 }
1346 
1347 
1349 inline cVector3d operator+(const cVector3d& a_vector0, const cVector3d& a_vector1)
1350 {
1351  return cVector3d(a_vector0(0) + a_vector1(0),
1352  a_vector0(1) + a_vector1(1),
1353  a_vector0(2) + a_vector1(2));
1354 }
1355 
1356 
1358 inline cVector3d operator-(const cVector3d& a_vector0, const cVector3d& a_vector1)
1359 {
1360  return cVector3d(a_vector0(0) - a_vector1(0),
1361  a_vector0(1) - a_vector1(1),
1362  a_vector0(2) - a_vector1(2));
1363 }
1364 
1365 
1367 inline cVector3d operator-(const cVector3d& a_vector0)
1368 {
1369  return cVector3d(-a_vector0(0),
1370  -a_vector0(1),
1371  -a_vector0(2));
1372 }
1373 
1374 
1376 inline double operator*(const cVector3d& a_vector0, const cVector3d& a_vector1)
1377 {
1378  return (a_vector0(0) * a_vector1(0) +
1379  a_vector0(1) * a_vector1(1) +
1380  a_vector0(2) * a_vector1(2));
1381 }
1382 
1383 
1385 static inline std::ostream &operator << (std::ostream &a_os, cVector3d const& a_vector)
1386 {
1387  a_os << a_vector(0) << ", " << a_vector(1) << ", " << a_vector(2) ;
1388  return (a_os);
1389 }
1390 
1391 
1392 //------------------------------------------------------------------------------
1393 } // namespace chai3d
1394 //------------------------------------------------------------------------------
1395 
1396 //------------------------------------------------------------------------------
1397 #endif
1398 //------------------------------------------------------------------------------
This class implements a 3D vector.
Definition: CVector3d.h:85
std::string str(const unsigned int a_precision=2) const
This method convert this vector into a string.
Definition: CVector3d.h:1238
void operator+=(const cVector3d &a_input)
An overloaded += operator for vector/vector addition.
Definition: CVector3d.h:1274
bool set(const std::string &a_initStr)
This method initializes this vector from and input string.
Definition: CVector3d.h:375
void operator*=(const double &a_val)
An overloaded *= operator for vector/scalar multiplication.
Definition: CVector3d.h:1265
double distance(const cVector3d &a_vector) const
This method computes the distance between two points.
Definition: CVector3d.h:1140
void normalize()
This method normalizes this vector to length 1.
Definition: CVector3d.h:1048
void zero()
This method clears all vector components with zeros.
Definition: CVector3d.h:253
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:1195
void divr(const double &a_scalar, cVector3d &a_result) const
This method computes the division of this vector with a scalar.
Definition: CVector3d.h:870
double distancesq(const cVector3d &a_vector) const
This method computes the squared value distance between two points.
Definition: CVector3d.h:1166
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:115
void div(const double &a_scalar)
This method computes the division of this vector with a scalar.
Definition: CVector3d.h:842
void crossr(const cVector3d &a_vector, cVector3d &a_result) const
This method computes the cross product.
Definition: CVector3d.h:969
void y(const double a_value)
This method sets vector component y.
Definition: CVector3d.h:241
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:1080
double length() const
This method computes the Euclidean norm of this vector.
Definition: CVector3d.h:1009
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:646
void sub(const cVector3d &a_vector)
This method computes the subtraction of this vector with another.
Definition: CVector3d.h:560
void mulr(const double &a_scalar, cVector3d &a_result) const
This method computes the multiplication of this vector with a scalar.
Definition: CVector3d.h:733
void copyfrom(const cVector3d &a_source)
This method copies the content of a vector to this one.
Definition: CVector3d.h:421
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:816
Implements mathematical constants.
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:295
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:473
void z(const double a_value)
This method sets vector component z.
Definition: CVector3d.h:247
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:532
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:894
void addr(const cVector3d &a_vector, cVector3d &a_result) const
This method computes the addition of this vector with another.
Definition: CVector3d.h:502
void operator-=(const cVector3d &a_input)
An overloaded -= operator for vector/vector subtraction.
Definition: CVector3d.h:1283
double lengthsq() const
This method computes the squared value of the Euclidean norm of this vector.
Definition: CVector3d.h:1027
double & operator()(const int a_index)
An overloaded () operator.
Definition: CVector3d.h:1292
void negater(cVector3d &a_result) const
This method computes the negated vector.
Definition: CVector3d.h:919
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:765
void clamp(const double &a_maxLength)
This method clamps this vector to a maximum desired length.
Definition: CVector3d.h:1107
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:704
void copyto(cVector3d &a_destination) const
This method copies the content of this vector to another.
Definition: CVector3d.h:397
void operator/=(const double &a_val)
An overloaded /= operator for vector/scalar division.
Definition: CVector3d.h:1255
void subr(const cVector3d &a_vector, cVector3d &a_result) const
This method computes the subtraction of this vector with another.
Definition: CVector3d.h:616
void x(const double a_value)
This method sets vector component x.
Definition: CVector3d.h:235
double y() const
This method returns vector component y.
Definition: CVector3d.h:223
double x() const
This method returns vector component x.
Definition: CVector3d.h:217
void mul(const double &a_scalar)
This method computes the multiplication of this vector with a scalar.
Definition: CVector3d.h:674
cVector3d()
Definition: CVector3d.h:98
double dot(const cVector3d &a_vector) const
This method computes the dot product between this vector and another.
Definition: CVector3d.h:992
Definition: CAudioBuffer.cpp:56
cVector3d(const std::string &a_string)
Constructor of cVector3d.
Definition: CVector3d.h:196
void add(const cVector3d &a_vector)
This method computes the addition of this vector with another.
Definition: CVector3d.h:446
void cross(const cVector3d &a_vector)
This method computes the cross product.
Definition: CVector3d.h:940
void mulElement(const cVector3d &a_vector)
This method computes the element-by-element product between this vector and another.
Definition: CVector3d.h:791
bool set(const char *a_initStr)
This method initializes this vector from an input ANSI spring.
Definition: CVector3d.h:324
cVector3d(const char *a_string)
Constructor of cVector3d.
Definition: CVector3d.h:179
cVector3d(const cVector3d &a_vector)
Constructor of cVector3d.
Definition: CVector3d.h:135
cVector3d operator/(const cVector3d &a_vector, const double a_scale)
An overloaded / operator for vector/scalar division.
Definition: CVector3d.h:1340
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:587
double z() const
This method returns vector component z.
Definition: CVector3d.h:229

CHAI3D 3.0.0 documentation
Please address any questions to support@chai3d.org
(C) 2003-2015 - CHAI3D
All Rights Reserved.