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::AngleConstrainer Class Reference

Constrains a particle's angular position around an anchor. More...

#include <Constrainer.hpp>

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

Public Member Functions

 AngleConstrainer (std::shared_ptr< Particle > anchor, std::shared_ptr< Particle > particle)
 Construct with automatic intervals set to initial angles.
 
 AngleConstrainer (std::shared_ptr< Particle > anchor, std::shared_ptr< Particle > particle, const Interval< Radian > &theta_interval)
 Construct with custom theta interval, phi fixed to initial value.
 
 AngleConstrainer (std::shared_ptr< Particle > anchor, std::shared_ptr< Particle > particle, const Interval< Radian > &theta_interval, const Interval< Radian > &phi_interval)
 Construct with custom theta and phi intervals.
 
void Correct (const Quantity< Second > dt) const
 Correct velocity to satisfy angular constraints (Velocity Constrain)
 

Private Member Functions

void IntervalCheck () const
 Validate that angle intervals are within [-2pi, 2pi].
 

Private Attributes

std::shared_ptr< Particle > anchor_
 
std::shared_ptr< Particle > particle_
 
Interval< Radian > theta_interval_
 
Interval< Radian > phi_interval_
 

Detailed Description

Constrains a particle's angular position around an anchor.

AngleConstrainer restricts the polar angle (theta) and azimuthal angle (phi) of a particle relative to an anchor point. Both angles are constrained within user-specified intervals.

Angles are wrapped to [-2pi, 2pi] before validation, so intervals should be specified in this range.

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});

// Restrict theta to [30deg, 60deg], phi to [-45deg, 45deg] Interval<Radian> theta_range(30.0_deg, 60.0_deg); Interval<Radian> phi_range(-45.0_deg, 45.0_deg); AngleConstrainer constraint(anchor, particle, theta_range, phi_range);

// In simulation loop: constraint.Correct(dt);

Note: Theta is the polar angle from the Z axis (0 to pi in standard spherical coordinates). Phi is the azimuthal angle from the X axis.

Definition at line 135 of file Constrainer.hpp.

Constructor & Destructor Documentation

◆ AngleConstrainer() [1/3]

Phyth::Mechanics::AngleConstrainer::AngleConstrainer ( std::shared_ptr< Particle >  anchor,
std::shared_ptr< Particle >  particle 
)
inline

Construct with automatic intervals set to initial angles.

Both theta and phi intervals are fixed to the particle's initial angles.

Parameters
anchorThe fixed reference point
particleThe particle to constrain

Definition at line 145 of file Constrainer.hpp.

◆ AngleConstrainer() [2/3]

Phyth::Mechanics::AngleConstrainer::AngleConstrainer ( std::shared_ptr< Particle >  anchor,
std::shared_ptr< Particle >  particle,
const Interval< Radian > &  theta_interval 
)
inline

Construct with custom theta interval, phi fixed to initial value.

Parameters
anchorThe fixed reference point
particleThe particle to constrain
theta_intervalAllowed range for polar angle (radians)
Exceptions
std::invalid_argumentIf interval bounds exceed [-2pi, 2pi]

Definition at line 161 of file Constrainer.hpp.

◆ AngleConstrainer() [3/3]

Phyth::Mechanics::AngleConstrainer::AngleConstrainer ( std::shared_ptr< Particle >  anchor,
std::shared_ptr< Particle >  particle,
const Interval< Radian > &  theta_interval,
const Interval< Radian > &  phi_interval 
)
inline

Construct with custom theta and phi intervals.

Parameters
anchorThe fixed reference point
particleThe particle to constrain
theta_intervalAllowed range for polar angle (radians)
phi_intervalAllowed range for azimuthal angle (radians)
Exceptions
std::invalid_argumentIf interval bounds exceed [-2pi, 2pi]

Definition at line 178 of file Constrainer.hpp.

Member Function Documentation

◆ Correct()

void Phyth::Mechanics::AngleConstrainer::Correct ( const Quantity< Second >  dt) const
inline

Correct velocity to satisfy angular constraints (Velocity Constrain)

The particle's position is adjusted to the nearest valid angle if it falls outside the specified intervals. Both theta and phi are wrapped to [-2pi, 2pi] before validation.

The correction uses the particle's current distance from the anchor (preserved during angular correction) and adjusts velocity accordingly.

Parameters
dtTime step used for velocity correction

If the particle is exactly at the anchor (length == 0), no correction is applied.

Definition at line 199 of file Constrainer.hpp.

◆ IntervalCheck()

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

Validate that angle intervals are within [-2pi, 2pi].

Exceptions
std::invalid_argumentIf any interval bound exceeds [-2pi, 2pi]

Angles are wrapped to this range before validation, so intervals must be specified within this range.

Definition at line 258 of file Constrainer.hpp.

Member Data Documentation

◆ anchor_

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

Definition at line 244 of file Constrainer.hpp.

◆ particle_

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

Definition at line 245 of file Constrainer.hpp.

◆ phi_interval_

Interval<Radian> Phyth::Mechanics::AngleConstrainer::phi_interval_
private

Definition at line 248 of file Constrainer.hpp.

◆ theta_interval_

Interval<Radian> Phyth::Mechanics::AngleConstrainer::theta_interval_
private

Definition at line 247 of file Constrainer.hpp.


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