Virtual Solar System (formula for gravity in 3d)

In summary, the conversation is about creating a virtual solar system in Java3d and implementing the orbiting of planets and ships. The formula for calculating gravitational force in 3D is discussed, with the difficulty of using doubles to hold large distances and small forces. The use of a BigVector3d class is mentioned, and a formula for calculating the gravitational force for x, y, and z components is proposed and implemented. The conversation ends with a discussion about the results obtained from the formula.
  • #1
Mipada
2
0
I've made a virtual solar system in Java3d. I'm trying to implement the orbiting of planets and ships. I get the basic formula
Code:
F = G((m1*m2)/r^2))[\code] and saw a discussion here about the formula in 3d but, I don't know how to read a letter with an arrow over it, lol.  Can someone help me with the details?
Note:doubles can't seem to hold the big distances and the minute force of gravity at those distances.  I've ended up creating a BigVector3d class.  It holds BigDecimal numbers and allows me to use vectors (at least to hold 3d numbers in one object).  I'll post that for someone else to use.
Fundamentally I'm doing this.
(Sorry, I can't find the usual code formatting commands I've seen before.  And, I don't know if this is in the right forum.)
[code]
vv = vv + av;//velocity vector = velocity vector + acceleration vector
lv = lv + vv;//location vector = location vector + velocity vector (for x, y, z)
[\code]

My main loop calls acceleration(Mass3d m2)
[code]
for (int j = 0;j < mass.size();j++){
    for (int i = j;i < mass.size();i++)//skip previously done masses
    {
        mass.get(j).acceleration(mass.get(i));//for each other mass
    }
}
[\code]
Then i try using this formula.
[code]
acceleration(Mass3D m2){
//F = -((G*m1*m2 * r.x)/r3) * r3
//split force between two masses.  I don't think this part works at all.
m1.location.add(F/2);
m2.location.sub(F/2);
}
[\code]
How can i get the gravitational force for the x, y, z components?
 
Last edited:
Astronomy news on Phys.org
  • #2
I found this formula.
Gravity formula.jpg

and tried to implement it as:
//FX
if (BD.get(X).doubleValue() > 0.000000009){//avoid div by 0 error
FX = FX.add(BG);//big gravity
FX = FX.multiply(BM);//big mass
FX = FX.divide(BD.get(X).pow(2), mc);//big distance (x dist^2)
FX = FX.multiply(BD.get(X));//big distance
FX = FX.multiply(NEG1);//make negative
}
else{//distance is 0, no force applied
FX = new BigDecimal("0");
}
Giving me the Earth pulling on a small ship in orbit, a value of
FX5=-9960977999999.9991344000
in meters per second. I'll check the numbers and get back to you.
 

1. What is the formula for calculating gravity in a virtual solar system?

The formula for calculating gravity in a virtual solar system is the same as in the real world. It is F = G * (m1 * m2) / r^2, where F is the force of gravity, G is the gravitational constant, m1 and m2 are the masses of the two objects, and r is the distance between them.

2. How is the force of gravity affected by the distance between objects in a virtual solar system?

The force of gravity is inversely proportional to the square of the distance between objects. This means that as the distance between objects increases, the force of gravity decreases.

3. Can the formula for gravity in a virtual solar system be modified for different sized objects?

Yes, the formula can be modified for different sized objects. The masses of the objects would need to be adjusted accordingly in order to accurately calculate the force of gravity.

4. Is the formula for gravity in a virtual solar system affected by the size of the virtual space?

No, the size of the virtual space does not affect the formula for gravity. The formula is based on the masses and distance between objects, not the size of the space they are in.

5. How does the formula for gravity in a virtual solar system differ from the formula for gravity in real life?

The formula for gravity in a virtual solar system is the same as in real life. However, in a virtual solar system, the masses and distances may be scaled down in order to fit within the virtual space, resulting in a different numerical value for the force of gravity.

Similar threads

  • Programming and Computer Science
Replies
2
Views
2K
  • Introductory Physics Homework Help
Replies
18
Views
1K
  • Astronomy and Astrophysics
Replies
6
Views
1K
  • Astronomy and Astrophysics
Replies
1
Views
1K
Replies
2
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
800
Replies
15
Views
2K
  • Astronomy and Astrophysics
Replies
19
Views
10K
  • Programming and Computer Science
Replies
4
Views
1K
Replies
2
Views
599
Back
Top