So I made this simulation of charged particles: https://github.com/TheDemx27/Charge-Simulator(adsbygoogle = window.adsbygoogle || []).push({});

My goal is to be able to put the charges on a line, as I've done, and see them tend toward a final state where there is more charge at the ends of the line and less towards the center. The problem is, the simulation runs like an elastically no matter what I try. At the moment, I've tried adding an acceleration in the opposing direction of motion, proportional to the velocity. This is the main loop for calculating the acceleration and setting the velocity:

This doesn't seem to do anything. If I make c large enough, the oscillations get bigger, the sim eventually spirals out of control, and I get null values for the positions.Code (Text):

for (int i = 0; i < charges.Count; i++) {

for (int j = i + 1; j < charges.Count; j++) {

distance = GetDistVec(charges[i], charges[j]);

f = charges[i].q * charges[j].q * k / (distance.Magnitude * distance.Magnitude);

acceleration1.Magnitude = Math.Abs(f / charges[i].m);

acceleration2.Magnitude = Math.Abs(f / charges[j].m);

acceleration1.Direction = distance.Direction;

acceleration2.Direction = distance.Direction += Math.PI;

// DAMPENING

double c = 10;

accel1 = PolarToComponent(acceleration1);

accel2 = PolarToComponent(acceleration2);

accel1.x -= c * charges[i].x;

accel1.y -= c * charges[i].y;

accel2.x -= c * charges[j].x;

accel2.y -= c * charges[j].y;

// DAMPENING

SetVelVec(charges[i], accel1);

SetVelVec(charges[j], accel2);

}

}

**Physics Forums | Science Articles, Homework Help, Discussion**

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# C/++/# How to Implement Damping in Particle Simulation

Have something to add?

Draft saved
Draft deleted

Loading...

Similar Threads for Implement Damping Particle |
---|

Fortran Moving Dashpot simulation |

C/++/# Velocity Verlet C++ implementation |

Implementing symmetry boundary condition for the diffusion equation |

**Physics Forums | Science Articles, Homework Help, Discussion**