diff options
author | eug-vs <eugene@eug-vs.xyz> | 2024-12-17 17:16:12 +0100 |
---|---|---|
committer | eug-vs <eugene@eug-vs.xyz> | 2024-12-17 17:16:49 +0100 |
commit | cc162a42127077744705dc6194de302bff069171 (patch) | |
tree | 0f225e7694a2de8088304703532651f7fb4bef0d /physics/src/constraint/anchor.rs | |
parent | 9a19677c53dd8d3735027d03c6bc923b3fd9c3e6 (diff) | |
download | particle-physics-cc162a42127077744705dc6194de302bff069171.tar.gz |
refactor: generalize anchor constraint via beam
Diffstat (limited to 'physics/src/constraint/anchor.rs')
-rw-r--r-- | physics/src/constraint/anchor.rs | 43 |
1 files changed, 0 insertions, 43 deletions
diff --git a/physics/src/constraint/anchor.rs b/physics/src/constraint/anchor.rs deleted file mode 100644 index c90cfb2..0000000 --- a/physics/src/constraint/anchor.rs +++ /dev/null @@ -1,43 +0,0 @@ -use nalgebra::{DVector, RowDVector}; - -use crate::particle_system::ParticleSystem; -use crate::algebra::{Point, Scalar, N}; - -use super::Constraint; - -pub struct AnchorConstraint { - pub particle_id: usize, - pub anchor: Point, - - jacobian: RowDVector<Scalar>, -} - -impl ParticleSystem { - pub fn add_anchor_constraint(&mut self, particle_id: usize) { - let anchor = self.particles[particle_id].position; - self.constraints.push(Box::new(AnchorConstraint { - particle_id, - anchor, - jacobian: RowDVector::zeros(self.particles.len() * N), - })); - } -} - -impl Constraint for AnchorConstraint { - fn get_particles(&self) -> Vec<usize> { - vec![self.particle_id] - } - - fn c(&self, q: &DVector<Scalar>) -> Scalar { - let position = q.fixed_rows(self.particle_id * N); - (position - self.anchor.coords).norm() - } - - fn set_jacobian(&mut self, jacobian: RowDVector<Scalar>) { - self.jacobian = jacobian - } - - fn jacobian_prev(&self) -> RowDVector<Scalar> { - self.jacobian.clone() - } -} |