|
Phyth v0.1.0
A dimensional safe C++ header-only mechanics and electromagnetics simulation library.
|
3D vector with Quantity components More...
#include <Vector3.hpp>
Public Member Functions | |
| constexpr | Vector () |
| Construct a zero vector (0, 0, 0) | |
| constexpr | Vector (T x_, T y_, T z_) |
| Construct a vector with specified components. | |
| auto | ToPolar () const |
| Convert to 2D polar coordinates (z component is ignored) | |
| auto | ToSpherical () const |
| Convert to spherical coordinates. | |
| constexpr T & | operator[] (const size_t i) |
| Index-based access (non-const) | |
| constexpr const T & | operator[] (const size_t i) const |
| Index-based access (const) | |
| template<typename U > | |
| constexpr auto | operator+ (const Vector3< U > &other) const |
| Vector addition. | |
| template<typename U > | |
| constexpr auto | operator- (const Vector3< U > &other) const |
| Vector subtraction. | |
| constexpr auto | operator- () const |
| Unary negation. | |
| template<typename U , typename = std::enable_if_t<!std::is_same_v<std::decay_t<U>, Vector>>> | |
| constexpr auto | operator* (U scalar) const |
| Scalar multiplication (vector * scalar) | |
| template<typename U > | |
| constexpr auto | operator/ (U scalar) const |
| Scalar division (vector / scalar) | |
| template<typename U > | |
| constexpr Vector & | operator+= (const Vector3< U > &other) |
| Addition assignment. | |
| template<typename U > | |
| constexpr Vector & | operator-= (const Vector3< U > &other) |
| Subtraction assignment. | |
| template<typename U > | |
| constexpr Vector & | operator*= (U scalar) |
| Scalar multiplication assignment. | |
| template<typename U > | |
| constexpr Vector & | operator/= (U scalar) |
| Scalar division assignment. | |
| template<typename U > | |
| constexpr bool | operator== (const Vector3< U > &other) const |
| Equality comparison. | |
| template<typename U > | |
| constexpr bool | operator!= (const Vector3< U > &other) const |
| Inequality comparison. | |
| template<typename U > | |
| constexpr auto | Dot (const Vector3< U > &other) const -> decltype(x *other.x) |
| Dot product. | |
| template<typename U > | |
| constexpr auto | Cross (const Vector3< U > &other) const |
| Cross product. | |
| auto | Length () const |
| Euclidean length (magnitude) | |
| auto | LengthSquared () const |
| Squared Euclidean length. | |
| Vector3< Scalar > | Normalized () const |
| Normalized vector (unit vector in the same direction) | |
| template<typename U > | |
| auto | Project (const Vector3< U > &other) const |
| Project this vector onto another vector. | |
| template<typename UnitT > | |
| Vector3< Quantity< UnitT > > | As () const |
| Convert all components to a different unit of the same dimension. | |
Static Public Member Functions | |
| static constexpr Vector | FromPolar (T r, const Scalar theta_rad) |
| Construct a 2D polar vector (z = 0) | |
| static constexpr Vector | FromSpherical (T r, const Scalar theta_rad, const Scalar phi_rad) |
| Construct a 3D spherical vector. | |
Public Attributes | |
| T | x |
| T | y |
| T | z |
Friends | |
| std::ostream & | operator<< (std::ostream &os, const Vector &v) |
| Stream insertion operator for Vector3. | |
3D vector with Quantity components
Vector3 is a homogeneous 3D vector where all components share the same Quantity type. This ensures that vector operations preserve physical dimensions correctly.
| T | Component type (must be a Quantity instantiation) |
Example: Vector3<Quantity<Meter>> position(1.0_m, 2.0_m, 3.0_m); Vector3<Quantity<MeterPerSecond>> velocity(1.0_m/s, 0.0_m/s, 0.0_m/s); auto displacement = velocity * 2.0_s; // Vector3<Quantity<Meter>>
Definition at line 28 of file Vector3.hpp.
|
inlineconstexpr |
Construct a zero vector (0, 0, 0)
Definition at line 39 of file Vector3.hpp.
Construct a vector with specified components.
| x_ | X component |
| y_ | Y component |
| z_ | Z component |
Definition at line 49 of file Vector3.hpp.
|
inline |
Convert all components to a different unit of the same dimension.
| UnitT | The target unit type |
Example: auto pos = Vector3<Quantity<Kilometer>>(1.0_km, 0_km, 0_km); auto in_meters = pos.as<Meter>(); // (1000 m, 0 m, 0 m)
Definition at line 419 of file Vector3.hpp.
Cross product.
| U | Quantity type of the other vector |
| other | The other vector |
Example: auto a = Vector3<Quantity<Meter>>(1.0_m, 0_m, 0_m); auto b = Vector3<Quantity<Meter>>(0_m, 1.0_m, 0_m); auto cross = a.Cross(b); // (0 m^2, 0 m^2, 1 m^2)
Definition at line 345 of file Vector3.hpp.
|
inlineconstexpr |
Dot product.
| U | Quantity type of the other vector |
| other | The other vector |
Example: auto a = Vector3<Quantity<Meter>>(1.0_m, 0_m, 0_m); auto b = Vector3<Quantity<Meter>>(0_m, 2.0_m, 0_m); auto dot = a.Dot(b); // (0 m^2, 0 m^2, 0 m^2) (Meter*Meter = Area)
Definition at line 328 of file Vector3.hpp.
|
inlinestaticconstexpr |
Construct a 2D polar vector (z = 0)
| r | Radial distance (must be a Quantity) |
| theta_rad | Angle from the positive X axis, in radians (dimensionless) |
Example: auto pos = Vector3<Quantity<Meter>>::FromPolar(5.0_m, 30.0_deg); // pos ~ (4.33_m, 2.5_m, 0_m)
Definition at line 63 of file Vector3.hpp.
|
inlinestaticconstexpr |
Construct a 3D spherical vector.
| r | Radial distance (must be a Quantity) |
| theta_rad | Polar angle from Z axis, in radians (dimensionless) |
| phi_rad | Azimuthal angle in XY plane from X axis, in radians |
Example: auto pos = Vector3<Quantity<Meter>>::FromSpherical( 5.0_m, 60.0_deg, 45.0_deg );
Definition at line 84 of file Vector3.hpp.
|
inline |
Euclidean length (magnitude)
Definition at line 358 of file Vector3.hpp.
|
inline |
Squared Euclidean length.
Use this instead of Length() when you only need to compare magnitudes, as it avoids the square root computation.
Definition at line 370 of file Vector3.hpp.
Normalized vector (unit vector in the same direction)
Definition at line 382 of file Vector3.hpp.
|
inlineconstexpr |
Inequality comparison.
| U | Quantity type of the other vector |
| other | Vector to compare against |
Definition at line 311 of file Vector3.hpp.
|
inlineconstexpr |
Scalar multiplication (vector * scalar)
| U | Scalar type (must not be a Vector3) |
| scalar | The scalar multiplier |
Note: This is intentionally constrained to non-Vector3 types to avoid ambiguity with element-wise multiplication.
Definition at line 207 of file Vector3.hpp.
|
inlineconstexpr |
Scalar multiplication assignment.
| U | Scalar type |
| scalar | The scalar multiplier |
Definition at line 269 of file Vector3.hpp.
|
inlineconstexpr |
Vector addition.
| U | Quantity type of the other vector |
| other | Vector to add |
Definition at line 163 of file Vector3.hpp.
|
inlineconstexpr |
Addition assignment.
| U | Quantity type of the other vector |
| other | Vector to add |
Definition at line 239 of file Vector3.hpp.
|
inlineconstexpr |
Unary negation.
Definition at line 192 of file Vector3.hpp.
|
inlineconstexpr |
Vector subtraction.
| U | Quantity type of the other vector |
| other | Vector to subtract |
Definition at line 179 of file Vector3.hpp.
|
inlineconstexpr |
Subtraction assignment.
| U | Quantity type of the other vector |
| other | Vector to subtract |
Definition at line 254 of file Vector3.hpp.
|
inlineconstexpr |
Scalar division (vector / scalar)
| U | Scalar type |
| scalar | The scalar divisor |
Definition at line 223 of file Vector3.hpp.
|
inlineconstexpr |
Scalar division assignment.
| U | Scalar type |
| scalar | The scalar divisor |
Definition at line 284 of file Vector3.hpp.
|
inlineconstexpr |
Equality comparison.
| U | Quantity type of the other vector |
| other | Vector to compare against |
Definition at line 299 of file Vector3.hpp.
|
inlineconstexpr |
Index-based access (non-const)
| i | Index: 0 = x, 1 = y, 2 = z |
Example: vec[0] = 1.0_m; // modifies x
Definition at line 133 of file Vector3.hpp.
|
inlineconstexpr |
Index-based access (const)
| i | Index: 0 = x, 1 = y, 2 = z |
Definition at line 147 of file Vector3.hpp.
Project this vector onto another vector.
| U | Quantity type of the target vector |
| other | The vector to project onto |
Example: auto a = Vector3<Quantity<Meter>>(1.0_m, 1.0_m, 0_m); auto b = Vector3<Quantity<Meter>>(1.0_m, 0_m, 0_m); auto proj = a.Project(b); // (1.0 m, 0 m, 0 m)
Definition at line 404 of file Vector3.hpp.
|
inline |
Convert to 2D polar coordinates (z component is ignored)
Note: This function name might be misleading. It returns XY-plane polar coordinates, not a full 3D conversion. Consider using ToSpherical() for full 3D conversion.
Definition at line 103 of file Vector3.hpp.
|
inline |
Convert to spherical coordinates.
Definition at line 117 of file Vector3.hpp.
Stream insertion operator for Vector3.
Output format: "(x, y, z)" where each component uses Quantity's stream formatting.
Example output: "(1 m, 2 m, 3 m)"
Definition at line 431 of file Vector3.hpp.
| T Phyth::Vector< 3, T >::x |
X component
Definition at line 32 of file Vector3.hpp.
| T Phyth::Vector< 3, T >::y |
Y component
Definition at line 34 of file Vector3.hpp.
| T Phyth::Vector< 3, T >::z |
Z component
Definition at line 36 of file Vector3.hpp.