static void Main(string[] args) { double len = 20; Vertex[] vs = new Vertex[] { new Vertex(0, true, new Point3d(0, 0, 0)), new Vertex(1, false, new Point3d(1 * len, 0, 0)), new Vertex(2, false, new Point3d(2 * len, 0, 0)), new Vertex(3, false, new Point3d(3 * len, 0, 0)), new Vertex(4, true, new Point3d(4 * len, 0, 0)), }; Spring[] sp = new Spring[] { new Spring(0, 1, len), new Spring(1, 2, len), new Spring(2, 3, len), new Spring(3, 4, len), }; //Vertex[] vs = new Vertex[] // { // new Vertex(0,true, new Point3d(0,0,0)), // new Vertex(1,false, new Point3d(2,0,0)), // new Vertex(2,true, new Point3d(4,0,0)), // }; //double len = 2; //Spring[] sp = new Spring[] // { // new Spring(0,1,len), // new Spring(1,2,len), // }; PhysicsGraph graph = new PhysicsGraph(vs, sp); for (int i = 0; i < 100; i++) { graph.EstimateForce(); graph.Update(); Console.WriteLine(graph); } }
private Tuple <Vertex[], Spring[]> FindAdjacents(int id) { var vertices = new List <Vertex>(); var springs = new List <Spring>(); foreach (var s in Springs) { if (s.IsConnected(id)) { Spring spring = s; int vertexId = s.GetOther(id); Vertex vertex = Vertices.Single(n => n.Id == vertexId); vertices.Add(vertex); springs.Add(s); } } return(new Tuple <Vertex[], Spring[]>(vertices.ToArray(), springs.ToArray())); }
public Damper(Spring spring, double dampingRatio) { interactionType = InteractionType.Damper; this.A = spring.A; this.B = spring.B; double reducedMass = (A.mass * B.mass / (A.mass + B.mass)).value; if (double.IsNaN(reducedMass)) { reducedMass = A.mass.value; } if (double.IsNaN(reducedMass)) { reducedMass = B.mass.value; } double dampingCoefficient = 2.0 * dampingRatio * Math.Sqrt((spring.SpringRate * reducedMass).value); this.dampingCoefficient = new Scalar(dampingCoefficient, DerivedUnits.Force / DerivedUnits.Velocity); }
/// <summary> /// Reclaims a spring, adding it to the object pool for recycling /// </summary> /// <param name="s">the spring to Reclaim</param> protected static void reclaimSpring(Spring s) { if (_spool.Count < objectPoolLimit) { _spool.Push(s); } }
/// <summary> /// Adds a spring to the simulation /// </summary> /// <param name="p1">the first Particle attached to the spring</param> /// <param name="p2">the second Particle attached to the spring</param> /// <param name="restLength">the rest length of the spring</param> /// <param name="tenstion">the tension of the spring</param> /// <param name="damping">the damping (friction) co-efficient of the spring</param> /// <returns>the added spring</returns> public Spring AddSpring(Particle p1, Particle p2, double restLength, double tension, double damping) { var edge = new Spring(p1, p2) { restLength = restLength, tension = tension, damping = damping }; p1.degree++; p2.degree++; Springs.Add(edge); return edge; }