17 #ifndef GZ_MATH_VECTOR3_HH_
18 #define GZ_MATH_VECTOR3_HH_
27 #include <gz/math/config.hh>
32 inline namespace GZ_MATH_VERSION_NAMESPACE {
69 public: constexpr
Vector3(
const T &_x,
const T &_y,
const T &_z)
85 return this->data[0] + this->data[1] + this->data[2];
93 return static_cast<T
>(sqrt(
94 (this->data[0]-_pt[0])*(this->data[0]-_pt[0]) +
95 (this->data[1]-_pt[1])*(this->data[1]-_pt[1]) +
96 (this->data[2]-_pt[2])*(this->data[2]-_pt[2])));
106 return this->Distance(
Vector3(_x, _y, _z));
113 return static_cast<T
>(sqrt(this->SquaredLength()));
121 this->data[0] * this->data[0] +
122 this->data[1] * this->data[1] +
123 this->data[2] * this->data[2];
130 T d = this->Length();
132 if (!equal<T>(d,
static_cast<T
>(0.0)))
174 public:
inline void Set(T _x = 0, T _y = 0, T _z = 0)
186 return Vector3(this->data[1] * _v[2] - this->data[2] * _v[1],
187 this->data[2] * _v[0] - this->data[0] * _v[2],
188 this->data[0] * _v[1] - this->data[1] * _v[0]);
196 return this->data[0] * _v[0] +
197 this->data[1] * _v[1] +
198 this->data[2] * _v[2];
211 return std::abs(this->data[0] * _v[0]) +
212 std::abs(this->data[1] * _v[1]) +
213 std::abs(this->data[2] * _v[2]);
220 return Vector3(std::abs(this->data[0]),
221 std::abs(this->data[1]),
222 std::abs(this->data[2]));
229 static const T sqrZero =
static_cast<T
>(1e-06 * 1e-06);
236 perp = this->Cross(
Vector3(0, 1, 0));
262 T d = ((*this) - _pt1).Cross((*
this) - _pt2).Length();
263 d = d / (_pt2 - _pt1).Length();
272 if (_v[0] > this->data[0])
273 this->data[0] = _v[0];
274 if (_v[1] > this->data[1])
275 this->data[1] = _v[1];
276 if (_v[2] > this->data[2])
277 this->data[2] = _v[2];
285 if (_v[0] < this->data[0])
286 this->data[0] = _v[0];
287 if (_v[1] < this->data[1])
288 this->data[1] = _v[1];
289 if (_v[2] < this->data[2])
290 this->data[2] = _v[2];
311 T
max =
std::max(std::abs(this->data[0]), std::abs(this->data[1]));
320 T
min =
std::min(std::abs(this->data[0]), std::abs(this->data[1]));
347 return Vector3(this->data[0] + _v[0],
348 this->data[1] + _v[1],
349 this->data[2] + _v[2]);
357 this->data[0] += _v[0];
358 this->data[1] += _v[1];
359 this->data[2] += _v[2];
381 return {_v.
X() + _s, _v.
Y() + _s, _v.
Z() + _s};
400 return Vector3(-this->data[0], -this->data[1], -this->data[2]);
408 return Vector3(this->data[0] - _pt[0],
409 this->data[1] - _pt[1],
410 this->data[2] - _pt[2]);
418 this->data[0] -= _pt[0];
419 this->data[1] -= _pt[1];
420 this->data[2] -= _pt[2];
442 return {_s - _v.
X(), _s - _v.
Y(), _s - _v.
Z()};
463 return Vector3(this->data[0] / _pt[0],
464 this->data[1] / _pt[1],
465 this->data[2] / _pt[2]);
474 this->data[0] /= _pt[0];
475 this->data[1] /= _pt[1];
476 this->data[2] /= _pt[2];
487 return Vector3(this->data[0] / _v,
511 return Vector3(this->data[0] * _p[0],
512 this->data[1] * _p[1],
513 this->data[2] * _p[2]);
522 this->data[0] *= _v[0];
523 this->data[1] *= _v[1];
524 this->data[2] *= _v[2];
545 return {_v.
X() * _s, _v.
Y() * _s, _v.
Z() * _s};
567 return equal<T>(this->data[0], _v[0], _tol)
568 && equal<T>(this->data[1], _v[1], _tol)
569 && equal<T>(this->data[2], _v[2], _tol);
578 return this->Equal(_v,
static_cast<T
>(1e-3));
587 return !(*
this == _v);
636 this->data[0] =
precision(this->data[0], _precision);
637 this->data[1] =
precision(this->data[1], _precision);
638 this->data[2] =
precision(this->data[2], _precision);
647 return equal<T>(this->data[0], _v[0]) &&
648 equal<T>(this->data[1], _v[1]) &&
649 equal<T>(this->data[2], _v[2]);
654 public:
inline T
X()
const
656 return this->data[0];
661 public:
inline T
Y()
const
663 return this->data[1];
668 public:
inline T
Z()
const
670 return this->data[2];
675 public:
inline T &
X()
677 return this->data[0];
682 public:
inline T &
Y()
684 return this->data[1];
689 public:
inline T &
Z()
691 return this->data[2];
696 public:
inline void X(
const T &_v)
703 public:
inline void Y(
const T &_v)
710 public:
inline void Z(
const T &_v)
721 return this->data[0] < _pt[0] || this->data[1] < _pt[1] ||
722 this->data[2] < _pt[2];
732 for (
auto i : {0, 1, 2})
751 _in.
setf(std::ios_base::skipws);
768 constexpr Vector3<T> gVector3Zero(0, 0, 0);
770 constexpr Vector3<T> gVector3One(1, 1, 1);
772 constexpr Vector3<T> gVector3UnitX(1, 0, 0);
774 constexpr Vector3<T> gVector3UnitY(0, 1, 0);
776 constexpr Vector3<T> gVector3UnitZ(0, 0, 1);
778 constexpr Vector3<T> gVector3NaN(