Gravitacija - Zero gravity

Program "Zero gravity" je namenjen za izračunavanje na kojoj visini ( udaljenosti ) od planete je gravitaciona sila toliko mala da je praktično zanemarljiva i ne utiče na posmatrano telo koje se udaljuje od planete. Jačina gravitacione sile se izračunava takozvanom grubom silom računanja. To se ostvaruje konstantnim uvećanjem visine za određeni korak ( h ), preračunavanjem vrednosti gravitacione sile i ukoliko je ispunjen uslov ( F =< 0,001 N ), program završava računanje, i prikazuje dostignutu visinu ( udaljenost ). Tačna vrednost gravitacione sile bi trebalo da bude nula , kada je telo definitivno oslobođeno uticaja gravitacionog polja planete, što je na osnovu prikazane formule praktično nemoguće, osim da bude beskonačno mala veličina. Međutim, sobzirom da su kućni kompjuteri dosta spori za ovakav vid izračunavanja ( grubom silom ) , uslov za zaustavljanje izračunavanja je da jačina gravitacione sile bude jednaka ili manja od 0,001 N.

https://sites.google.com/site/periczeljkosmederevo/fizika/gravitacija---zero-gravity/Zero%20gravity%20screenshot.png

Ukoliko raspolažete izuzetno jakom mašinom možete pokušati i sa uslovom ( F =< 0,00000000000000000000000000000001 N ). Naravno za kontrolu tačnosti ovakvog načina izračunavanja treba ipak izračunati jačunu gravitacione sile na klasičan način, uz pomoć matematičke formule koja je dole priložena. Mnogo je brže :)). Upoređivanjem ovako dobijenog rezultata i rezultata dobijenog "grubom silom", možete doći do interesantnog zaključka. Takođe, dobijeni rezultat predpostavlja da u svemiru ne postoji ništa drugo osim dva posmatrana tela i da na njih ne utiče nikakva druga sila osim sile gravitacije. Ovo je i navedeno u okviru programskog koda. Sve što se tiče gravitacije možete pronaći na dole navedenim adresama :

Pored ovih adresa ima još mnogo mesta na internetu posvećenih ovoj temi. Ono što je bitno za programera koji rešava ovakav tip problema jeste kako se izračunava jačina gravitacione sile.Na osnovu gore navedene literature :

Postupak za izračunavanje gravitacione sile je sada jasan. Neophodno je da korisnik programa unese vrednosti promenljivih M, m, R, r i h . Gravitaciona konstanta , samo ime joj kaže ima konstantnu vrednost, koja iznosi približno 6.67E-11 Nm^2/Kg^2. Po unosu, vrednosti se jednostavno ubace u gore navedenu formulu i dobijamo vrednost jačine sile privlačenja između dva tela odnosno jačinu gravitacione sile. Bitno je da je veličina h u programu upotrebljena za unos koraka u metrima za koji će se uvećavati nadmorska visina odnosno udaljenost tela od planete. Vrednost h bi zbog brzine računanja trebalo da varira između 100 i 1000 metara. U tom slučaju dobijate relativno brzo približno tačan rezultat. Ukoliko imate izuzetan kompjuter kada su procesori u pitanju možete postaviti i vrednost od jednog milimetra, kada se preciznost povećava na praktično maksimalan nivo. Algoritam pokušajte da napravite sami, u međuvremenu pogledajte programski kod :

/************************************************************************************************

* Program name : Zero Gravity *

* Program ver. : 2.0 *

* Created by : SharpDevelop *

* Code author : Perić Željko *

* Code language : C# *

* Date created : 05.02.2012 *

* Time created : 20:44 *

* *

* *

* Program Description : *

* *

* Simple console application for calculating body altitude , *

* distance between planet and body , where the influence *

* of the gravitational field of planet is insignificant , *

* gravity force between planet and body is less or equal 0,001 N. *

* *

* Math formula : F = M * m * G / ( R + r + h )^2 *

* *

* F - gravity force N *

* M - mass of planet Kg *

* m - mas of body Kg *

* G - gravity constant N * m^2 / Kg^2 *

* R - planet radius m *

* r - body radius m *

* h - distance m *

* *

* Program accepts scientific format for large and small numbers. *

* *

* 4,3 e+5 = 4,3 * (10 ^ 5) = 4 300 000 e+5 stands for 10 raised to +5th power *

* *

* 587 e-5 = 587 * (10 ^-5) = 0,00587 e-5 stands for 10 raised to -5th power *

* *

* To enter such number , just type in 4,3e+5 or 587e-5 *

* *

* Number range that this program accept is from 1,7 e-308 up to 1,7 e+308 *

* *

* It is expected that entered values for calculation have adequate planet/body ratio , *

* other wise program looses logical sense , but still it shall give correct result. *

* *

* Example : Make calculation for planet Earth and simple ball *

* *

* *

* planet Earth : M = 5,98 e+024 Kg *

* R = 6378 e+003 m *

* *

* simple ball : m = 2,50 e-001 Kg *

* r = 3,00 e-001 m *

* *

* Result should be : h = 3,09401194708158 e+005 Km or 309 401,194708158 Km *

* *

* This result presumes ideal condition , that there are only these two bodies *

* in universe with no other forces of any kind that can influence them. *

* *

* Program Accuracy Notice : *

* *

* All calculations in program are executed using double type of variable. *

* By default , a double value contains 15 decimal digits of precision , *

* although a maximum of 17 digits is maintained internally. *

* Result is shown in scientific format , rounded at fourteen decimals. *

* This could cause fatal error because , in some cases for accurate result , *

* many more digits are significant , especially when very large or very small *

* numbers are involved. *

* *

* Gravity constant value is rounded at two decimal places , *

* and usually input values that user type in , have it's own precision error... *

* *

* So the result that this program gives is always approximate and never 100 % accurate ! *

* *

* *

* All the best, *

* Author. *

************************************************************************************************/

using System;

namespace Zero_gravity

{

class Program

{

public static void Main(string[] args)

{

//

// Description of Main().

//

// Set values to necessary variables for calculation.

//

// Calculate gravity force at zero altitude

// and show result on console screen

// as formatted string representation of number.

//

// Simulation of body flying away from planet :

//

// Calculate strength of gravity force for every body altitude

// incremented by altitude increment value and show result on

// console screen as formatted string representation of number.

//

// Simulation end's when strength of gravity force becomes

// equal or less than 0,001 N.

//

// Calculate distance between body and planet where gravity force is equal 0,001 N

// and show result on console screen as formatted string representation of number.

//

// Calculated altitude result is divided by 1000 m and represents distance in Km.

//

//

// variable declaration

//

// gravity constant , just two decimal places !!!

const double GravityConstant = 6.67e-11;

double PlanetRadius = 0;

double BodyRadius = 0;

double PlanetMass = 0;

double BodyMass = 0;

double BodyAltitude = 0;

double GravityForce = 0;

double AltitudeIncrement = 0;

double helper = 0;

double helper1 = 0;

// scientific (exponential) number format with 14 decimals

// first three decimals shall always be shown on console

// next eleven are optional , if not equal zero

string format1 = "0.000############ e+000";

// scientific (exponential) number format rounded at 6 decimals

string format2 = "0.000000 e+000";

// cursor column position

int Column = 0;

// cursor row position

int Row = 0;

// counter

double i = 0;

//

// set console : title , window & buffer size , fore & back color and clear console

//

Console.Title = " Zero Gravity - by Perić Željko (periczeljkosmederevo@yahoo.com)";

Console.SetWindowSize(80,42);

Console.SetBufferSize(80,42);

Console.ForegroundColor = ConsoleColor.Green;

Console.BackgroundColor = ConsoleColor.Black;

Console.Clear();

//

// declare new variable 'key' and set it's initial value to 'Y' - 'Yes' ,

// used for getting user's answer from keyboard at the end of program

//

ConsoleKeyInfo key = new ConsoleKeyInfo('Y',ConsoleKey.Y,true,true,true);

//

// restart calculation if answer is 'Y' - 'Yes'

//

while(key.Key == ConsoleKey.Y)

{

//

// set variables to initial values

//

PlanetRadius = 0;

BodyRadius = 0;

PlanetMass = 0;

BodyMass = 0;

BodyAltitude = 0;

GravityForce = 0;

AltitudeIncrement = 0;

helper = 0;

helper1 = 0;

Column = 0;

Row = 0;

i = 0;

//

// write program description to user

//

Console.Clear();

Console.Write("********************************************************************************");

Console.Write(" ");

Console.Write(" Program for calculating body altitude ");

Console.Write(" ");

Console.Write(" ( distance between planet and body ) ");

Console.Write(" ");

Console.Write(" where the influence of the gravitational field ");

Console.Write(" ");

Console.Write(" of planet is insignificant, F is less or equal 0,001 N ");

Console.Write(" ");

Console.Write("********************************************************************************");

Console.Write("\n");

//

// get inital values

//

// warning ,

// there is no part for validation

// of relevance of entered number

// that part try to write yourself

//

// To enter very large or very small number

// use scientific format that program recognize.

//

// Mass of Sun M = 1,99 e+30 Kg

//

// type in 1,99e+30 or 1,99e30 or 1,99E+30 or 1,99E30

//

// Gravity constant G = 6,67 e-11 N * m^2 / Kg^2

//

// type in 6,67e-11 or 6,67E-11

//

//

Console.Write(" Enter mass of planet in kilograms M = ");

PlanetMass = double.Parse(Console.ReadLine().ToString());

Console.Write("\n");

Console.Write(" Enter radius of planet in meters R = ");

PlanetRadius= double.Parse(Console.ReadLine().ToString());

Console.Write("\n");

Console.Write(" Enter mass of body in kilograms m = ");

BodyMass = double.Parse(Console.ReadLine().ToString());

Console.Write("\n");

Console.Write(" Enter radius of body in meters r = ");

BodyRadius= double.Parse(Console.ReadLine().ToString());

Console.Write("\n");

Console.Write(" Enter altitude increment in meters h = ");

AltitudeIncrement = double.Parse(Console.ReadLine().ToString());

Console.Write("\n");

//

// calculate gravity force at zero altitude , and write result

//

GravityForce = BodyMass*PlanetMass*GravityConstant;

helper = PlanetRadius + BodyRadius + BodyAltitude;

helper = helper * helper;

GravityForce = GravityForce / helper;

//

// show result as string using format1

//

Console.Write("********************************************************************************");

Console.Write(" ");

Console.Write(" Garvity force at zero altitude F = ");

Console.Write(GravityForce.ToString(format1) + " N ");

Console.Write("\n");

Console.Write(" ");

Console.Write("********************************************************************************");

Console.Write("\n");

//

// get current cursor column and row position

//

Column = Console.CursorLeft;

Row = Console.CursorTop;

Console.Write(" Press any key to continue . . .");

Console.ReadKey(true);

//

// set cursor position

//

Console.SetCursorPosition(Column,Row);

Console.Write(" ");

Console.Write(" ");

Console.Write(" ");

Console.Write(" ");

Console.Write("********************************************************************************");

//

// increase altitude until gravity force becomes less or equal 0,001

//

while (GravityForce > 0.001) // here you can change condition for gravity strength

{

BodyAltitude = BodyAltitude + AltitudeIncrement;

GravityForce = BodyMass*PlanetMass*GravityConstant;

helper = PlanetRadius + BodyRadius + BodyAltitude;

helper = helper * helper;

GravityForce = GravityForce / helper;

i++;

//

// this question increases speed of calculation by

// writing on console every 1 000 000-th result

//

if(i%1000000 == 0)

{

//

// write results without changing position of text

//

Console.SetCursorPosition(Column,Row);

//

// show result as string using format2

//

Console.Write(" Gravity force F = ");

Console.Write(GravityForce.ToString(format2) + " N ");

Console.Write("\n\n");

Console.Write(" At achieved altitude h = ");

Console.Write((BodyAltitude/1000).ToString(format2) + " Km ");

}

}

//

// write final results without changing position of text

//

Console.SetCursorPosition(Column,Row);

//

// show result as string using format1

//

Console.Write(" Gravity force F = ");

Console.Write(GravityForce.ToString(format1) + " N ");

Console.Write("\n\n");

Console.Write(" At achieved altitude h = ");

Console.Write((BodyAltitude/1000).ToString(format1) + " Km ");

Console.Write("\n\n");

//

// calculate zero gravity altitude directly trough math calculation

// for F = 0,001 N altitude h = ?

//

GravityForce = BodyMass*PlanetMass*GravityConstant;

helper1 = GravityForce / 0.001;

helper1 = Math.Sqrt(helper1);

if (helper1.ToString() == (PlanetRadius + BodyRadius).ToString())

{

helper1 = 0;

}

else

{

helper1 = (helper1 - PlanetRadius - BodyRadius) / 1000;

}

//

// show result as string using format1

//

Console.Write("********************************************************************************");

Console.Write(" ");

Console.Write(" Gravity force F = 0,001 N ");

Console.Write(" ");

Console.Write(" At calculated altitude h = " + helper1.ToString(format1) + " Km \n");

Console.Write(" ");

Console.Write("********************************************************************************");

Console.Write("\n");

//

// end of program

//

Console.Write(" Another calculation (y/n) ? ");

key = Console.ReadKey(true);

}

}

}

}

/************************************************************************

* Program Licence : *

* *

* Copyright 2012 , Perić Željko *

* (periczeljkosmederevo@yahoo.com) *

* *

* According to it's main purpose , this program is licenced *

* under the therms of 'Free Software' licence agreement. *

* *

* If You do not know what those therms applies to *

* please read explanation at the following link : *

* (http://www.gnu.org/philosophy/free-sw.html.en) *

* *

* Since it is Free Software this program has no warranty of any kind. *

************************************************************************

* Ethical Notice : *

* *

* It is not ethical to change program code signed by it's author *

* and then to redistribute it under the same name , especially *

* if it is incorrect. *

* *

* It is recommended that if you make improvement in program code , *

* to make remarks of it and then to sign it by Your's name , *

* for further redistribution as new major version of program. *

* *

* Author name and references of old program code version should be *

* kept , for tracking history of program development. *

* *

* For any further information please contact code author at his email. *

************************************************************************/

/************************************

* List Of Revisions *

************************************

* Minor revision of version 1.0 *

* Author 21.02.2013 *

* new comments added *

* New version number 1.1 *

************************************

* Major revision of version 1.1 *

* Author 22.02.2013 *

* new comments added *

* console user interface changed *

* number format changed *

* spelling checked *

* program licence added *

* New version number 2.0 *

************************************/

Prilikom unosa vrednosti možete koristiti takozvani naučni format brojeva primer: 230 000 000 000 = 2,3e+11

Vodite računa da li je kod vas definisan zarez za razdvajanje decimala od celih brojeva ili tačka.

Pokušajte da izračunate udaljenost tela od planete Zemlje na kojoj je F = 0,001 N :

* Masa Zemlje M = 5,98 e+24 Kg

* Poluprečnik Zemlje R = 6,372797 e+6 m

* Masa tela m = 1 Kg

* Poluprečnik tela r = 1 m

* Korak za uvećanje h = 10000 m

Rezultat pogledajte gore na slici.

U prilogu se nalazi "Zero gravity open source.zip" arhiva s kompletnim rešenjem pisanim za IDE SharpDevelop C#,

koje možete preuzeti i u okviru koga je i sam program. Neophodan .Net framework 4.0 ili noviji.