From 783070635b568b44b6902bfdc01bdadf12b86bc8 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Thu, 12 Dec 2024 15:23:01 +0100 Subject: feat: implement constraint system and PPM rendering --- src/constraint/anchor.rs | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/constraint/anchor.rs (limited to 'src/constraint/anchor.rs') diff --git a/src/constraint/anchor.rs b/src/constraint/anchor.rs new file mode 100644 index 0000000..3ef94ff --- /dev/null +++ b/src/constraint/anchor.rs @@ -0,0 +1,42 @@ +use nalgebra::{DVector, RowDVector}; + +use crate::particle_system::{ParticleSystem, Point, Scalar, N}; + +use super::Constraint; + +pub struct AnchorConstraint { + pub particle_id: usize, + pub anchor: Point, + + jacobian: RowDVector, +} + +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 { + vec![self.particle_id] + } + + fn c(&self, q: &DVector) -> Scalar { + let position = q.fixed_rows(self.particle_id * N); + (position - self.anchor.coords).norm() + } + + fn set_jacobian(&mut self, jacobian: RowDVector) { + self.jacobian = jacobian + } + + fn jacobian_prev(&self) -> RowDVector { + self.jacobian.clone() + } +} -- cgit v1.2.3