Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vulnerability related to the formula of universal gravitation #1284

Open
MLH-AIDS opened this issue Apr 3, 2024 · 0 comments
Open

Vulnerability related to the formula of universal gravitation #1284

MLH-AIDS opened this issue Apr 3, 2024 · 0 comments

Comments

@MLH-AIDS
Copy link

MLH-AIDS commented Apr 3, 2024

I made such a function according to the formula and called it before updating.

function applyG(body){
    for(let i of Composite.allBodies(engine.world)){
        if(i===body){
            continue;
        }
        let F=__gravitational__*body.mass*i.mass/(distance2body(body,i)**2);
        let p=Vector.sub(i.position,body.position);
        let Fg=Vector.mult(p,F/(p.x**2+p.y**2)**0.5);
        body.force.x+=Fg.x
        body.force.y+=Fg.y
    }
    function distance2body(b1,b2){
        let s=Vector.sub(b1.position,b2.position);
        return (s.x**2+s.y**2)**0.5;
    }
}
Events.on(runner, "beforeUpdate", ()=>{
  for(let i of Composite.allBodies(engine.world)){
    applyG(i)
  }
});

But when I set a rigid body and set a linear velocity to make it run on a circular track, the linear velocity always seems too small.

Body.setVelocity(ball,{x:(__gravitational__*earth.mass/distance2body(earth.position,ball.position))**0.8,y:0})

When near a celestial body, the calculated linear velocity is approximately 70, but in reality, a linear velocity of 1100 is needed to make it orbit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant