|
JSim 2026.06.01-p(1)
|
3D vector utility used throughout JSim physics. More...
#include <vector.hpp>
Classes | |
| struct | DragVector |
| Directional drag force vector and validity metadata. More... | |
| struct | DragForceDetails |
| Expanded drag diagnostics for force computation. More... | |
Public Member Functions | |
| constexpr | Vector3 () noexcept |
| Constructs a zero vector. | |
| constexpr | Vector3 (double x_, double y_, double z_) noexcept |
| Constructs a vector from component values. | |
| constexpr | Vector3 (const Vector3 &) noexcept=default |
| constexpr | Vector3 (Vector3 &&) noexcept=default |
| constexpr Vector3 & | operator= (const Vector3 &) noexcept=default |
| constexpr Vector3 & | operator= (Vector3 &&) noexcept=default |
| constexpr Vector3 | operator+ (const Vector3 &o) const noexcept |
| Returns component-wise sum. | |
| constexpr Vector3 | operator- (const Vector3 &o) const noexcept |
| Returns component-wise difference. | |
| constexpr Vector3 | operator* (double s) const noexcept |
| Returns this vector scaled by a scalar. | |
| constexpr Vector3 | operator/ (double s) const noexcept |
| Returns this vector divided by a scalar. | |
| Vector3 & | operator+= (const Vector3 &o) noexcept |
| Adds o component-wise into this vector. | |
| Vector3 & | operator-= (const Vector3 &o) noexcept |
| Subtracts o component-wise from this vector. | |
| Vector3 & | operator*= (double s) noexcept |
| Multiplies each component by s. | |
| Vector3 & | operator/= (double s) noexcept |
| Divides each component by s. | |
| constexpr bool | operator== (const Vector3 &o) const noexcept |
| Exact component-wise equality comparison. | |
| constexpr bool | operator!= (const Vector3 &o) const noexcept |
| Exact component-wise inequality comparison. | |
| constexpr double | norm2 () const noexcept |
| Returns squared magnitude: $x^2+y^2+z^2$. | |
| double | norm () const noexcept |
| Returns Euclidean magnitude. | |
| Vector3 | normalized () const noexcept |
| Returns the normalized direction vector. | |
| constexpr bool | isZero (double eps=1e-12) const noexcept |
| Checks whether the vector is near zero magnitude. | |
| bool | hasNaN () const noexcept |
| Returns true when any component is NaN. | |
| void | toArray (double arr[3]) const noexcept |
| Writes components to a 3-element array. | |
| Vector3 | clamp (const Vector3 &min, const Vector3 &max) const noexcept |
| Clamps each component into the inclusive [min, max] range. | |
| constexpr double | dot (const Vector3 &o) const noexcept |
| Returns dot product with o. | |
| Vector3 | cross (const Vector3 &o) const noexcept |
| Returns cross product with o. | |
| double | planarSpeed () const noexcept |
| Returns magnitude of the XY projection. | |
| constexpr Vector3 | xy () const noexcept |
| Returns this vector projected onto the XY plane (z=0). | |
| Vector3 | planarDir () const noexcept |
| Returns normalized XY direction with z=0. | |
| Vector3 | projectOnto (const Vector3 &axis) const noexcept |
| Projects this vector onto another axis. | |
| Vector3 | reflect (const Vector3 &n) const noexcept |
| Reflects this vector across a normalized plane normal. | |
| Vector3 | torque (const Vector3 &r) const noexcept |
| Computes torque from a force applied at offset r. | |
| constexpr Vector3 | operator- () const noexcept |
| Returns the additive inverse of this vector. | |
| double & | operator[] (size_t i) |
| Returns a mutable component by index. | |
| const double & | operator[] (size_t i) const |
| Returns a const component by index. | |
Static Public Member Functions | |
| static Vector3 | fromArray (const double arr[3]) noexcept |
| Builds a vector from a 3-element array. | |
| static double | distance (const Vector3 &a, const Vector3 &b) noexcept |
| Returns Euclidean distance between two vectors treated as points. | |
| static Vector3 | lerp (const Vector3 &a, const Vector3 &b, double t) noexcept |
| Linearly interpolates from a to b. | |
| static Vector3 | magnusForce (const Vector3 &velocity, const Vector3 &omega, double k=1e-4) noexcept |
| Computes the Magnus lift force omega x v scaled by k. | |
| static DragForceDetails | dragForceDetailed (const Vector3 &v, double Cd, double A, double rho=1.225, double linear_drag_coefficient_n_per_mps=0.0) noexcept |
| Computes drag force details for a body moving through air. | |
| static Vector3 | dragForce (const Vector3 &v, double Cd, double A, double rho=1.225) noexcept |
| Computes the total drag force vector for a velocity and body. | |
| static Vector3 | dynamicGravity (const Vector3 &velocity, const Vector3 &spin, double g=9.81, double magnusCoeff=1e-4, double gravityEffect=1.0) noexcept |
| Combines gravity with an optional Magnus lift contribution. | |
| static constexpr Vector3 | zero () noexcept |
| Returns the zero vector. | |
| static constexpr Vector3 | unitX () noexcept |
| Returns the +X basis vector. | |
| static constexpr Vector3 | unitY () noexcept |
| Returns the +Y basis vector. | |
| static constexpr Vector3 | unitZ () noexcept |
| Returns the +Z basis vector. | |
| static Vector3 | tractionForce (const Vector3 &normal, double frictionCoeff, double normalForce) noexcept |
| Computes a traction/friction force aligned with the supplied normal. | |
Public Attributes | |
| double | x |
| X component. | |
| double | y |
| Y component. | |
| double | z |
| Z component. | |
Friends | |
| std::ostream & | operator<< (std::ostream &os, const Vector3 &v) |
| Streams the vector in a fixed-width bracketed format. | |
3D vector utility used throughout JSim physics.
This type stores Cartesian coordinates in SI units when used with simulation state (meters, meters/second, radians/second, newtons, etc.). The math helpers are unit-agnostic, but callers should keep units consistent.
|
inlineconstexprnoexcept |
Constructs a zero vector.
|
inlineconstexprnoexcept |
Constructs a vector from component values.
| x_ | X component. |
| y_ | Y component. |
| z_ | Z component. |
|
constexprdefaultnoexcept |
|
constexprdefaultnoexcept |
Clamps each component into the inclusive [min, max] range.
Returns cross product with o.
Returns Euclidean distance between two vectors treated as points.
|
inlineconstexprnoexcept |
Returns dot product with o.
|
inlinestaticnoexcept |
Computes the total drag force vector for a velocity and body.
| v | Body velocity in meters per second. |
| Cd | Drag coefficient. |
| A | Reference area in square meters. |
| rho | Air density in kilograms per cubic meter. |
|
inlinestaticnoexcept |
Computes drag force details for a body moving through air.
| v | Body velocity in meters per second. |
| Cd | Drag coefficient. |
| A | Reference area in square meters. |
| rho | Air density in kilograms per cubic meter. |
| linear_drag_coefficient_n_per_mps | Optional linear drag term. |
|
inlinestaticnoexcept |
Combines gravity with an optional Magnus lift contribution.
| velocity | Object velocity in meters per second. |
| spin | Angular velocity in radians per second. |
| g | Gravity magnitude in meters per second squared. |
| magnusCoeff | Magnus coefficient applied to the lift term. |
| gravityEffect | Multiplier applied to the gravity vector. |
|
inlinestaticnoexcept |
Builds a vector from a 3-element array.
|
inlinenoexcept |
Returns true when any component is NaN.
|
inlineconstexprnoexcept |
Checks whether the vector is near zero magnitude.
| eps | Absolute tolerance on magnitude. |
|
inlinestaticnoexcept |
Linearly interpolates from a to b.
| a | Start vector. |
| b | End vector. |
| t | Interpolation ratio where 0 is a and 1 is b. |
|
inlinestaticnoexcept |
Computes the Magnus lift force omega x v scaled by k.
| velocity | Linear velocity in meters per second. |
| omega | Angular velocity in radians per second. |
| k | Magnus coefficient in SI units. |
|
inlinenoexcept |
Returns Euclidean magnitude.
|
inlineconstexprnoexcept |
Returns squared magnitude: $x^2+y^2+z^2$.
|
inlinenoexcept |
Returns the normalized direction vector.
|
inlineconstexprnoexcept |
Exact component-wise inequality comparison.
|
inlineconstexprnoexcept |
Returns this vector scaled by a scalar.
|
inlinenoexcept |
Multiplies each component by s.
Returns component-wise sum.
Adds o component-wise into this vector.
|
inlineconstexprnoexcept |
Returns the additive inverse of this vector.
Returns component-wise difference.
Subtracts o component-wise from this vector.
|
inlineconstexprnoexcept |
Returns this vector divided by a scalar.
|
inlinenoexcept |
Divides each component by s.
|
inlineconstexprnoexcept |
Exact component-wise equality comparison.
|
inline |
Returns a mutable component by index.
| i | Component index: 0 for x, 1 for y, 2 for z. |
|
inline |
Returns a const component by index.
| i | Component index: 0 for x, 1 for y, 2 for z. |
|
inlinenoexcept |
Returns normalized XY direction with z=0.
|
inlinenoexcept |
Returns magnitude of the XY projection.
Projects this vector onto another axis.
| axis | Axis to project onto. |
Reflects this vector across a normalized plane normal.
| n | Unit normal of the reflection plane. |
|
inlinenoexcept |
Writes components to a 3-element array.
Computes torque from a force applied at offset r.
| r | Lever arm from the reference point to the application point. |
|
inlinestaticnoexcept |
Computes a traction/friction force aligned with the supplied normal.
| normal | Contact normal direction (expected normalized). |
| frictionCoeff | Unitless friction coefficient. |
| normalForce | Normal force magnitude in newtons. |
|
inlinestaticconstexprnoexcept |
Returns the +X basis vector.
|
inlinestaticconstexprnoexcept |
Returns the +Y basis vector.
|
inlinestaticconstexprnoexcept |
Returns the +Z basis vector.
|
inlineconstexprnoexcept |
Returns this vector projected onto the XY plane (z=0).
|
inlinestaticconstexprnoexcept |
Returns the zero vector.
|
friend |
Streams the vector in a fixed-width bracketed format.
| double frcsim::Vector3::x |
| double frcsim::Vector3::y |
| double frcsim::Vector3::z |