Closed veillette closed 9 years ago
Happens in 1.0.0-dev.3 HTML
Here is a workaround to address this issue. Since it is a very special case,that relies on a very symmetric charge configuration AND a starting point that lies on a symmetric line, it is not worth investing a lot of time in finding a better algorithm (such as marching squares) to generate an equipotential line.
It is relatively easy to find out if a line terminates on the play ground without closing on itself.
I propose this
this.getEquipotentialPositionArray: function(position)
blah blah
if ( !this.isLineClosed && this.isEquipotentialLineTerminatingInsideBounds ) {
console.log( 'an electricPotential line terminates on the screen' );
// see https://github.com/phetsims/charges-and-fields/issues/1
// this is very difficult to come up with such a scenario. so far this
// was encountered only with a pure quadrupole configuration.
// let's redo the entire process but starting a tad to the right so we don't get stuck in our search
var weeVector = new Vector2( 0.00031415, 0.00027178 );
return this.getEquipotentialPositionArray( position.plus( weeVector ) );
return positionArray
Essentially, it is a recursive function that calls itself if it fails to find a closed loop. The difference is that the initial point is slightly to the right of the initial position. In this way the starting point will no longer be on the symmetric axis and will be able to generate a position array.
The idea is that the weeVector is so small it will be an imperceptible offset that will not be noticed by the user.
No issues came up while testing. Closing
The current algorithm to generate equipotential doesn't deal well with electric quadrupole