Get actual gravity?

Blitz3D Forums/Blitz3D Beginners Area/Get actual gravity?

Guy Fawkes(Posted 2009) [#1]
Hi all, how can I get the ACTUAL gravity of earth, and use that formula in my program, so I can add the actual weight of any mesh to it, so I get perfect earth gravity?

can someone show me a small example?


GfK(Posted 2009) [#2]
There is no "perfect earth gravity" - it varies depending on many factors such as geographic location, altitude above sea level etc. You can get away with 9.8m/s^2 and performing accurate-ish calculations will be complex. I can't see any circumstance where you couldn't simulate it with a couple of minutes trial and error. It'll be faster, and easier.

Google "international gravity formula" if you want specific info.

PS: This is far from a beginner's subject.


Guy Fawkes(Posted 2009) [#3]
that's what i meant, an accurate-ish formula w/ use to create gravity by adding on the object's actual 'weight'


big10p(Posted 2009) [#4]
Personally, I'd just tweak it until it 'looked' right.


Guy Fawkes(Posted 2009) [#5]
it's always the easy way w/ coders. why can't there EVER be a complex formula that WORKS easily?

now, how can i use the earth gravity formula in the code?

how do i get the value of m/s^2?


GfK(Posted 2009) [#6]
it's always the easy way w/ coders
...and? Why make things more difficult than they need to be?

Essentially you're asking somebody else to do this for you. If you wanted to figure it out for yourself then I could understand it as you'd be learning from it. If you do what I said (above) you can quickly find the formula (it was on Wikipedia).


_Skully(Posted 2009) [#7]
It won't work. The reason is factors of scale but go for it... try it.

Add 9.8m/s per second to the object every 1000ms .. now go ahead... ask "What is a metre on screen"


GfK(Posted 2009) [#8]
Add 9.8m/s per second to the object every 1000ms .. now go ahead... ask "What is a metre on screen"
What's a screen? ;)

Sorry I'm just being silly now.


Guy Fawkes(Posted 2009) [#9]
what is a metre on screen? -.- LOL


Guy Fawkes(Posted 2009) [#10]
(:P)


Midimaster(Posted 2009) [#11]
there are two different reasons to need gravity: for rising speed of an object, that is falling down, or to know the enery of an object, when collides another.

Rez, I hope you only need the speed aspect...

You can simply do this by adding "gravitiy" to the y-speed:

Graphics3D 600,400

Global BallX#, BallY#, BallxSpeed#, BallYSpeed#, Gravity#

BallXSpeed=2
Gravity=0.10
Repeat

        ; simulated gravity
	BallYSpeed=BallYSpeed+Gravity
	BallX=BallX+BallxSpeed
	Bally=Bally+BallYSpeed
	
	;only to simulate borders
	If BallX<0 Or BallX>591 Then
		BallxSpeed=-BallXSpeed
	EndIf
	If  BallY>391 Then
		BallYSpeed=-BallYSpeed*0.95
		BallY=390
	EndIf

        ;the drawing
	Cls
	Oval BallX,Bally,10,10	
	Flip

Until KeyHit(1)


Try out different values for "gravity" from 0.05 to 0.20


Guy Fawkes(Posted 2009) [#12]
thanks midimaster, this is great! :) although i changed the oval to a sphere just for fun :P


GfK(Posted 2009) [#13]
thanks midimaster, this is great! :)
...its also what I suggested you do in the first place. ;)


Guy Fawkes(Posted 2009) [#14]
well yea, but regardless of how complex it is, wouldn't it be much more real if i used the formula?


_PJ_(Posted 2009) [#15]
Not really, since event he most powerful computers invented can only do simple approximations to certain effects of gravity.
There is no 'real formula' as there's too much we don't know. If you can find it, be sure to let the physcists know!

In reality, the masses of every massive object need to be calculated and then their effects applied to every other object.

It's really MUCH easier just to go with a basic newtonian mechanical approximation and assume a constant acceleration due to gravity as something like 9.8m/s^2

The basics of Newton's principles should suffice for most games and aer summarised as:

Acceleration= F / m
Gravitational Potential Energy= mGh
Kinetic Energy= 0.5mv^2


_Skully(Posted 2009) [#16]
You *could* do real gravity, but you have to relate pixel distance to metres... with that you can figure out what your Y value add is per second to get it exact.

For example, if a 32 pixels is 1 metre... 9.8/32 is what you need to add per second.

As for Mass... all objects in our world are effected exactly the same by gravity... its friction that effects the results which is why 2 balls of exactly the same size but differing mass will fall at the same speed. Of, course there is a threshold there too because obviously a ball of fluff vs a ball of iron will be a little different because of its boyancy vs air.


_PJ_(Posted 2009) [#17]
Not true at all, Skully.

As mentioned, it is impossible to calculate 'real' gravity, noone can.

Acceleration due to gravity between objects is inversely proportional to the mass and distance squared. For example, a massive object at the Earth's North Pole would have be influenced by a greater magnitude of 'weight' than a similar massive object at the Earth's equator.

Buoyancy has NO correlation to gravity whatsoever. Buoyancy is an aspect of pressure and density.

The best option is to use typical newtonian mechanical approximations. computer games shouldn't need any more complexity.


Midimaster(Posted 2009) [#18]
@malice:

oh, this is nice... i tried to do a pool billiard simulation some time ago, and therefore this formulas would have been usefull (sorry for my bad english).

The rolling billiard balls have different directions and different speed and the "exchange" energy in the moment of collisions. My simulation looked very nice, as long as only 2 or three collided, or if the collision was to the pools walls.

But in the moment of first shot (you know: all balls are laying very closed together) it looked very "strange" and I stopped the project.

could you please explain, what the single elements of the formulas mean?


_PJ_(Posted 2009) [#19]
For billiard balls, you only really need to consider two things, Speed and the angle that they collide, unless you're specifying that the cue ball is not the same weight as the regular balls, the formulae above aren't so useful.

Friction of the table would slow the balls down and is very simply going to be a constant negative acceleration (deceleration) which you can define as you are free to make up how rough the baise is!

Otherwise, the Kinetic Energy will be useful though as energy is conserved.
( 0.5 * MASS * (Velocity^2) ) is the energy of a moving object. When it collides, (some energy is actually lost in the collision as heat and sound, but it's negligible)

So for any two objects, (note if one is at rest, then it will have 0 Kinetic energy due to 0 veliocity), the TOTAL energy is:

( 0.5 * MASS_OF_OBJ_1 * (Velocity_OF_OBJ_2^2) ) + ( 0.5 * MASS_OF_OBJ_2 * (Velocity_OF_OBJ_2^2) )

On collision, this total energy is conserved and the two objects each have a new VELOCITY.

To establish the new velocities, you need to use trigonometry (which I suck at) but it's basically the ratio of the angle of collision compared to a 'direct hit' head on. In a direct hit, Object 1's velocity actually becomes 0 and all the energy is given to object 2 which moves in the same direction as object 1 was moving.

at 89.99999 degrees, only a tiny fraction of the energy is given to Object 2 so it's new velocity is small.

(We don;t necessarily need to consider the masses for the billioard balls if we assume they are identical, as well as we aren't 'chipping bits off them' in collisions, so the masses are unafected!)

This page may help with the maths for the billiards:
http://hyperphysics.phy-astr.gsu.edu/Hbase/elacol2.html#c2



As to the formulae I posted earlier,

F= Force (measured in Newtons)
m= mass (measured in kilograms)
a= acceleration (measured in metres per second per second) == per second^2
v=velocity (measured in metres per second)
g=acceleration due to gravity ( this is what can be averaged to 9.807 metres pre second per second mentioned earlier)
h=height (measured in metres)


An object falling can be described by the conversion of gravitational potential energy into kinetic energy (again, a neglibgible amount of energy is lost as heat and sound)

The mgh represents its initial energy, and at the start of iits fall, the kinetic energy is 0 (it has 0 velocity in a DOWNWARDS direction)
As it falls, it gains momentum (mv) and so the kinetic energy increases (0.5*MASS*velocity^2) because its height is decreasing, though, the mgh gravitational potential energy is decreasing, until when it hits the floor (centre of the earth :) ) its mgh = 0 and KE will euqual the initial mgh (give otr take the energy lost in heat and sound and smashing itself to bits on the floor!)


_Skully(Posted 2009) [#20]
Standard Gravity or that near the surface of the earth is well known to be approximately 9.8m/s^2... there is a tiny difference of the force at sea-level vs a mountain top but its quite minor.

If boyancy is not a factor affecting an object then a helium baloon would not rise compared to an air balloon that falls. Same size, different mass sure... but its boyancy that makes the helium baloon rise. I'm not saying it affects gravity, I'm saying it affects an object along with air friction that is responsible for terminal velocity.

Mind you, if you take the topic title literally, you are very correct. I was just trying to keep it simple.


Guy Fawkes(Posted 2009) [#21]
can someone just explain to me how i can get the values of m/s^2 ?


_Skully(Posted 2009) [#22]
It was explained in code above


Guy Fawkes(Posted 2009) [#23]
yes, but the variable "s" was NOT explained.


GIB3D(Posted 2009) [#24]
I'm guessing s = second.

Meters per Second^2


Midimaster(Posted 2009) [#25]
@malice:

excellent!!! with your post this topic will become a source for a lot of blitzcoders. Thank you! I will need some time to think about it :-)

@rez:

use it like that:

Speed after x seconds
-------------------------------------------
Speed = 9.8 meter / secē * x sec =>
Speed = 9.8 * x meter/sec


wmaass(Posted 2009) [#26]
Good stuff Malice. Now, if you could give us your thoughts on simulating golf ball flight, you'll be my hero. Ball spin relative to slice/hook and lift make my head hurt.

So far my research has taken me to some fancy formulas that are very accurate by seem to require that I populate an array of the position of the ball for its entire flight, then "play it back". The problem with that for me is latency. When a player hits the ball, I want it to launch...immediately. There doesn't seem to be a way to use any of the middleware physics engines to do it in real-time. Though today I thought that I might be able to simulate a slice for example by doing this:

For every x amount of sidespin (rpm), turn the ball y amount in the direction of the spin. The same might apply for backspin and lift. Silly?


Guy Fawkes(Posted 2009) [#27]
indeed, malice :)


Midimaster(Posted 2009) [#28]
if we are talking about gravity, do not forget the "air drag"!

With only gravity, an object would become faster and faster, but the air drag (air resistance) stopps the acceleration.

A man jumping from a airplane can only get a speed of max 240 km/h in falling, when opening his parachute only 30km/h to 6km/h. A snowflake or a piece of paper only 3 km/h.

So the formula should have an aspect for this behavior, too!


Matty(Posted 2009) [#29]
Force due to air resistance is proportional to the velocity of the object squared. You also need to factor in the cross sectional area of the object.

If you want to go further you can even look at whether the air flow is laminar or turbulent, and begin looking at Reynolds numbers and such like.


wmaass(Posted 2009) [#30]
That's right Matty. Check out Magnus Effect:

http://en.wikipedia.org/wiki/Magnus_effect


_PJ_(Posted 2009) [#31]
Standard Gravity or that near the surface of the earth is well known to be approximately 9.8m/s^2... there is a tiny difference of the force at sea-level vs a mountain top but its quite minor.
If boyancy is not a factor affecting an object then a helium baloon would not rise compared to an air balloon that falls. Same size, different mass sure... but its boyancy that makes the helium baloon rise. I'm not saying it affects gravity, I'm saying it affects an object along with air friction that is responsible for terminal velocity.
Mind you, if you take the topic title literally, you are very correct. I was just trying to keep it simple.


Sure, but it was misleading, you shoulda clarified a little rather than stating it as definite.

Buoyancy involves density which is mass/volume. the gravitational force felt by and exerted by an object has no relation to its density.
For example, a 1kg ball of lead will have the same gravitational force on it (at equivalent distance) as a 1kg ball of air molecules.


So far my research has taken me to some fancy formulas that are very accurate by seem to require that I populate an array of the position of the ball for its entire flight, then "play it back". The problem with that for me is latency. When a player hits the ball, I want it to launch...immediately. There doesn't seem to be a way to use any of the middleware physics engines to do it in real-time. Though today I thought that I might be able to simulate a slice for example by doing this:

For every x amount of sidespin (rpm), turn the ball y amount in the direction of the spin. The same might apply for backspin and lift. Silly?


I'm not much of a golfer, but consider

s=ut+(0.5*a*(t^2))

s=displacement (metres)
u=initial velocity (metres per second)
t=time (seconds)
a=accel (metres per second per second)

This gives a distance in a lateral dimension for an object 'launched' with initial speed of u

The initial speed is obtained by he kinetic energy stuff earlier, so the Energy put into the golf-club swing is transferred to the ball.

If you know the ball's mass, then it's initial K.E will be 0.5*m*u^2
where m is its mass giving you "u" the initial velocity.

The path of the ball will trace a parabola as it is only accelerating downwards. When itn the air, the only force acting on it is gravity (modified by effets of air resistance, which will also cause its lateral motion to slow).


wmaass(Posted 2009) [#32]
Good info Malice. Did you have a look at the Mangus Effect link I posted? I did manage to get something to resemble a ball that hooks or slices by turning the ball about the Y axis in the case of side spin. It looks convincing enough for casual golf games but I am also interested in realism.


Nate the Great(Posted 2009) [#33]
Force due to air resistance is proportional to the velocity of the object squared. You also need to factor in the cross sectional area of the object.

If you want to go further you can even look at whether the air flow is laminar or turbulent, and begin looking at Reynolds numbers and such like.



I find it easier to write a physics engine and a fluid engine on top of that than to simulate air friction and gravity with prewritten formulas... all of these formulas are too complex...

all you need to know is an object in motion will stay in motion unless acted on by another force

hence every frame
vx,vy = velocity vector
x,y = position vector

x = x + vx
y = y + vy

vy = vy + gravityconstant

and add in the navier stokes formula and bam you have fluid friction and a physics engine lol