Example #1
0
        //public ParticleSpring makeOrUpdateSpring(int ID, Particle a, Particle b, double restLength, double springConstant, double damping)
        //{
        //    bool found = false;
        //    for (int i = 0; i < springs.Count(); ++i)
        //    {
        //        if (ID != null && (springs[i].ID() != null))
        //        {
        //            if (ID == springs[i].ID())
        //            {
        //                found = true;
        //                return springs[i];

        //            }
        //        }
        //    }
        //    if (found == false)
        //    {
        //        ParticleSpring s = new ParticleSpring(ID++, a, b, restLength, springConstant, damping);
        //        springs.Add(s);
        //        return s;
        //    }
        //    return null;
        //}

        public void applyForces()
        {
            maxResidualForce = -1000000000.0;
            maxNodalVelocity = -1000000000.0;

            for (int i = 0; i < particles.Count(); ++i)
            {
                //if (!isFaceConstrained)
                //{
                particles[i].addForce(gravity);
                //}

                particles[i].addForce(particles[i].getVelocity() * -drag);

                maxNodalVelocity = Math.Max(maxNodalVelocity, particles[i].getVelocity().GetLength());
            }

            //test whether we are converged according to the threshold criteria
            //make sure the simulation has a couple of steps computed so we don't
            //bail at time step 0 when the structure hasn't started moving yet.
            if (maxNodalVelocity < threshold && stepCount > 10)
            {
                converged = true;
            }

            //F=kd, calculate the maximum residual force in any member
            for (int i = 0; i < springs.Count(); i++)
            {
                ParticleSpring f = springs[i];
                f.apply();

                maxResidualForce = Math.Max(maxResidualForce, f.getResidualForce());
            }

            /*
             * if (isFaceConstrained && constraintFace != null)
             * {
             *  for (int i = 0; i < particles.Count(); ++i)
             *  {
             *      //get the component of force that is tangent
             *      //to the surface at the point
             *      IntersectionResult ir = constraintFace.Project(particles[i].getPosition());
             *      if (ir != null)
             *      {
             *          XYZ n = constraintFace.ComputeNormal(ir.UVPoint);
             *          n = n.Normalize();
             *          XYZ force = particles[i].getForce();
             *          //XYZ normalForce = new XYZ(force.X * n.X, force.Y * n.Y, force.Z * n.Z);
             *          double normalForce = force.DotProduct(n);
             *          //XYZ normalForce2 = new XYZ(normalForce.X * n.X, normalForce.Y * n.Y, normalForce.Z * n.Z);
             *          XYZ normalForce2 = normalForce * n;
             *          particles[i].clearForce();
             *          particles[i].addForce(force - normalForce2);
             *      }
             *  }
             * }
             */
        }