blob: 3ef94ffd490639339477e5b5f82253b880634e5c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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<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()
}
}
|