MdHarmonicSpring

SimulationBuilder > Shared > ParticleBuildingBlocks?

Harmonic springs are one type of spring that may be used to join MdBeads in Glotzilla simulations.

Synopsis

class SixtyFourBeadPolymer : public MdPolymer
{
        public:
                SixtyFourBeadPolymer()
                {
                        //declare a vector to save all beads (for connecting them later
                        std::vector <MdBead *> bead;
                        
                        //make beads in a loop
                        for(int i=0; i<4; i++)
                                for(int j=0; j<4; j++)
                                        for(int k=0; k<4; k++)
                                        {
                                                MdBead *b = new MdBead;
                                                b -> SetPosition(i, j, k);
                                                AddBead(b);
                                                bead.push_back(b);
                                        }
                        
                        //connect the beads using harmonic springs
                        for(int i=0; i< bead.size() -1; i++)
                        {
                                MdHarmonicSpring *s = new MdHarmonicSpring;
                                s -> Connect(bead[i], bead[i+1]);
                                AddSpring(s);
                        }
                }
};

Harmonic Spring, MATDL wiki