This topic is 4741 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello all, My good friend and I are in the process of creating a particle system. And we both thought it would be nice to have a Radial force field effect - Where each particle is attracted to the origin (0,0,0). I was thinking, we would could achieve this by only using the current position of the particle. And where the strength of the force is proportional to the distance from the origin. Our abstrast Force field interface has worked well so far. Well, so far here is my attempt, alas it fails. Does anyone here have the "know-how" to answer my post? As always, thanks in advance.
class ForceField
{
public:
virtual vector3f GetAcceleration(vector3f position, float mass, float t) const = 0;
};

{
public:
{
magnitude = _magnitude;
}

virtual vector3f GetAcceleration(vector3f position /* of particle */, float mass /* of particle */, float time) const
{
///// TODO: Help Here   ////////////
float distance = position.Length();

return (-magnitude / (distance * distance)) * vector3f(1,1,1);
////////////////////
}

float magnitude;
};


##### Share on other sites
I'm not in the mood to analyze your code intensively, but I guess the problem lays in the (1,1,1) vector. You scale this vector according to some distance related scalar, so all resulting vectors lay on the same line (the line that crosses the zero vector and 1,1,1). What you actually want (I guess) is something like:

velocity=(pos-fieldorigin)*some_scalar

where some_scalar is based on the distance.

good luck!

##### Share on other sites
Thanks. I tried that, and this version, but still no luck...

Any other ideas?

We're attempting and using mit ocw to get started...

http://groups.csail.mit.edu/graphics/classes/6.837/F04/assignments/assignment9/

Help...

class RadialForceField : public ForceField{public:   RadialForceField(float m)   {      magnitude = m;   }   virtual vector3f GetAcceleration(vector3f position, float mass, float t) const   {      float radius = position.Length();      return -(magnitude / (radius * radius)) * position;   }   float magnitude;};

##### Share on other sites
What effect does the current code have, if any?

##### Share on other sites
It generates a radial force field, but it is not quite "radial" eg a circle. More like an oval...

Ideas?

##### Share on other sites
It's still not clear exactly what you're observing the current code doing. How are you testing the force field? Are you evaluating the acceleration at various points to draw a representation of the acceleration vectors, or are you dropping a bunch of particles and watching where they are going?

##### Share on other sites
Hope this helps:
    C = Position of the center of attraction (vector)    P = Position of the object (vector)    r = distance between C and P    D = direction from the object to the center of attraction (vector)    k = "magnitude" of the attraction    F = force on the object (vector)    m = mass of the object    A = acceleration of the object (vector)    r = length( C - P )    D = ( C - P ) / r        F = D * k / r2      = ( C - P ) * k / r3        A = F / m      = ( C - P ) * k / ( r3 * m )
However, if you are talking about gravity, then F = D * k * m / r2, where k = G * m0, so A = ( C - P ) * k / r3.

##### Share on other sites
AP, yes, i'm using both methods to test: drawing a representation of the acceleration vectors and dropping a bunch of particles and watching where they are going...

JohnBolton, your post makes perfect sense, but I'm not reproducing the desired results / effect.

image: http://homepage.cs.latrobe.edu.au/sjflannery/1.gif

Using:

   virtual vector3f GetAcceleration(vector3f position, float mass, float t) const   {      static vector3f origin(0,0,0);      float radius = (origin - position).Length();      return origin - position * magnitude / (radius * radius * radius * mass);   }

where magnitude = k

##### Share on other sites
I don't see what's wrong with it. Basically you are simulating gravitational effects on a point mass (force inversely proportional to distance squared). The path of a particle in this force field is supposed to be elliptical, just like the path of planets around the sun.

If you want the particles to move in a circular path around the point, you need to also apply a force that will make the particle's direction perpendicular to the displacement between the particle and the point. This force would depend on the velocity and position of the particle.

##### Share on other sites
Perhaps the problem is that
    return origin - position * magnitude / (radius * radius * radius * mass);
should be
    return ( origin - position ) * magnitude / (radius * radius * radius * mass);
However, if origin is (0,0,0), then they are the same.

1. 1
2. 2
Rutin
22
3. 3
4. 4
frob
17
5. 5

• 33
• 13
• 12
• 10
• 12
• ### Forum Statistics

• Total Topics
632575
• Total Posts
3007150

×