/// <summary> /// Gets the force. /// </summary> /// <param name="s">The s.</param> public override void GetForce(Spring s) { ForceItem item1 = s.Item1; ForceItem item2 = s.Item2; float length = (s.Length < 0 ? parms[SpringLength] : s.Length); float x1 = item1.Location[0], y1 = item1.Location[1]; float x2 = item2.Location[0], y2 = item2.Location[1]; float dx = x2 - x1, dy = y2 - y1; float r = (float)Math.Sqrt(dx * dx + dy * dy); if (r == 0.0) { dx = ((float)rnd.NextDouble() - 0.5f) / 50.0f; dy = ((float)rnd.NextDouble() - 0.5f) / 50.0f; r = (float)Math.Sqrt(dx * dx + dy * dy); } float d = r - length; float coeff = (s.Coeff < 0 ? parms[SpringCoeff] : s.Coeff) * d / r; item1.Force[0] += coeff * dx; item1.Force[1] += coeff * dy; item2.Force[0] += -coeff * dx; item2.Force[1] += -coeff * dy; }
/// <summary> /// Updates the force calculation on the given Spring. The ForceItems /// attached to Spring will have their force values updated appropriately. /// </summary> /// <param name="spring">spring the Spring on which to compute updated forces</param> public virtual void GetForce(Spring spring) { throw new NotImplementedException("This class does not support this operation"); }
/// <summary> /// Reclaim a Spring into the object pool. /// </summary> public void reclaim(Spring s) { s.Item1 = null; s.Item2 = null; if (springs.Count < Capacity) springs.Add(s); }