phetsims / charges-and-fields

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

Sim crashes if you try to draw a line in a 0 V area #186

Open KatieWoe opened 4 years ago

KatieWoe commented 4 years ago

For https://github.com/phetsims/QA/issues/508. Likely not connected to Studio. Seems to be possible due to the Snap to Grid feature, which means that reproducing in published may not be possible, even if it occurs there. If you set up a situation where there are charges on the screen that perfectly cancel each other and create a 0 V area, and then try to draw an equipotential line there, the sim will crash. If you try to put sensor nodes there an arrow will appear when it shouldn't as well. Steps:

  1. Turn on the grid and snap to grid options
  2. Put a red charge on a thick line intersection
  3. Put a blue charge two thick line intersections away
  4. Two intersections down, put a blue and red charge to cancel them out
  5. Put the sensor/equipotential line drawer in the middle of these charges
  6. Try to draw a line

zerovoltcrash

KatieWoe commented 4 years ago

On published, I might have managed to recreate this situation, though it is hard to tell if the voltage is exactly zero. If it is, then in published it makes an odd line, but does not crash. inpublished

zepumph commented 4 years ago

Thanks for the report, this should be worked on next time the sim is in active dev.

veillette commented 3 years ago

With the snap to grid, it is much easier to come up with highly symmetric charge configurations as above. In addition, it is possible to locate the equipotential tool at very symmetric places. From a pedagogical point of view, this is highly desirable to generate the configurations. However, from a computational point of view, these points are often maximum, minimum or saddle points of the electric potential.

To draw the equipotential line, the current algorithm looks for a direction perpendicular to the electric field. If the electric field is zero, then the algorithm fails.

Without the snap to grid feature, it is difficult to create locations where the E field vanishes to zero and even if you do, it is virtually impossible to set the equipotential tool at that particular location (even a tiny E field of 10^-15 would be sufficient for the algorithm).

This bug is not related to Studio as @KatieWoe pointed out. The bug is in principle present in the published version of charges and fields but because the snap to grid doesn't exist it would be extremely difficult to reproduce.

In order to enable a snap to grid feature, a more robust method method to draw equipotential needs to be implemented.