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 {
78 return this->data[0] + this->data[1] + this->data[2];
86 return static_cast<T
>(sqrt(
87 (this->data[0]-
_pt[0])*(this->data[0]-
_pt[0]) +
88 (this->data[1]-
_pt[1])*(this->data[1]-
_pt[1]) +
89 (this->data[2]-
_pt[2])*(this->data[2]-
_pt[2])));
106 return static_cast<T
>(sqrt(this->SquaredLength()));
114 this->data[0] * this->data[0] +
115 this->data[1] * this->data[1] +
116 this->data[2] * this->data[2];
123 T d = this->Length();
125 if (!
equal<T>(d,
static_cast<T
>(0.0)))
179 return Vector3(this->data[1] *
_v[2] - this->data[2] *
_v[1],
180 this->data[2] *
_v[0] - this->data[0] *
_v[2],
181 this->data[0] *
_v[1] - this->data[1] *
_v[0]);
189 return this->data[0] *
_v[0] +
190 this->data[1] *
_v[1] +
191 this->data[2] *
_v[2];
204 return std::abs(this->data[0] *
_v[0]) +
205 std::abs(this->data[1] *
_v[1]) +
206 std::abs(this->data[2] *
_v[2]);
213 return Vector3(std::abs(this->data[0]),
214 std::abs(this->data[1]),
215 std::abs(this->data[2]));
222 static const T
sqrZero =
static_cast<T
>(1
e-06 * 1
e-06);
246 return n.Normalize();
255 T d = ((*this) -
_pt1).Cross((*
this) -
_pt2).Length();
265 if (
_v[0] > this->data[0])
266 this->data[0] =
_v[0];
267 if (
_v[1] > this->data[1])
268 this->data[1] =
_v[1];
269 if (
_v[2] > this->data[2])
270 this->data[2] =
_v[2];
278 if (
_v[0] < this->data[0])
279 this->data[0] =
_v[0];
280 if (
_v[1] < this->data[1])
281 this->data[1] =
_v[1];
282 if (
_v[2] < this->data[2])
283 this->data[2] =
_v[2];
304 T max =
std::max(std::abs(this->data[0]), std::abs(this->data[1]));
305 max =
std::max(max, std::abs(this->data[2]));
313 T min =
std::min(std::abs(this->data[0]), std::abs(this->data[1]));
314 min =
std::min(min, std::abs(this->data[2]));
336 this->data[1] +
_v[1],
337 this->data[2] +
_v[2]);
345 this->data[0] +=
_v[0];
346 this->data[1] +=
_v[1];
347 this->data[2] +=
_v[2];
388 return Vector3(-this->data[0], -this->data[1], -this->data[2]);
397 this->data[1] -
_pt[1],
398 this->data[2] -
_pt[2]);
406 this->data[0] -=
_pt[0];
407 this->data[1] -=
_pt[1];
408 this->data[2] -=
_pt[2];
452 this->data[1] /
_pt[1],
453 this->data[2] /
_pt[2]);
462 this->data[0] /=
_pt[0];
463 this->data[1] /=
_pt[1];
464 this->data[2] /=
_pt[2];
500 this->data[1] *
_p[1],
501 this->data[2] *
_p[2]);
510 this->data[0] *=
_v[0];
511 this->data[1] *=
_v[1];
512 this->data[2] *=
_v[2];
566 return this->Equal(
_v,
static_cast<T
>(1
e-3));
575 return !(*
this ==
_v);
608 return this->data[
clamp(
_index, GZ_ZERO_SIZE_T, GZ_TWO_SIZE_T)];
617 return this->data[
clamp(
_index, GZ_ZERO_SIZE_T, GZ_TWO_SIZE_T)];
642 public:
inline T
X()
const
644 return this->data[0];
649 public:
inline T
Y()
const
651 return this->data[1];
656 public:
inline T
Z()
const
658 return this->data[2];
663 public:
inline T &
X()
665 return this->data[0];
670 public:
inline T &
Y()
672 return this->data[1];
677 public:
inline T &
Z()
679 return this->data[2];
684 public:
inline void X(
const T &
_v)
691 public:
inline void Y(
const T &
_v)
698 public:
inline void Z(
const T &
_v)
709 return this->data[0] <
_pt[0] || this->data[1] <
_pt[1] ||
710 this->data[2] <
_pt[2];
720 for (
auto i : {0, 1, 2})
739 _in.setf(std::ios_base::skipws);
756 constexpr Vector3<T> gVector3Zero(0, 0, 0);
758 constexpr Vector3<T> gVector3One(1, 1, 1);
760 constexpr Vector3<T> gVector3UnitX(1, 0, 0);
762 constexpr Vector3<T> gVector3UnitY(0, 1, 0);
764 constexpr Vector3<T> gVector3UnitZ(0, 0, 1);
766 constexpr Vector3<T> gVector3NaN(