1 #include "simple-spacer.hh"
2 #include "idealspacing.hh"
7 Spring_info::set(Idealspacing *i)
9 space_f_ = i->space_f_;
10 hooke_f_ = i->hooke_f_;
13 Spring_info::Spring_info()
17 blocking_stretch_f_ = infinity_f;
24 Simple_spring_spacer::init ()
26 for (PCursor<Rod_info*> i(rods_.top()); i.ok (); i++)
29 Real dist= i->distance_f_;
33 for (int j = i->cols_[LEFT]; j < i->cols_[RIGHT]; j++)
35 hooke += 1/springs_[j].hooke_f_;
36 dist -= springs_[j].space_f_;
41 for (int j = i->cols_[LEFT]; j < i->cols_[RIGHT]; j++)
43 Real block_stretch = hooke * dist / (springs_[j].space_f_ *
44 springs_[j].hooke_f_ );
46 if (block_stretch < springs_[j].blocking_stretch_f_)
48 springs_[j].blocking_stretch_f_ = block_stretch;
49 springs_[j].blocking_rod_l_ = i.ptr ();
56 Simple_spring_spacer::solve ()
58 Real start_force = 0.0;
60 for (int i=0; i< springs_.size (); i++)
62 start_force = start_force >?
63 springs_[i].blocking_stretch_f_ * springs_[i].hooke_f_;
66 Array<Real> stretch_factors;
69 Real current_len =0.0;
70 for (int i=0; i < springs_.size (); i++)
72 Real stretch = start_force / (springs_[i].hooke_f_ * springs_[i].space_f_);
73 stretch_factors.push (stretch);
74 current_len += (1 + stretch) * springs_[i].space_f_;
79 while (blocked_count < blocked.size ())
81 Real next_stretch = -1.0;
83 for (int i=0; i< stretch_factors.size (); i++)
87 next_stretch = next_stretch >? springs_[i].blocking_stretch_f_;
89 if (next_stretch < springs_[i].blocking_stretch_f_)
91 next_stretch = springs_[i].blocking_stretch_f_;
98 Real force = next_stretch * (springs_[block_index].space_f_* springs_[block_index].hooke_f_);
99 for (int i=0; i< stretch_factors.size (); i++)
103 stretch_factors[i] = force / (springs_[i].space_f_ * springs_[i].hooke_f_);
105 current_len += (1.0 + stretch_factors[i]) * springs_[i].space_f_;
108 Rod_info *blockrod = springs_[block_index].blocking_rod_l_;
109 for (int j = blockrod->cols_ [LEFT]; j < blockrod->cols_ [RIGHT]; j++)
117 Array<Real> distances;
118 for (int i=0; i < stretch_factors.size (); i++)
120 distances.push (stretch_factors[i] * springs_[i].space_f_);