3
$\begingroup$

I would like to move around two points that are projecting lines. As they get closer to eachother the lines bend further and further from each other. I can't seem to find the math that makes this believable. Something to do with distance, but I'm not certain yet.

Ideally it will look like this

http://www.physics4kids.com/files/art/elec_magfield2_240x180.gif

And update when either charge is moved around.

$\endgroup$

1 Answer 1

6
$\begingroup$

enter image description here

I'm no expert in geo-nodes, but I got something working. I wonder if there's a method to this of which is absent of manual looping. That'd be much faster and easier. However, I couldn't find a way around it.

We'll begin with some math explanations. Suppose the two positive point charges are located at $P_1$ on the left and $P_2$ on the right. Suppose some test charge is located at $P$.

Two positive charges as in your diagram produce a vector field. We can think of this field as existing on $\mathbb{R}^2 \setminus \{P_1, P_2\}$. This field doesn't exist at $P_1$ and $P_2$ because of division by zero at these points.

So, if you pick any point $P$ of $\mathbb{R}^2 \setminus \{P_1, P_2\}$ and plug it into the function:

$$F(P) = \dfrac{kq_1(\vec{P} - \vec{P_1})}{||\vec{P} - \vec{P_1}||^3} + \dfrac{kq_2(\vec{P} - \vec{P_2})}{||\vec{P} - \vec{P_2}||^3}$$

you obtain the field vector at that point. $k$ is a physics constant and $q_1$ and $q_2$ are the respective charges of $P_1$ and $P_2$. Opposite charges attract and same charges repel. Watch here for more explanation of the vector field function: https://www.youtube.com/watch?v=47moTe6FVkY&ab_channel=CraigWLooney

Now to obtain the vector field lines, we treat these field vectors as the tangent vectors of the vector field lines. Thus, you pick a point $P_1$ or $P_2$ and then nudge it radially outwards. At this new point, you get the normalized field vector at that point, then nudge outwards in this new direction to obtain the next point and so forth... Wikipidea explains this concept here under "Construction": https://en.wikipedia.org/wiki/Field_line

Now, for the geo nodes...

I first instanced two vertices at each vertex of a primitive mesh circle. enter image description here

I feed the instances into this separator. One circle has even indices and the other has odd indices at this point, so you can separate them with mod 2. enter image description here

There are multiple cases of what happens next.

Case 0: I set one circle of points to either $P_1$ or $P_2$.

Case 1: I set the other circle to a small circle around either $P_1$ or $P_2$.

Case 2: Set the next ring of points and feed in the the small ring of point in for dot product comaparison into the vector vield function.

Case Else: This is where the logic got repetitive for me, so I made a node group of this separation, duplication, repositioning process.

Each of these node groups contain 20 iterations of this sep, dup, pos process. Thus, these three node groups append 60 layers. enter image description here

Here they are if you open up one of them (this is what I mean by manual looping. I couldn't really find a way around it ): enter image description here

Here's what a sep, dup, pos node group looks like: enter image description here

In it is the vector field function, which is also a node group. This function is $F(P)$. You can think of the field vector output for some ring $i$ is used to offset the verts of ring $i + 1$ for $i \neq 0$ where $i$ iterates through circles going outwards.

enter image description here

Here I compare the current field tangent vector to the previous field tangent vector via dot product. If this dot product is less than zero, that tells us that it's too sharp of a turn, so I set the current tangent to zero when this happens, thus the offset vector is the zero vector. (Unplug the greater than output value output from the multiply input and observe the points to thee sporadic patterns)

enter image description here

Some final words: I used separate versions of the node groups per circle. So, if you want to play with attribute such as the charges $q_1$ and $q_2$, make sure you alter both node groups. I also originally wanted to use curves instead of points for this answer, but I couldn't figure out a way to use curves.

$\endgroup$
2
  • 1
    $\begingroup$ ...Crazy. Nice. :-) $\endgroup$
    – quellenform
    Commented Mar 30, 2023 at 22:13
  • 1
    $\begingroup$ Great freaking work my guy. Loops cannot come soon enough. $\endgroup$
    – TheJeran
    Commented Mar 31, 2023 at 7:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .