/// <summary> /// Calculates the attraction force between two connected nodes, using the specified spring length. /// </summary> /// <param name="a">The node that the force is acting on.</param> /// <param name="b">The node creating the force.</param> /// <param name="springLength">The length of the spring, in pixels.</param> /// <returns>A Vector representing the attraction force.</returns> private Vector3D CalcAttractionForce(double springLength, double attractionConstant) { if (StartNode == EndNode) { return(new Vector3D(0, 0, 0)); } var proximity = Math.Max(StartNode.GetDistanceToNode(EndNode), 0); //var proximity = CalcDistance(a, b); // Hooke's Law: F = -kx var force = attractionConstant * (proximity - springLength); //var force = ATTRACTION_CONSTANT * (proximity - springLength); //var angle = GetBearingAngle(a, b); //var angle = Math.Atan((b.Y - a.Y) / (b.X - a.X)); //return new Vector(force * Math.Cos(angle), force * Math.Sin(angle)); var vector = EndNode.Pos - StartNode.Pos; if (vector.Length > 0) { vector.Normalize(); } return(vector * force); }