Phyth v0.1.0
A dimensional safe C++ header-only mechanics and electromagnetics simulation library.
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | List of all members
Phyth::Mechanics::DistanceConstrainer Class Reference

Constrains a particle's distance from an anchor within an interval. More...

#include <Constrainer.hpp>

Collaboration diagram for Phyth::Mechanics::DistanceConstrainer:
Collaboration graph
[legend]

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_
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ DistanceConstrainer() [1/2]

Phyth::Mechanics::DistanceConstrainer::DistanceConstrainer ( std::shared_ptr< Particle >  anchor,
std::shared_ptr< Particle >  particle 
)
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).

Parameters
anchorThe fixed reference point
particleThe particle to constrain

Definition at line 45 of file Constrainer.hpp.

◆ DistanceConstrainer() [2/2]

Phyth::Mechanics::DistanceConstrainer::DistanceConstrainer ( std::shared_ptr< Particle >  anchor,
std::shared_ptr< Particle >  particle,
const Interval< Meter > &  interval 
)
inline

Construct with a custom distance interval.

Parameters
anchorThe fixed reference point
particleThe particle to constrain
intervalThe allowed distance range [min, max] (meters)
Exceptions
std::invalid_argumentIf interval.min < 0

Definition at line 60 of file Constrainer.hpp.

Member Function Documentation

◆ Correct()

void Phyth::Mechanics::DistanceConstrainer::Correct ( ) const
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.

◆ IntervalCheck()

void Phyth::Mechanics::DistanceConstrainer::IntervalCheck ( ) const
inlineprivate

Validate that the interval minimum is non-negative.

Exceptions
std::invalid_argumentIf interval.min < 0 (negative distance is physically meaningless)

Definition at line 103 of file Constrainer.hpp.

Member Data Documentation

◆ anchor_

std::shared_ptr<Particle> Phyth::Mechanics::DistanceConstrainer::anchor_
private

Definition at line 93 of file Constrainer.hpp.

◆ interval_

Interval<Meter> Phyth::Mechanics::DistanceConstrainer::interval_
private

Definition at line 96 of file Constrainer.hpp.

◆ particle_

std::shared_ptr<Particle> Phyth::Mechanics::DistanceConstrainer::particle_
private

Definition at line 94 of file Constrainer.hpp.


The documentation for this class was generated from the following file: