Beispiel #1
0
        /// <summary>
        /// Processes the interaction of two bodies due to Newton's Laws of
        /// Universal Gravitation. Adjusts both bodies' velocities.
        /// </summary>
        /// <param name="otherObject">The other object to interact with.</param>
        private void ProcessGravitationalInteraction(DEEPGravitationalObject otherObject)
        {
            /* Calculate the gravitational force. */

            double m1 = this.mass;
            double m2 = otherObject.mass;

            DenseVector p1 = this.GetPosition();
            DenseVector p2 = otherObject.GetPosition();

            /* Calculate the Cartesian distance between the two points. */
            double r = (p2 - p1).L2Norm();

            double F = (G * m1 * m2) / 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     = p2 - p1;
            DenseVector un1    = n1 / n1.Norm(2d);
            DenseVector accel1 = a1 * un1;

            DenseVector n2     = p1 - p2;
            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;
        }
        /// <summary>
        /// Processes the interaction of two bodies due to Newton's Laws of 
        /// Universal Gravitation. Adjusts both bodies' velocities.
        /// </summary>
        /// <param name="otherObject">The other object to interact with.</param>
        private void ProcessGravitationalInteraction(DEEPGravitationalObject otherObject)
        {
            /* Calculate the gravitational force. */

            double m1 = this.mass;
            double m2 = otherObject.mass;

            DenseVector p1 = this.GetPosition();
            DenseVector p2 = otherObject.GetPosition();

            /* Calculate the Cartesian distance between the two points. */
            double r = (p2 - p1).L2Norm();

            double F = (G * m1 * m2) / 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 = p2 - p1;
            DenseVector un1 = n1 / n1.Norm(2d);
            DenseVector accel1 = a1 * un1;

            DenseVector n2 = p1 - p2;
            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;
        }