|
Phyth v0.1.0
A dimensional safe C++ header-only mechanics and electromagnetics simulation library.
|
Constrains a particle's distance from an anchor within an interval. More...
#include <Constrainer.hpp>

Public Member Functions | |
| DistanceConstrainer (std::shared_ptr< Particle > anchor, std::shared_ptr< Particle > particle) | |
| Construct with automatic interval set to initial distance. | |
| DistanceConstrainer (std::shared_ptr< Particle > anchor, std::shared_ptr< Particle > particle, const Interval< Meter > &interval) | |
| Construct with a custom distance interval. | |
| void | Correct () const |
| Correct velocity to satisfy the distance constraint (Velocity Constrain) | |
Private Member Functions | |
| void | IntervalCheck () const |
| Validate that the interval minimum is non-negative. | |
Private Attributes | |
| std::shared_ptr< Particle > | anchor_ |
| std::shared_ptr< Particle > | particle_ |
| Interval< Meter > | interval_ |
Constrains a particle's distance from an anchor within an interval.
DistanceConstrainer ensures that a particle stays within a specified distance range [min, max] from an anchor point. If the particle moves outside this range, it is corrected back to the nearest bound.
The correction is applied to both position and velocity to maintain consistency with the time integration scheme.
Example: auto anchor = std::make_shared<Particle>(1_kg, Vector3{0_m, 0_m, 0_m}); auto particle = std::make_shared<Particle>(1_kg, Vector3{1_m, 0_m, 0_m});
// Keep distance between 0.5m and 1.5m Interval<Meter> range(0.5_m, 1.5_m); DistanceConstrainer constraint(anchor, particle, range);
// In simulation loop: constraint.Correct();
Definition at line 34 of file Constrainer.hpp.
|
inline |
Construct with automatic interval set to initial distance.
The interval's min and max are both set to the initial distance, effectively fixing the distance to a constant value (rigid constraint).
| anchor | The fixed reference point |
| particle | The particle to constrain |
Definition at line 45 of file Constrainer.hpp.
|
inline |
Construct with a custom distance interval.
| anchor | The fixed reference point |
| particle | The particle to constrain |
| interval | The allowed distance range [min, max] (meters) |
| std::invalid_argument | If interval.min < 0 |
Definition at line 60 of file Constrainer.hpp.
|
inline |
Correct velocity to satisfy the distance constraint (Velocity Constrain)
If the current distance is outside [min, max], the particle is moved to the nearest bound. Velocity is adjusted to compensate for the position change over the current time step.
The velocity correction is: v_new = v_old - (position_error) / dt
This ensures that the constraint is satisfied after integration.
Definition at line 78 of file Constrainer.hpp.
|
inlineprivate |
Validate that the interval minimum is non-negative.
| std::invalid_argument | If interval.min < 0 (negative distance is physically meaningless) |
Definition at line 103 of file Constrainer.hpp.
|
private |
Definition at line 93 of file Constrainer.hpp.
Definition at line 96 of file Constrainer.hpp.
|
private |
Definition at line 94 of file Constrainer.hpp.