My Project
Loading...
Searching...
No Matches
CVector3d.h
Go to the documentation of this file.
1//==============================================================================
2/*
3 Software License Agreement (BSD License)
4 Copyright (c) 2003-2024, 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.3.0
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//------------------------------------------------------------------------------
61namespace chai3d {
62//------------------------------------------------------------------------------
63
64//==============================================================================
72//==============================================================================
73
74//==============================================================================
87//==============================================================================
89{
90 //--------------------------------------------------------------------------
91 // CONSTRUCTOR & DESTRUCTOR:
92 //--------------------------------------------------------------------------
93
94public:
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#ifdef C_USE_EIGEN
127
128 //--------------------------------------------------------------------------
139 //--------------------------------------------------------------------------
140 cVector3d (const Eigen::Vector3d &a_vector)
141 {
142 (*this)(0) = a_vector(0);
143 (*this)(1) = a_vector(1);
144 (*this)(2) = a_vector(2);
145 }
146
147#endif
148
149
150 //--------------------------------------------------------------------------
161 //--------------------------------------------------------------------------
162 cVector3d(const char* a_string)
163 {
164 set(a_string);
165 }
166
167
168 //--------------------------------------------------------------------------
178 //--------------------------------------------------------------------------
179 cVector3d(const std::string& a_string)
180 {
181 set(a_string);
182 }
183
184
185 //--------------------------------------------------------------------------
186 // PUBLIC METHODS
187 //--------------------------------------------------------------------------
188
189#ifdef C_USE_EIGEN
190
192 Eigen::Vector3d eigen()
193 {
194 return (Eigen::Vector3d((*this)(0), (*this)(1), (*this)(2)));
195 }
196
197#endif
198
200 inline double x() const
201 {
202 return((*this)(0));
203 }
204
206 inline double y() const
207 {
208 return((*this)(1));
209 }
210
212 inline double z() const
213 {
214 return((*this)(2));
215 }
216
218 inline void x(const double a_value)
219 {
220 (*this)(0) = a_value;
221 }
222
224 inline void y(const double a_value)
225 {
226 (*this)(1) = a_value;
227 }
228
230 inline void z(const double a_value)
231 {
232 (*this)(2) = a_value;
233 }
234
236 inline void zero()
237 {
238 (*this)(0) = 0.0;
239 (*this)(1) = 0.0;
240 (*this)(2) = 0.0;
241 }
242
243
244 //--------------------------------------------------------------------------
256 //--------------------------------------------------------------------------
257 inline double get(const unsigned int& a_component) const
258 {
259 return ((const double*)(this))[a_component];
260 }
261
262
263 //--------------------------------------------------------------------------
277 //--------------------------------------------------------------------------
278 inline void set(const double& a_x, const double& a_y, const double& a_z)
279 {
280 (*this)(0) = a_x;
281 (*this)(1) = a_y;
282 (*this)(2) = a_z;
283 }
284
285
286 //--------------------------------------------------------------------------
306 //--------------------------------------------------------------------------
307 inline bool set(const char* a_initStr)
308 {
309 // sanity check
310 if (a_initStr == 0) return (false);
311
312 // look for a valid-format string. ignore leading whitespace and ('s
313 const char* curpos = a_initStr;
314 while( (*curpos != '\0') &&
315 (*curpos == ' ' || *curpos == '\t' || *curpos == '('))
316 {
317 curpos++;
318 }
319
320 // parse data
321 double ax, ay, az;
322 std::string str = a_initStr;
323 std::locale loc;
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);
329
330 // copy the values we found
331 (*this)(0) = ax;
332 (*this)(1) = ay;
333 (*this)(2) = az;
334
335 // return result
336 return (true);
337 }
338
339
340 //--------------------------------------------------------------------------
360 //--------------------------------------------------------------------------
361 inline bool set(const std::string& a_initStr)
362 {
363 return ( set(a_initStr.c_str()) );
364 }
365
366
367 //--------------------------------------------------------------------------
382 //--------------------------------------------------------------------------
383 inline void copyto(cVector3d& a_destination) const
384 {
385 a_destination(0) = (*this)(0);
386 a_destination(1) = (*this)(1);
387 a_destination(2) = (*this)(2);
388 }
389
390
391 //--------------------------------------------------------------------------
406 //--------------------------------------------------------------------------
407 inline void copyfrom(const cVector3d &a_source)
408 {
409 (*this)(0) = a_source(0);
410 (*this)(1) = a_source(1);
411 (*this)(2) = a_source(2);
412 }
413
414
415 //--------------------------------------------------------------------------
431 //--------------------------------------------------------------------------
432 inline void add(const cVector3d& a_vector)
433 {
434 (*this)(0) = (*this)(0) + a_vector(0);
435 (*this)(1) = (*this)(1) + a_vector(1);
436 (*this)(2) = (*this)(2) + a_vector(2);
437 }
438
439
440 //--------------------------------------------------------------------------
458 //--------------------------------------------------------------------------
459 inline void add(const double& a_x,
460 const double& a_y,
461 const double& a_z)
462 {
463 (*this)(0) = (*this)(0) + a_x;
464 (*this)(1) = (*this)(1) + a_y;
465 (*this)(2) = (*this)(2) + a_z;
466 }
467
468
469 //--------------------------------------------------------------------------
487 //--------------------------------------------------------------------------
488 inline void addr(const cVector3d& a_vector,
489 cVector3d& a_result) const
490 {
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);
494 }
495
496
497 //--------------------------------------------------------------------------
517 //--------------------------------------------------------------------------
518 inline void addr(const double& a_x,
519 const double& a_y,
520 const double& a_z,
521 cVector3d& a_result) const
522 {
523 a_result(0) = (*this)(0) + a_x;
524 a_result(1) = (*this)(1) + a_y;
525 a_result(2) = (*this)(2) + a_z;
526 }
527
528
529 //--------------------------------------------------------------------------
545 //--------------------------------------------------------------------------
546 inline void sub(const cVector3d& a_vector)
547 {
548 (*this)(0) = (*this)(0) - a_vector(0);
549 (*this)(1) = (*this)(1) - a_vector(1);
550 (*this)(2) = (*this)(2) - a_vector(2);
551 }
552
553
554 //--------------------------------------------------------------------------
572 //--------------------------------------------------------------------------
573 inline void sub(const double& a_x,
574 const double& a_y,
575 const double& a_z)
576 {
577 (*this)(0) = (*this)(0) - a_x;
578 (*this)(1) = (*this)(1) - a_y;
579 (*this)(2) = (*this)(2) - a_z;
580 }
581
582
583 //--------------------------------------------------------------------------
601 //--------------------------------------------------------------------------
602 inline void subr(const cVector3d& a_vector,
603 cVector3d& a_result) const
604 {
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);
608 }
609
610
611 //--------------------------------------------------------------------------
631 //--------------------------------------------------------------------------
632 inline void subr(const double& a_x,
633 const double& a_y,
634 const double& a_z,
635 cVector3d &a_result) const
636 {
637 a_result(0) = (*this)(0) - a_x;
638 a_result(1) = (*this)(1) - a_y;
639 a_result(2) = (*this)(2) - a_z;
640 }
641
642
643 //--------------------------------------------------------------------------
659 //--------------------------------------------------------------------------
660 inline void mul(const double &a_scalar)
661 {
662 (*this)(0) = a_scalar * (*this)(0);
663 (*this)(1) = a_scalar * (*this)(1);
664 (*this)(2) = a_scalar * (*this)(2);
665 }
666
667
668 //--------------------------------------------------------------------------
689 //--------------------------------------------------------------------------
690 inline void mul(const double &a_scalar0,
691 const double &a_scalar1,
692 const double &a_scalar2)
693 {
694 (*this)(0) = a_scalar0 * (*this)(0);
695 (*this)(1) = a_scalar1 * (*this)(1);
696 (*this)(2) = a_scalar2 * (*this)(2);
697 }
698
699
700 //--------------------------------------------------------------------------
718 //--------------------------------------------------------------------------
719 inline void mulr(const double& a_scalar,
720 cVector3d& a_result) const
721 {
722 a_result(0) = a_scalar * (*this)(0);
723 a_result(1) = a_scalar * (*this)(1);
724 a_result(2) = a_scalar * (*this)(2);
725 }
726
727
728 //--------------------------------------------------------------------------
750 //--------------------------------------------------------------------------
751 inline void mulr(const double &a_scalar0,
752 const double &a_scalar1,
753 const double &a_scalar2,
754 cVector3d& a_result) const
755 {
756 a_result(0) = a_scalar0 * (*this)(0);
757 a_result(1) = a_scalar1 * (*this)(1);
758 a_result(2) = a_scalar2 * (*this)(2);
759 }
760
761
762 //--------------------------------------------------------------------------
776 //--------------------------------------------------------------------------
777 inline void mulElement(const cVector3d& a_vector)
778 {
779 (*this)(0)*=a_vector(0);
780 (*this)(1)*=a_vector(1);
781 (*this)(2)*=a_vector(2);
782 }
783
784
785 //--------------------------------------------------------------------------
801 //--------------------------------------------------------------------------
802 inline void mulElementr(const cVector3d& a_vector,
803 cVector3d& a_result) const
804 {
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);
808 }
809
810
811 //--------------------------------------------------------------------------
827 //--------------------------------------------------------------------------
828 inline void div(const double& a_scalar)
829 {
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;
834 }
835
836
837 //--------------------------------------------------------------------------
855 //--------------------------------------------------------------------------
856 inline void divr(const double& a_scalar,
857 cVector3d& a_result) const
858 {
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;
863 }
864
865
866 //--------------------------------------------------------------------------
879 //--------------------------------------------------------------------------
880 inline void negate()
881 {
882 (*this)(0) = -(*this)(0);
883 (*this)(1) = -(*this)(1);
884 (*this)(2) = -(*this)(2);
885 }
886
887
888 //--------------------------------------------------------------------------
904 //--------------------------------------------------------------------------
905 inline void negater(cVector3d& a_result) const
906 {
907 a_result(0) = -(*this)(0);
908 a_result(1) = -(*this)(1);
909 a_result(2) = -(*this)(2);
910 }
911
912
913 //--------------------------------------------------------------------------
925 //--------------------------------------------------------------------------
926 inline void cross(const cVector3d& a_vector)
927 {
928 // compute cross product
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) );
932
933 // store result in current vector
934 (*this)(0) = a;
935 (*this)(1) = b;
936 (*this)(2) = c;
937 }
938
939
940 //--------------------------------------------------------------------------
954 //--------------------------------------------------------------------------
955 inline void crossr(const cVector3d& a_vector,
956 cVector3d& a_result) const
957 {
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) );
961 }
962
963
964 //--------------------------------------------------------------------------
977 //--------------------------------------------------------------------------
978 inline double dot(const cVector3d& a_vector) const
979 {
980 return(((*this)(0) * a_vector(0) ) + ((*this)(1) * a_vector(1) ) + ((*this)(2) * a_vector(2) ));
981 }
982
983
984 //--------------------------------------------------------------------------
994 //--------------------------------------------------------------------------
995 inline double length() const
996 {
997 return(sqrt(((*this)(0) * (*this)(0)) + ((*this)(1) * (*this)(1)) + ((*this)(2) * (*this)(2))));
998 }
999
1000
1001 //--------------------------------------------------------------------------
1012 //--------------------------------------------------------------------------
1013 inline double lengthsq() const
1014 {
1015 return(((*this)(0) * (*this)(0)) + ((*this)(1) * (*this)(1)) + ((*this)(2) * (*this)(2)));
1016 }
1017
1018
1019 //--------------------------------------------------------------------------
1033 //--------------------------------------------------------------------------
1034 inline void normalize()
1035 {
1036 // compute length of vector
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;
1040
1041 // divide current vector by its length
1042 (*this)(0) = (*this)(0) * factor;
1043 (*this)(1) = (*this)(1) * factor;
1044 (*this)(2) = (*this)(2) * factor;
1045 }
1046
1047
1048 //--------------------------------------------------------------------------
1065 //--------------------------------------------------------------------------
1066 inline void normalizer(cVector3d& a_result) const
1067 {
1068 // compute length of vector
1069 double len = sqrt(((*this)(0) * (*this)(0)) + ((*this)(1) * (*this)(1)) + ((*this)(2) * (*this)(2)));
1070 double factor = 1.0 / len;
1071
1072 // divide current vector by its length
1073 a_result(0) = (*this)(0) * factor;
1074 a_result(1) = (*this)(1) * factor;
1075 a_result(2) = (*this)(2) * factor;
1076 }
1077
1078
1079 //--------------------------------------------------------------------------
1092 //--------------------------------------------------------------------------
1093 inline void clamp(const double& a_maxLength)
1094 {
1095 double len = sqrt(((*this)(0) * (*this)(0)) + ((*this)(1) * (*this)(1)) + ((*this)(2) * (*this)(2)));
1096 if (a_maxLength == 0)
1097 {
1098 (*this)(0) = 0.0;
1099 (*this)(1) = 0.0;
1100 (*this)(2) = 0.0;
1101 }
1102 else if (len > a_maxLength)
1103 {
1104 double factor = a_maxLength / len;
1105 (*this)(0) = (*this)(0) * factor;
1106 (*this)(1) = (*this)(1) * factor;
1107 (*this)(2) = (*this)(2) * factor;
1108 }
1109 }
1110
1111
1112 //--------------------------------------------------------------------------
1125 //--------------------------------------------------------------------------
1126 inline double distance(const cVector3d& a_vector) const
1127 {
1128 // compute distance between both points
1129 double dx = (*this)(0) - a_vector(0) ;
1130 double dy = (*this)(1) - a_vector(1) ;
1131 double dz = (*this)(2) - a_vector(2) ;
1132
1133 // return result
1134 return(sqrt(dx*dx + dy*dy + dz*dz));
1135 }
1136
1137
1138 //--------------------------------------------------------------------------
1151 //--------------------------------------------------------------------------
1152 inline double distancesq(const cVector3d& a_vector) const
1153 {
1154 // compute distance for each element
1155 double dx = (*this)(0) - a_vector(0) ;
1156 double dy = (*this)(1) - a_vector(1) ;
1157 double dz = (*this)(2) - a_vector(2) ;
1158
1159 // return squared distance
1160 return(dx*dx + dy*dy + dz*dz);
1161 }
1162
1163
1164 //--------------------------------------------------------------------------
1180 //--------------------------------------------------------------------------
1181 inline bool equals(const cVector3d& a_vector,
1182 const double a_epsilon = 0.0) const
1183 {
1184 // accelerated path for exact equality
1185 if (a_epsilon == 0.0)
1186 {
1187 if ( ((*this)(0) == a_vector(0) ) && ((*this)(1) == a_vector(1) ) && ((*this)(2) == a_vector(2) ) )
1188 {
1189 return (true);
1190 }
1191 else
1192 {
1193 return (false);
1194 }
1195 }
1196
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))
1200 {
1201 return (true);
1202 }
1203 else
1204 {
1205 return (false);
1206 }
1207 }
1208
1209
1210 //--------------------------------------------------------------------------
1223 //--------------------------------------------------------------------------
1224 inline std::string str(const unsigned int a_precision = 2) const
1225 {
1226 std::string result;
1227 result = (cStr((*this)(0), a_precision) + ", " +
1228 cStr((*this)(1), a_precision) + ", " +
1229 cStr((*this)(2), a_precision));
1230 return (result);
1231 }
1232
1233
1234 //--------------------------------------------------------------------------
1235 // OPERATORS:
1236 //--------------------------------------------------------------------------
1237
1238public:
1239
1241 inline void operator/= (const double& a_val)
1242 {
1243 double factor = 1.0 / a_val;
1244 (*this)(0) *= factor;
1245 (*this)(1) *= factor;
1246 (*this)(2) *= factor;
1247 }
1248
1249
1251 inline void operator*= (const double& a_val)
1252 {
1253 (*this)(0) *= a_val;
1254 (*this)(1) *= a_val;
1255 (*this)(2) *= a_val;
1256 }
1257
1258
1260 inline void operator+= (const cVector3d& a_input)
1261 {
1262 (*this)(0) += a_input(0);
1263 (*this)(1) += a_input(1);
1264 (*this)(2) += a_input(2);
1265 }
1266
1267
1269 inline void operator-= (const cVector3d& a_input)
1270 {
1271 (*this)(0) -= a_input(0);
1272 (*this)(1) -= a_input(1);
1273 (*this)(2) -= a_input(2);
1274 }
1275
1276
1278 inline double& operator() (const int a_index)
1279 {
1280 return m_data[a_index];
1281 }
1282
1283
1285 inline const double& operator() (const int a_index) const
1286 {
1287 return m_data[a_index];
1288 }
1289
1290
1291 //--------------------------------------------------------------------------
1292 // PRIVATE MEMBERS
1293 //--------------------------------------------------------------------------
1294
1295private:
1296
1298 double m_data[3];
1299};
1300
1301
1302//==============================================================================
1303// OPERATORS:
1304//==============================================================================
1305
1306
1308inline cVector3d operator*(const cVector3d& a_vector, const double a_scale)
1309{
1310 return (cVector3d(a_vector(0) * a_scale,
1311 a_vector(1) * a_scale,
1312 a_vector(2) * a_scale));
1313}
1314
1315
1317inline cVector3d operator*(const double a_scale, const cVector3d& a_vector)
1318{
1319 return (cVector3d(a_vector(0) * a_scale,
1320 a_vector(1) * a_scale,
1321 a_vector(2) * a_scale));
1322}
1323
1324
1326inline cVector3d operator/(const cVector3d& a_vector, const double a_scale)
1327{
1328 return (cVector3d(a_vector(0) / a_scale,
1329 a_vector(1) / a_scale,
1330 a_vector(2) / a_scale));
1331}
1332
1333
1335inline cVector3d operator+(const cVector3d& a_vector0, const cVector3d& a_vector1)
1336{
1337 return cVector3d(a_vector0(0) + a_vector1(0),
1338 a_vector0(1) + a_vector1(1),
1339 a_vector0(2) + a_vector1(2));
1340}
1341
1342
1344inline cVector3d operator-(const cVector3d& a_vector0, const cVector3d& a_vector1)
1345{
1346 return cVector3d(a_vector0(0) - a_vector1(0),
1347 a_vector0(1) - a_vector1(1),
1348 a_vector0(2) - a_vector1(2));
1349}
1350
1351
1353inline cVector3d operator-(const cVector3d& a_vector0)
1354{
1355 return cVector3d(-a_vector0(0),
1356 -a_vector0(1),
1357 -a_vector0(2));
1358}
1359
1360
1362inline double operator*(const cVector3d& a_vector0, const cVector3d& a_vector1)
1363{
1364 return (a_vector0(0) * a_vector1(0) +
1365 a_vector0(1) * a_vector1(1) +
1366 a_vector0(2) * a_vector1(2));
1367}
1368
1369
1371static inline std::ostream &operator << (std::ostream &a_os, cVector3d const& a_vector)
1372{
1373 a_os << a_vector(0) << ", " << a_vector(1) << ", " << a_vector(2) ;
1374 return (a_os);
1375}
1376
1377
1378//------------------------------------------------------------------------------
1379} // namespace chai3d
1380//------------------------------------------------------------------------------
1381
1382//------------------------------------------------------------------------------
1383#endif
1384//------------------------------------------------------------------------------
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