53 Spring(std::shared_ptr<Particle>
p1, std::shared_ptr<Particle>
p2,
117 return (
p1_->GetPosition() -
p2_->GetPosition()).Length();
179 std::shared_ptr<Particle>
p1_;
180 std::shared_ptr<Particle>
p2_;
187 if (
const auto len =
length.value; !std::isfinite(
len) ||
len <= 0.0) {
188 throw std::invalid_argument(
"Spring::validateRestLength: rest length must be a positive finite number");
194 throw std::invalid_argument(
"Spring::validateStiffness: stiffness must be non-negative");
200 throw std::invalid_argument(
"Spring::validateDamping: damping must be non-negative");
Spring constraint between two particles.
Quantity< Newton > GetEnergyDensity() const
Compute energy per unit length.
void Constrain() const
Apply spring and damping forces to both particles (Force Constrain)
const Quantity< Meter > & GetRestLength() const
Quantity< Meter > GetElongation() const
Quantity< KilogramPerSecond > damping_
Quantity< NewtonPerMeter > stiffness_
Spring(std::shared_ptr< Particle > p1, std::shared_ptr< Particle > p2, const Quantity< NewtonPerMeter > &stiffness, const Quantity< KilogramPerSecond > &damping=Quantity< KilogramPerSecond >{0})
Construct a spring between two particles.
const std::shared_ptr< Particle > & GetParticle1() const
void SetDamping(const Quantity< KilogramPerSecond > &damping)
Set a new damping coefficient.
Quantity< Joule > GetElasticEnergy() const
Compute the elastic potential energy stored in the spring.
Quantity< Meter > rest_length_
Quantity< Meter > GetCurrentLength() const
void SetRestLength(const Quantity< Meter > &rest_length)
Set a new rest length.
std::shared_ptr< Particle > p2_
const std::shared_ptr< Particle > & GetParticle2() const
static void validateDamping(const Quantity< KilogramPerSecond > &damping)
const Quantity< KilogramPerSecond > & GetDamping() const
const Quantity< NewtonPerMeter > & GetStiffness() const
void SetStiffness(const Quantity< NewtonPerMeter > &stiffness)
Set a new stiffness.
static void validateRestLength(const Quantity< Meter > &length)
static void validateStiffness(const Quantity< NewtonPerMeter > &stiffness)
std::shared_ptr< Particle > p1_
Compile-time physical dimension as 7 SI base exponents.
Physical quantity with a value and a compile-time unit.
3D vector with Quantity components
Vector3< Scalar > Normalized() const
Normalized vector (unit vector in the same direction)