Apologies as this is my first time posting here.

I am trying to simulate Electric Fields and lines of force using pygame to find no flow boundaries. I wrote some crude code and was able to come up with these figures.

Equal charges, no line

As we can see, in this case of two FIXED equal negative charges, the no flow boundary lies on the perpendicular bisector of the line joining the two charges. Equal charges with line

What I mean by a no flow boundary, if I put a charge on the line, it moves toward no charge. It will stay and move on the line itself. There exists no flow across the line. Any charge to the left of the line will move towards the left charge and right will move towards the right.

In the case of an unequal negative charges, (I increased the lengths of the field lines), surprisingly, or unsurprisingly, we can maybe figure out that the no flow boundary is not a straight line. Unqeual charges, no line

It makes sense cuz the force exerted by the smaller charge will be lower than that of the greater charge at the midpoint, and hence it has to be closer to it to make charges equal. And hence, if we draw the No Flow Boundary on this one, it might look like this.Unequal Charges with line

My question is, how can one figure out where the no flow boundary is; using some vector operation? Is there a way that doesn't rely on looking at field line and then figuring it out? How can I go about "coding" an approximate for the no flow boundary? Is it possible? I feel like it is, cuz we can clearly see it if we plot the lines. Can that feeling be quantified in some way?

I was thinking maybe Divergence, but that just gives me the flow in an infinitesimal area. We know that in the case of the equal charges, the charge might move on the line itself, but never across, so, there will be a non zero divergence on the line.

Any help would greatly be appreciated.


  • $\begingroup$ If the Lorentz force law gives a null vector the charge is not moving anywhere (assuming it is tiny enough to not affect the fields) except maybe in a constant velocity direction I guess (not sure) if you disregard all other force types. $\endgroup$
    – Emil
    Mar 11, 2023 at 6:25
  • $\begingroup$ This makes me wonder if your red line is correct. How do you infer the magnitude of the vector field from your images ? Or perhaps you are just looking for the flow line/streamline? Do you mean any old streamline as long as the distance to all charges is monotonically increasing? $\endgroup$
    – Emil
    Mar 11, 2023 at 6:34
  • $\begingroup$ Or perhaps you are after the boundaries for asymptotic stability? $\endgroup$
    – Emil
    Mar 11, 2023 at 6:44
  • $\begingroup$ The way I was looking at the red line is to just demarcate the regions where the charge will go to. If I put it on the left, it'll go to the left charge and if on the right, it'll go towards the right charge. If that counts as asymptotic stability line, then yes, I am looking for how to develop that, given an arbitrary configuration of charges. $\endgroup$
    – Chandra
    Mar 11, 2023 at 6:48
  • $\begingroup$ I don't know the best way to find them. I kind of recognize it from chaos theory/phase portraits for ODEs/control theory. It feels like at least one of Lyapunov stability or Greens method or eigenvalues or path functionals or method of characteristics is kind of related. $\endgroup$
    – Emil
    Mar 11, 2023 at 7:04

2 Answers 2



I was able to solve this problem by using a brute force algorithm. I know that is not the most ideal solution. I was looking for a cleverer approach. I see the one @kricheli posted. It will take some time for me to try to implement it in my code.

Basically, all I did was, using the force due to the electric field, I marched each and every point on a charge. I, then stored the "name" of the charge and I have it assigned to a 2 dimensional array.

Now all I have to do is see where the 2d array changes from one region to another. I was able to make some algorithms, although I am pretty sure that better ones exist out there, but there is nothing more satisfying than coding something on your own from scratch.

For example, I have a case where the charges are -1 and -3.

The red area is where any charge would go to particle 1, and the yellow area is where it would go to particle 2.

Colour Areas

Now that I have a 2d array of either 1 or 2, I just need to find where the 1 changes to a 2.

Doing that would lead me to this.

Just Boundaries

It is a solution but definitely not the cleanest.

Then again, I am super happy to see solutions like this come up with some bunch of code I've written.

The red charges are positive charges and the blue ones are negative.

Random Case

Random Case 2

One of my favourite cases is where you can almost generate 2 parallel lines. I say almost because you'll be needing infinite charges to get 2 exactly parallel lines.

Not so random case

Now, why am I doing this? It honestly is just a passion project. I've always wanted to code electric charges, field lines and no flow boundaries. I do have something that I want to do with the no flow boundaries in specific.

Once again, thank you everyone for the help and inspiration.



What you are looking for, I think, are lines to which the electric field is tangential, something like a curve $\vec{c}:I \mapsto \mathbb{R}^3$ on some interval $I$ such that $$ \frac{\text{d}}{\text{d}s}\vec{c} = a \vec{E} $$ with some constant $a$. Beware that this is not the line a charge would be moving on because in the equation of motion for the charge the Lorentz force created by the electric field would be proportional to the charge's acceleration, not its velocity as in the above.

Nevertheless, if you go with the equation above, you can easily solve this first-order equation from any starting point, which you can also implement numerically. From most starting points you can go in at least one direction along this curve until you end up in one of the charges - unless you are on the red line you are looking for.

Thus: For a given starting point solve the above ode, measure the distance $d$ along the curve to one of the charges. Vary the starting point from which you solve (for example along the line connecting the two charges), and where $d$ diverges you have found what you are looking for.

  • $\begingroup$ I'll be honest. I don't see why there would be a lorentz force. Is the magnetic field from the moving charge? If yes, that is very interesting. $\endgroup$
    – Chandra
    Mar 13, 2023 at 7:53
  • $\begingroup$ en.wikipedia.org/wiki/Lorentz_force The Lorentz force has a contribution from the electric field - which is what I meant - and a contribution from a magnetic field, which is zero here. $\endgroup$
    – kricheli
    Mar 13, 2023 at 8:28
  • $\begingroup$ I see. Thank you so much. $\endgroup$
    – Chandra
    Mar 13, 2023 at 11:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.