admin管理员组文章数量:1414621
Clip of wonky orbit
I made a rudimentary (I'm still extremely proud of it) orbital sim. The satellite does not go around the planet on the second pass the same way it went around on the first pass. Its periapsis is constantly moving, not unlike orbital precession. I would think it actually is orbital precession, but there are no other orbital bodies in the simulation. The satellite exerts no force back on the Earth. Is it a problem with my code or is this a real phenomenon? The code below are the only lines that manage the orbital physics.
public static float Gravity(Transform m2Loc, Rigidbody m1Mass, Rigidbody m2Mass, float gravityConstant)
{
float force = (m1Mass.mass * m2Mass.mass) / MathF.Pow(m2Loc.position.magnitude, 2) * gravityConstant;
return force;
}
i.mass.AddForce(i.pos.position * -1 * Equations.Gravity(i.pos, planetMass, i.mass, gravity), ForceMode.Force);
The pink is the satellite’s trail. The gravitational equation is used F=(G*M1*M2)/R^2
, except G is 1. The Earth has a mass of 1000, the ship with a mass of 10. Force is applied to the ship using Rigidbody.AddForce
every frame under FixedUpdate()
. The entire script.
EDIT:
I let the simulation run for a bit and I see that the orbits are NOT random, because A: The orbits never exceed or go below a certain altitude and B: The orbits NEVER deviate from their inclination.
Still need an answer, though.
Clip of wonky orbit
I made a rudimentary (I'm still extremely proud of it) orbital sim. The satellite does not go around the planet on the second pass the same way it went around on the first pass. Its periapsis is constantly moving, not unlike orbital precession. I would think it actually is orbital precession, but there are no other orbital bodies in the simulation. The satellite exerts no force back on the Earth. Is it a problem with my code or is this a real phenomenon? The code below are the only lines that manage the orbital physics.
public static float Gravity(Transform m2Loc, Rigidbody m1Mass, Rigidbody m2Mass, float gravityConstant)
{
float force = (m1Mass.mass * m2Mass.mass) / MathF.Pow(m2Loc.position.magnitude, 2) * gravityConstant;
return force;
}
i.mass.AddForce(i.pos.position * -1 * Equations.Gravity(i.pos, planetMass, i.mass, gravity), ForceMode.Force);
The pink is the satellite’s trail. The gravitational equation is used F=(G*M1*M2)/R^2
, except G is 1. The Earth has a mass of 1000, the ship with a mass of 10. Force is applied to the ship using Rigidbody.AddForce
every frame under FixedUpdate()
. The entire script.
EDIT:
I let the simulation run for a bit and I see that the orbits are NOT random, because A: The orbits never exceed or go below a certain altitude and B: The orbits NEVER deviate from their inclination.
Still need an answer, though.
Share Improve this question edited Feb 22 at 2:38 Privvet asked Feb 21 at 5:09 PrivvetPrivvet 214 bronze badges 7 | Show 2 more comments1 Answer
Reset to default 0It seems to be because two variables for the gravity equation that I used (G = 1, M1 = 1000)
were not best for the scale of my simulation.
I'm no orbital physicist, so I can't explain WHY this fixed it exactly, but I changed the Gravitational Constant G to 5 * 10^-3
and the mass of the Earth to 1 * 10^9
. I guess this setup more closely resembled real life scales, so gravity needed less time to act correctly? This change led to objects' perigees and apogees staying closer to their original position for longer; less ridiculous orbital precession.
There's this value called the Standard Gravitational Parameter (SGP). It's defined as G(M1 + M2)
. Plugging in real life values, this number comes out to 3.986 * 10^14
. Using my original values, it came out to 1000. I then thought that manipulating my G and M1 so that it is closer to the real SGP would result in basically zero orbital precession but deviating from my fixed SGP of 5 * 10^6
in either direction led to more orbital precession.
So, that answers my question, but I do not understand the mathematical reasoning.
本文标签: cWhy does this orbiting object not perfectly repeat its orbitStack Overflow
版权声明:本文标题:c# - Why does this orbiting object not perfectly repeat its orbit? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745166375a2645704.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
float
based so that's already one huge source of inaccuracies (no clue what the physics engine uses internally though I would hopedouble
) ..And then as mentioned physics update only happens on fixed intervals .. which you can try to reduce of course. – derHugo Commented Feb 21 at 8:38