Setting Gravity

Posted By: Teelo888

Setting Gravity - 02/15/04 11:27

All those who are willing to listen, please answer.

I was wondering in 3DGS how to set a gravitational point inside of a sphere, to make objects be drawn to it, and how to remove the default gravity already there. Please reply, im very desperate and I have been researching this topic for a few days now.
Posted By: kopitzki

Re: Setting Gravity - 02/15/04 18:53

If you are talking of 3dGS physics system, maybe this:

Code:
 
//while(1)
var sphere_pos[3];
var grav_vec[3];

vec_set(sphere_pos,sphere.x);
vec_diff(grav_vec, sphere_pos.x, my.x);
vec_normalize(grav_vec,grav_force);
phent_addcentralforce ( my, grav_vec );


Posted By: Teelo888

Re: Setting Gravity - 02/16/04 04:13

So which variables do i change according to where the sphere is and stuff?
and I dont see any variable telling the y pos or anything, wouldnt that be needed?
as you can tell im pretty newbish at C-Script but thanks for your help so far, I really appreciate it

Also my Aim name is Teelo888 also my MSN e-mail is teelo888@msn.com if someone would please help me on there
Posted By: kopitzki

Re: Setting Gravity - 02/18/04 22:42

Code:
 
entity sphere*;
var grav_force=1;//or 10 or 100 or 20.5 or 2500 or ...

action sphere//assign spheremodel to it
{
sphere=my;
}

action theothermodels //assign models affected by faked spheregravity to it
{
//
//phent_settype and all the usual physics setting stuff
//

var sphere_pos[3];
var grav_vec[3];

while(1){
vec_set(sphere_pos,sphere.x);
vec_diff(grav_vec, sphere_pos.x, my.x);
vec_normalize(grav_vec,grav_force);
phent_addcentralforce ( my, grav_vec );
wait(1);}
}


Posted By: fastlane69

Re: Setting Gravity - 02/19/04 03:05

Your code simulates attraction TO a sphere not INSIDE a sphere.

As per an earier post, gravity inside a hollow sphere is zero and gravity inside a non-hollow sphere is dependent on how much mass is the sphere "beneath" you so to speak.

If you just want gravitational attraction between bodies, then freakys code is right on. If you truly want gravity INSIDE a sphere, you'll have to follow what I said above and use some other scheme.
Posted By: Newton

Re: Setting Gravity - 02/19/04 03:54

I going to tap here if I may. Gravity inside a spherical object is linear with the distance from the object to center of the sphere. (assume more or less contant density).

So you do not need to use spherical coodenate in order to get the value of the gravity at any point inside the sphere.

all yo need is to now the magnitud of gravity on the surface, and the interpolate that value with the distance to the center.

somethin like this (pseudo code)

let G be the gravity
let R be the radius of the sphere
let P be the center of the sphere
lep Q be the point inside the sphere

distVector = substract (Q, P);
magOfdistVector = Magnitud (distVector)

gravDirVector = Normalize (distVector);
gravMag = G * (magOfdistVector / R)


this is valid in for any spherical object as long as the point is inside the sphere.

when the point is outside the it ovey Newton Gravitation Law

Newton

Posted By: fastlane69

Re: Setting Gravity - 02/19/04 06:38

Just wanted to make clear that Newtons Law of gravity applies to point sources. We approximate all the mass at the center of a planet or sun and thus treat it as a point source, but this is just an approximation. When inside an object, you can no longer use this point source appoximation since you have mass everywhere around you.

But youre absolutely right; spherical coords are overkill inside a uniformly dense spherical object
Posted By: Newton

Re: Setting Gravity - 02/19/04 07:29

no that is not an aproximation that is a fact

Newton
Posted By: fastlane69

Re: Setting Gravity - 02/19/04 09:06

Don't care to have this degrade into "Quen es mas Phisico", but you yourself stated a set of assumptions regarding geometry and mass; hence it's an approximation.

While your statments as to the linear behaiviour of gravity is fact, it is still a fact based on approximation that the earth is uniformly dense and a perfect sphere. A true Integration on the Oblate Spheroid that is the Earth and most Planets would not give a uniformly linear increase in gravitational Force. Gravitational Mapping of the surface of the earth show clearly how it varies across the face of the earth.

Further, the 1/(r*r) behaiviour that we so carelessly apply is in Fact a point source approximation. We "Put" all the mass at the center of a planet/star as an approximation that works well when we are far away from the mass so that it "looks" like a point mass. Hence, all the planets can be considered points like in calculating their gravitational interaction and thus, their orbits and little-g.

However, if you are close to the mass, or as in this case inside, then this simple point source approximation fails and you acutally have to use, gulp, Calculus to integrate all of the point source around you, in essense every atom, to account for the mass around you to give you the gravity. The fact that we are considering a symmetrical uniformly dense object (to whit a sphere) means that this integration (which BTW is easiest in spherical coords ) gives us an easy result, the linear behaiviour you mentioned.

Maybe we just debating semantics here, but all I was addressing was that Newtons Universal Gravitation Law is for point sources and should be used with care on extended objects. Usually, nice clean answers like the behaiviour you described is based on one approximation or another....

Finally, to get a bit esoteric, there is mounting evidence that while Newtons Grav law works well at our distance scales, on the scale of the Quantum or the Cosmic, then it **seems** that the traditional f= (Gm1m2)/(r*r) actually fails; new facts ursurping old laws!
© 2024 lite-C Forums