phetsims / charges-and-fields

"Charges And Fields" is an educational simulation in HTML5, by PhET Interactive Simulations.
GNU General Public License v3.0
8 stars 7 forks source link

Equipotential line fails near a charge #5

Closed veillette closed 9 years ago

veillette commented 9 years ago

image

veillette commented 9 years ago

The html5 version has the same issue because we use the same algorithm to get the equipotential line.

    /**
     * Given a (initial) position, find a position with the targeted electric potential within a distance deltaDistance
     * @private
     * @param {Vector2} position
     * @param {number} electricPotential
     * @param {number} deltaDistance - a distance in meters, can be positive or negative
     * @returns {Vector2} finalPosition
     */
    getNextPositionAlongEquipotentialWithElectricPotential: function( position, electricPotential, deltaDistance ) {
      /*
       General Idea: Given the electric field at point position, find an intermediate point that is 90 degrees
       to the left of the electric field (if deltaDistance is positive) or to the right (if deltaDistance is negative).
       A further correction is applied since this intermediate point will not have the same electric potential
       as the targeted electric potential. To find the final point, the electric potential offset between the targeted
       and the electric potential at the intermediate point is found. By knowing the electric field at the intermediate point
       the next point should be found (approximately) at a distance epsilon equal to (Delta V)/|E| of the intermediate point.
       */
      var initialElectricField = this.getElectricField( position ); // {Vector2}
      assert && assert( initialElectricField.magnitude() !== 0, 'the magnitude of the electric field is zero: initial Electric Field' );
      var equipotentialNormalizedVector = initialElectricField.normalize().rotate( Math.PI / 2 ); // {Vector2} normalized Vector along equipotential
      var midwayPosition = ( equipotentialNormalizedVector.multiplyScalar( deltaDistance ) ).add( position ); // {Vector2}
      var midwayElectricField = this.getElectricField( midwayPosition ); // {Vector2}
      assert && assert( midwayElectricField.magnitude() !== 0, 'the magnitude of the electric field is zero: midway Electric Field ' );
      var midwayElectricPotential = this.getElectricPotential( midwayPosition ); //  {number}
      var deltaElectricPotential = midwayElectricPotential - electricPotential; // {number}
      var deltaPosition = midwayElectricField.multiplyScalar( deltaElectricPotential / midwayElectricField.magnitudeSquared() ); // {Vector2}
      //var finalPosition = midwayPosition.add( deltaPosition );
      return midwayPosition.add( deltaPosition ); // finalPosition
    },

The deltaPosition, which is supposed to be a tiny correction ends up being huge.

veillette commented 9 years ago

A stop gap measure is to prevent equipotential line that are too close to the charges.

veillette commented 9 years ago

No ticket has ever been issued on this behavior in spite of the fact that the flash simulation has been around for quite sometime. It is a fair indication that this is not a high priority. In nay case, no algorithm will ever be capable of handling all the pathological cases.

In this case, it seems safe to return an empty array when the electric potential sensor is too close to a charged particle. The distance was chosen to be within a radius of the circle. The correct equipotential line would be within the radius of the charge and therefore invisible anyway (at least for a single particle charge)

veillette commented 9 years ago

Forgot to close. FIxed. closing