Gravitacija - Gravity Acceleration
Program " Gravity Acceleration" je namenjen za izračunavanje vrednosti jačine gravitacionog ubrzanja ( g ), koje dobija jedno telo s poznatom masom ( m ) i poluprečnikom ( r ) , privučeno snagom gravitacionog polja drugog tela, koje ima masu ( M ) i poluprečnik ( R ), na posmatranoj udaljenosti ( h ) . Program izračunava gravitaciono ubrzanje za oba tela, na zadatoj međusobnoj udaljenosti ( h ) i na udaljenosti nula metara. Termin 'udaljenost između dva tela' se odnosi na udaljenost između površina ova dva tela. Rezultat koji se dobija uz pomoć ovog programa podrazumeva idealne uslove, a to znači da u svemiru ne postoji ni jedno drugo telo osim ova dva posmatrana, i da na njih ne utiče ni jedna druga sila osim međusobne sile privlačenja, Gravitacione sile. Izračunata ( g ) za oba tela se odnosi na rastojanje između centara masa oba tela ( R + r + h). Klikom na sliku programa možete preuzeti besplatnu verziju programa, za čiji rad je neophodan .Net framework 4.0 ili noviji. Na dnu strane se nalaze prilozi u okviru kojih je i 'Gravity acceleration open source.zip' arhiva sa kompletnim rešenjem za IDE SharpDevelop C#, koje možete preuzeti i u okviru koga je i kompletan programski kod koji možete menjati po želji. U nastavku je i originalni programski kod, u okviru koga je sve detaljno objašnjeno.
/************************************************************************************************
* Program name : Gravity acceleration *
* Program ver. : 1.0 *
* Created by : SharpDevelop *
* Code author : Perić Željko *
* Code language : C# *
* Date created : 24.02.2013 *
* Time created : 21:02 *
* *
* *
* Program Description : *
* *
* Simple console application for calculating gravity acceleration ( g ) , *
* that gets one celestial body with known mass ( m ) and radius ( r ) , *
* developed by the influence of force of gravity field of another body , *
* with known mass ( M ) and radius ( R ) , placed at observed distance ( h ). *
* *
* Program calculates gravity acceleration for both celestial bodies *
* at zero altitude ( h = 0 ) , and at observed distance. *
* *
* Calculated ( g ) applies at distance between centers of body masses ( R + r + h ) ! *
* *
* *
* Math formula for gravity force between two celestial bodies : *
* *
* F = M * m * G / ( R + r + h ) ^ 2 *
* *
* Math formula for gravity acceleration that gets body with mass ( m ) : *
* *
* g = F / m *
* *
* Math formula for gravity acceleration that gets body with mass ( M ) : *
* *
* g = F / M *
* *
* *
* Try to calculate gravity acceleration that gets metal object *
* with mass of one hundred kilograms and radius of ten centimeters , *
* placed at altitude of one hundred thousand meters from Earth's surface. *
* *
* Mass of object m = 1,00 e+002 Kg *
* Object radius r = 1,00 e-001 m *
* Object altitude h = 1,00 e+005 m *
* *
* Mass of Earth M = 5,98 e+024 Kg *
* Planet radius R = 6378 e+003 m *
* Gravity constant G = 6,67 e-011 N * m^2 / Kg^2 *
* *
* Result should be g = 9,50484671003033 e+000 m / s^2 *
* *
* This result presumes ideal condition , that there are only those two bodies *
* in universe with no other forces of any kind that can influence them. *
* *
* 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 *
* *
* 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 Gravity_acceleration
{
class Program
{
public static void Main(string[] args)
{
//
// Description of Main().
//
// Set values to necessary variables for calculation.
//
// Calculate gravity acceleration at zero altitude,
// and at observed distance for both celestial bodies.
//
// Show result in scientific ( exponential ) format.
//
//
//
// variable declaration
//
// gravity constant , just two decimal places !!!
const double G = 6.67e-11;
double R = 0;
double r = 0;
double M = 0;
double m = 0;
double h = 0;
double g1 = 0;
double g2 = 0;
double F = 0;
double d = 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";
//
// set console : title , window & buffer size , fore & back color and clear console
//
Console.Title = " Gravity acceleration - 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
//
R = 0;
r = 0;
M = 0;
m = 0;
h = 0;
g1 = 0;
g2 = 0;
F = 0;
d = 0;
//
// write program description to user
//
Console.Clear();
Console.Write("********************************************************************************");
Console.Write(" ");
Console.Write(" Program for calculating gravity acceleration ");
Console.Write(" ");
Console.Write(" that have one celestial body ");
Console.Write(" ");
Console.Write(" developed by the influence of gravity field of another celestial body ");
Console.Write(" ");
Console.Write(" at zero altitude and at observed distance ");
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 first body in kilograms M = ");
M = double.Parse(Console.ReadLine().ToString());
Console.Write("\n");
Console.Write(" Enter radius of first body in meters R = ");
R = double.Parse(Console.ReadLine().ToString());
Console.Write("\n");
Console.Write(" Enter mass of second body in kilograms m = ");
m = double.Parse(Console.ReadLine().ToString());
Console.Write("\n");
Console.Write(" Enter radius of second body in meters r = ");
r = double.Parse(Console.ReadLine().ToString());
Console.Write("\n");
Console.Write(" Enter observed body distance in meters h = ");
h = double.Parse(Console.ReadLine().ToString());
Console.Write("\n");
//
// calculate gravity force at zero altitude
//
F = m * M * G;
d = R + r;
d = d * d;
F = F / d;
//
// calculate gravity acceleration at zero altitude
//
g1 = F / M;
g2 = F / m;
//
// show result as string using format1
//
Console.Write("********************************************************************************");
Console.Write(" ");
Console.Write(" Gravity acceleration at zero altitude ");
Console.Write(" ");
Console.Write(" First body g = " + g1.ToString(format1) + " m / s^2 ");
Console.Write("\n");
Console.Write(" ");
Console.Write(" Second body g = " + g2.ToString(format1) + " m / s^2 ");
Console.Write("\n");
Console.Write(" ");
//
// calculate gravity force at observed distance
//
F = m * M * G;
d = R + r + h;
d = d * d;
F = F / d;
//
// calculate gravity acceleration at observed distance
//
g1 = F / M;
g2 = F / m;
//
// show result as string using format1
//
Console.Write("********************************************************************************");
Console.Write(" ");
Console.Write(" Gravity acceleration at observed distance ");
Console.Write(" ");
Console.Write(" First body g = " + g1.ToString(format1) + " m / s^2 ");
Console.Write("\n");
Console.Write(" ");
Console.Write(" Second body g = " + g2.ToString(format1) + " m / s^2 ");
Console.Write("\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 *
************************************
* *
* *
************************************/