C++ program that calculates the resulting gravitational force in a system with three massive particles.
#include<iostream>
#include <math.h>
using namespace std;
int main () {
double fd1, fd2, fd3, M1, M2, M3, d12, d23, d31, A1, A2, A3, Fr1, Fr2, Fr3, A1M, A2M, A3M, D12, D23, D31, Fd1, Fd2, Fd3, RA1, RA2, RA3, x, y, z, FR1, FR2, FR3, IN1, IN2, IN3, V, AA1, AA2, AA3, a1, a2, a3;
const double G = 0.000000000066741;
const double PI = 3.14159265359;
cout << "///////////////////////////////////////////////////////////////////\n/////////////////////////////TGASS/////////////////////////////////\nWelcome to the Triangular Gravitational Attraction System Simulator\n///////////////////////////////////////////////////////////////////\n///////////////////////////////////////////////////////////////////\n///////////////////Made by Eduardo Monteiro////////////////////////";
cin.get();
cout << "Insert the masses of the three particles and the distance between the barycenters, place the angles between them if they have triangular positions.\nThe gravitational constant is considered 0.000000000066741 and PI is considered 3.14159265359. Insert mass in Kilograms, space in meters and angles in degrees. If the particles are aligned vertically to each other insert 0 in the angles.";
cin.get();
cout << "Mass of particle 1:";
cin >> M1;
cin.get();
cout << "Mass of particle 2:";
cin >> M2;
cin.get();
cout << "Mass of particle 3:";
cin >> M3;
cin.get();
cout << "Distance between particle 1 and 2:";
cin >> d12;
cin.get();
cout << "Distance between particle 2 and 3:";
cin >> d23;
cin.get();
cout << "Distance between particle 3 and 1:";
cin >> d31;
cin.get();
cout << "Angle formed by particle 1:";
cin >> AA1;
cin.get();
cout << "Angle formed by particle 2:";
cin >> AA2;
cin.get();
cout << "Angle formed by particle 3:";
cin >> AA3;
cin.get();
D12 = d12*d12;
D23 = d23*d23;
D31 = d31*d31;
fd1 = M1*M2/D12;
fd2 = M2*M3/D23;
fd3 = M3*M1/D31;
Fd1 = fd1*G;
Fd2 = fd2*G;
Fd3 = fd3*G;
if(AA1 != 0, AA2 != 0, AA3 !=0){
A1 = 180-AA1;
A2 = 180-AA2;
A3 = 180-AA3;
V = PI/180;
RA1 = A1*V;
RA2 = A2*V;
RA3 = A3*V;
x = RA1/2;
y = RA2/2;
z = RA3/2;
IN1 = sin(x);
IN2 = sin(y);
IN3 = sin(z);
FR1 = IN1*Fd1;
FR2 = IN2*Fd2;
FR3 = IN3*Fd3;
Fr1 = FR1;
Fr2 = FR2;
Fr3 = FR3;
a1 = Fr1/M1;
a2 = Fr2/M2;
a3 = Fr3/M3;
cout << "Resultating gravitational force exhibited in particle 1 is:"<< Fr1 << endl;
cout << "Resultating gravitational force exhibited in particle 2 is:"<< Fr2 << endl;
cout << "Resultating gravitational force exhibited in particle 3 is:"<< Fr3 << endl;
cout << "Acceleration of particle 1 is:"<< a1 << endl;
cout << "Acceleration of particle 2 is:"<< a2 << endl;
cout << "Acceleration of particle 3 is:"<< a3 << endl;
cout << "_________1___________\n_________O___________\n_____________________\n_____________________\n_____________________\n__2_______________3__\n__O_______________O__";
}
if(AA1 == 0, AA2 == 0, AA3 == 0){
Fr1 = Fd1+Fd3;
Fr2 = Fd2-Fd1;
Fr3 = Fd3+Fd2;
a1 = Fr1/M1;
a2 = Fr2/M2;
a3 = Fr3/M3;
cout << "Resultating gravitational force exhibited in particle 1 is:"<< Fr1 << endl;
cout << "Resultating gravitational force exhibited in particle 2 is (positive result means vector is pointing to the right and negative result means vector is pointing to the left):"<< Fr2 << endl;
cout << "Resultating gravitational force exhibited in particle 3 is:"<< Fr3 << endl;
cout << "Acceleration of particle 1 is:"<< a1 << endl;
cout << "Acceleration of particle 2 is:"<< a2 << endl;
cout << "Acceleration of particle 3 is:"<< a3 << endl;
cout << "_____________________\n_____________________\n_1_______2________3__\n_O_______O________O__\n_____________________\n_____________________\n";
if(d31 != d12+d23){
cout << "If the angles are zero the distance between the particle 1 and the particle 3 should be the sum of the distance between the particle 1 and the particle 2 and the distance between the particle 2 and the particle 3.";
cout << "\nTHIS WAS MISCALCULATED BY YOU!";
}
cin.get();
system("PAUSE");
return 0;
}
}
No comments:
Post a Comment