1#ifndef PHYTH_VECTOR3_HPP
2#define PHYTH_VECTOR3_HPP
39 constexpr Vector() : x(0), y(0), z(0) {
193 return Vector(-x, -y, -z);
206 template<
typename U,
typename = std::enable_if_t<!std::is_same_v<std::decay_t<U>, Vector>> >
312 return !(*
this ==
other);
371 return x * x + y * y + z * z;
418 template<
typename UnitT>
432 os <<
"(" <<
v.x <<
", " <<
v.y <<
", " <<
v.z <<
")";
458 template<
typename T,
typename U,
459 typename = std::enable_if_t<!is_vector3_v<T>> >
Scalar cos(const Scalar q)
Cosine of a dimensionless quantity.
Scalar atan2(const Scalar y, const Scalar x)
Two-argument arc tangent (atan2)
auto sqrt(Quantity< UnitT > q)
Square root of a quantity.
Scalar acos(const Scalar q)
Arc cosine (inverse cosine)
Scalar sin(const Scalar q)
Sine of a dimensionless quantity.
constexpr auto operator*(Quantity< U1 > a, Quantity< U2 > b)
Multiply two quantities.
constexpr auto is_vector3_v
Convenience variable template for is_vector3.
3D vector with Quantity components
constexpr T & operator[](const size_t i)
Index-based access (non-const)
constexpr bool operator==(const Vector3< U > &other) const
Equality comparison.
constexpr Vector & operator*=(U scalar)
Scalar multiplication assignment.
constexpr auto operator*(U scalar) const
Scalar multiplication (vector * scalar)
auto LengthSquared() const
Squared Euclidean length.
static constexpr Vector FromSpherical(T r, const Scalar theta_rad, const Scalar phi_rad)
Construct a 3D spherical vector.
constexpr Vector & operator-=(const Vector3< U > &other)
Subtraction assignment.
constexpr Vector(T x_, T y_, T z_)
Construct a vector with specified components.
constexpr auto operator/(U scalar) const
Scalar division (vector / scalar)
constexpr auto Dot(const Vector3< U > &other) const -> decltype(x *other.x)
Dot product.
constexpr Vector & operator+=(const Vector3< U > &other)
Addition assignment.
constexpr bool operator!=(const Vector3< U > &other) const
Inequality comparison.
constexpr Vector()
Construct a zero vector (0, 0, 0)
Vector3< Quantity< UnitT > > As() const
Convert all components to a different unit of the same dimension.
static constexpr Vector FromPolar(T r, const Scalar theta_rad)
Construct a 2D polar vector (z = 0)
auto Length() const
Euclidean length (magnitude)
friend std::ostream & operator<<(std::ostream &os, const Vector &v)
Stream insertion operator for Vector3.
Vector3< Scalar > Normalized() const
Normalized vector (unit vector in the same direction)
constexpr auto Cross(const Vector3< U > &other) const
Cross product.
constexpr const T & operator[](const size_t i) const
Index-based access (const)
constexpr auto operator-(const Vector3< U > &other) const
Vector subtraction.
auto ToSpherical() const
Convert to spherical coordinates.
constexpr Vector & operator/=(U scalar)
Scalar division assignment.
auto Project(const Vector3< U > &other) const
Project this vector onto another vector.
constexpr auto operator-() const
Unary negation.
constexpr auto operator+(const Vector3< U > &other) const
Vector addition.
auto ToPolar() const
Convert to 2D polar coordinates (z component is ignored)
constexpr Vector()=default
constexpr auto Dot(const Vector< N, U > &other) const