/// <summary> /// Handle the interaction of charged particles. /// </summary> /// <param name="dEEPGravitationalObject"></param> private void ProcessElectricalInteraction(DEEPElectricalObject otherObject) { /* Calculate the gravitational force. */ double m1 = this.mass; double m2 = otherObject.mass; double q1 = this.charge; double q2 = otherObject.charge; DenseVector p1 = this.GetPosition(); DenseVector p2 = otherObject.GetPosition(); /* Calculate the Cartesian distance between the two points. */ double r = (p2 - p1).L2Norm(); double F = (k_e * q1 * q2) / Math.Pow(r, 2d); /* Calculate the acceleration magnitude. */ double a1 = F / m1; double a2 = F / m2; /* Multiply by direction unit vectors in the respective directions. */ DenseVector n1 = p1 - p2; DenseVector un1 = n1 / n1.Norm(2d); DenseVector accel1 = a1 * un1; DenseVector n2 = p2 - p1; DenseVector un2 = n2 / n2.Norm(2d); DenseVector accel2 = a2 * un2; /* Apply the acceleration over one timestep to get the change in velocity. */ DenseVector deltaV1 = accel1 * internalRefreshRate; DenseVector deltaV2 = accel2 * internalRefreshRate; /* Apply the velocity change to the objects. */ this.velocity += deltaV1; otherObject.velocity += deltaV2; }