I'm trying to simulate particle attraction and motion.

Given two particles with 0 velocity at distance X, the acceleration due to attraction is such that the sum of acceleration must be equal to the sum of the deceleration over the same time after the particles pass causing the velocity to return to 0 at the precise distance X.

At t1 particle velocity is 0. Particles attract towards each other increasing in velocity until they pass and begin to decelerate.
The problem is at some distance before they pass (at t2) they will have sufficient velocity to pass each other on the next iteration (t3). At t3 the distance will not be the same as t2 causing the deceleration to be different.

Anyone have a clue how to calculate the correct acceleration?

It might be useful to post your code that you have so far so that we can sugguest modifications.

Well it's not really a code issue. It's a theoretical computational issue.

The classical approach using Newtons approximation only works for orbits and breaks for this case.

It's almost the Tangent function reflected about the point of intersection.

My test code is too large to post here but if anyone is interested it is based on the NBody simulation from the DX11 SDK.
Reduce the number of particles to 2.
Change the mass and spread to 1 and eliminate G.
Adjust the time and distance calcs to observe the near point acceleration (the upward ramp of the tangent curve).

my time is 0.0000001 and I multiply the distance calc by 0.00001

I'm sure this has been worked out before. I just don't have the math background.

BTW, this is just an old programmers curiosity. Nothing important ;-)

Hmmm, It turns out that x (directed distance from center) is sine.
Velocity and acceleration seem to be related functions but I have no clue what they are.
See attachment for a graph of the functions.

Green = velocity
Purple = Acceleration

The other two are ...

Acceleration = -sin(t)/(sin(t)^2)
Velocity = cos(t)/sqrt(sin(t)^2)

Now to figure out how to apply these.

The other two are ...

Acceleration = -sin(t)/(sin(t)^2)
Velocity = cos(t)/sqrt(sin(t)^2)

Now to figure out how to apply these.

I'm a little confused here but if

a(t) = -sin(t)/(sin(t)^2) which can be reduced to a(t) = -1/sin(t) which also equals a(t) = -csc(t)
wouldn't v(t) be equal to:
v(t) = indefinite integral of -1/sin(t) dt?
Which is v(t) = ln(cot(t) + csc(t)) + c. Where C is some constant? T also should have some domain restrictions I think... its been awhile.

Assuming these functions are for the same particle and the function for acceleration is correct.

commented: Thanks +2

The problem is at some distance before they pass (at t2) they will have sufficient velocity to pass each other on the next iteration (t3). At t3 the distance will not be the same as t2 causing the deceleration to be different.

You may not care what the velocity is. The fact that the particles have not actually reached that mid point, is what counts. That should be the correct t2.

Note that I am NOT a physics guy, however. Seems like common sense.

@Annuate: Yeah I thought it might be csc but it didn't graph right. It could have just been scale and rounding though. My math is so rusty I didn't even think to reduce that!

@Adak: It's just that at near t2 the force is so great the next iteration the partical flies off out of range and can't decelerate. So you end up with random noise instead of a smooth cycling system.

I found the problem!
The force equation
f = 1/r2*d
resolves to 1/(sqrt(dx^2)^3) for x which goes to infinity and breaks. To get around that I added 1 to the denominator which gave me a good sin-like x but still threw the acceleration and velocity off giving the asymptotic forms.

Using 1/dt instead of 1 solved the problem resulting in the expected equations

f = (1/dt)/(sqrt(dx^2)^3+1/dt)

x(t) = sin(t)
v(t) = cos(t)
a(t) = -sin(t)

Thanks Annuate for pointing me in the right direction!

PS: I'll leave this unsolved as I still need to figure out how to apply the equations to the problem at hand.

Well 1/dt was close but not correct.

Changing dt threw it out so it must be some constant.
Closest I've come is

1000
------------
|d|^3 + 1995

which tracks for dt = 0.1 to 0.000001

I don't know what this is or what it's even related too. The magnitude as well as the ratio effects the tracking.

It looks like the number doesn't matter as long as it's some ridiculously large constant sufficient to prevent asymptotic acceleration.

C = 1/~0

0.5
---------- * C
|d|^3 + C

Hey SVR if you still are reading here where did you come up with force = 1/r2*d?
If I remember correctly: Sum of the forces = mass * acceleration.
If we are dealing with radial acceleration we can substitute acceleration for: velocity squared / radius. If we don't know the velocity we can substituent it for: 2pi * radius / Time. Those are pretty much the 3 basic equations from introductory physics for force. If we go back to your chart you posted, the acceleration looks like a function of secant (1/cos(x)). Also as per your last post as C becomes increasingly large; As the bottom becomes larger the whole equation becomes smaller. As c approaches infinity: limit as x->infinity 1/x = 0

Hi Annuate,
Sry was off on other things.

1/r^2 comes from G*(M1*M2)/r^2 (Newtons Gravity). Then multiplied by the normalized direction vector to get directed force.

I was pretty sloppy writing that so it's hard to tell what I meant.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.