Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Solar System Simulation
Index -> General Programming
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Cervantes




PostPosted: Fri Oct 15, 2004 3:39 pm   Post subject: Solar System Simulation

I've recently been thinking about making a solar system simulation, using Newtonian physics. Could anyone perhaps give me a quick rundown of what I'll need to know (in terms of the physics, not the coding Wink)
Sponsor
Sponsor
Sponsor
sponsor
josh




PostPosted: Fri Oct 15, 2004 3:51 pm   Post subject: (No subject)

by simulation do you mean a mathematical one or a 2D or a 3D one???

that is a sick idea by the way Very Happy Idea
Cervantes




PostPosted: Fri Oct 15, 2004 3:58 pm   Post subject: (No subject)

2D, using math.
Just the basics, at first.
josh




PostPosted: Fri Oct 15, 2004 4:12 pm   Post subject: (No subject)

I might have some books that mention it, I will try and find some info
Martin




PostPosted: Sat Oct 16, 2004 2:15 am   Post subject: (No subject)

Newton's equations are wrong.
Cervantes




PostPosted: Sat Oct 16, 2004 6:30 am   Post subject: (No subject)

I know, but I still want to use them.
Using Newton's equations, don't we end up with circular orbits? And with the General Theory of Relativity, we end up with elliptical oribts?
Andy




PostPosted: Sat Oct 16, 2004 1:41 pm   Post subject: (No subject)

just use centripetal acceleration formulas... where MAc=Fg... with Ac=V^2/r or Ac=4pi^2rf^2
Martin




PostPosted: Sun Oct 17, 2004 1:29 am   Post subject: (No subject)

Yeah, ignore friction (it's physics, real world forces don't apply), and just give them an initial velocity perpindicular to the object they're to be orbitting, and it should work. Remember, planets pull on each other Wink

And for god's sake, make it OO.
Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: Mon Oct 25, 2004 6:37 pm   Post subject: (No subject)

dodge_tomahawk wrote:
just use centripetal acceleration formulas... where MAc=Fg... with Ac=V^2/r or Ac=4pi^2rf^2

would you mind explaining that a little more please? Confused

Martin wrote:
Remember, planets pull on each other "wink:

Oh god, I know! I plan on making an initialization section of the program where you can edit the mass of the planets (along with various other things), in which case some funky things could happen.. perhaps with the right mass, the solar system will orbit earth! Laughing

Tony showed me a way of creating a gravity field a while back, and it worked well enough for its purpose at that time, but what would it do in a solar system simulation?

code:

View.Set ("graphics:600;600,nobuttonbar")
var ball :
    record
        x, y, dx, dy, GFdist, GFxdist, GFydist, GFangle, GFforce : real
    end record

ball.x := 300
ball.y := 500
ball.dx := 0.5
ball.dy := 0

var gravityfield :
    record
        x, y, strength : int
    end record

gravityfield.x := 300
gravityfield.y := 300
gravityfield.strength := 150

const highestspeed := 3
const ballradius := 6

function MathDistance (x1, y1, x2, y2 : real) : real
    result (((x2 - x1) ** 2) + ((y2 - y1) ** 2)) ** 0.5
end MathDistance

setscreen ("offscreenonly")
loop
    cls

    ball.x += ball.dx
    ball.y += ball.dy

    if ball.x > maxx - ballradius or ball.x < ballradius then
        ball.dx := -ball.dx
        ball.x += (2 * ball.dx)       %move it 2 steps ahead to help prevent sticking
    end if
    if ball.y > maxy - ballradius or ball.y < ballradius then
        ball.dy := -ball.dy
        ball.y += (2 * ball.dy)      %move it 2 steps ahead to help prevent sticking
    end if


    %%%%%%%%%GRAVITY FIELD EFFECTS%%%%%%
    ball.GFdist := MathDistance (gravityfield.x, gravityfield.y, ball.x, ball.y)
    ball.GFforce := gravityfield.strength * (1 / (ball.GFdist * ball.GFdist))
    if ball.x not= gravityfield.x then
        ball.GFxdist := gravityfield.x - ball.x
        ball.GFydist := gravityfield.y - ball.y
        ball.GFangle := arctand (ball.GFxdist / ball.GFydist)
    else
        if ball.y > gravityfield.y then
            ball.GFangle := 90
        else
            ball.GFangle := 270
        end if
    end if
    if ball.x < gravityfield.x then
        ball.GFangle := ball.GFangle + 180
    end if
    ball.dx -= ball.GFforce * cosd (ball.GFangle)
    ball.dy -= ball.GFforce * sind (ball.GFangle)
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    if ball.dx > highestspeed then
        ball.dx := highestspeed
    elsif ball.dx < -highestspeed then
        ball.dx := -highestspeed
    end if
    if ball.dy > highestspeed then
        ball.dy := highestspeed
    elsif ball.dy < -highestspeed then
        ball.dy := -highestspeed
    end if

    drawfilloval (round (ball.x), round (ball.y), ballradius, ballradius, red)


    drawfilloval (gravityfield.x, gravityfield.y, 11, 11, black)
    View.Update
    delay (10)
end loop


See how the ball goes right, then left, then back? Gravity shouldn't do that! Surprised or should it? One of those good ol' fashioned "Educational Films" showed that our solar system is not revolving around the centre of the galaxy in a 2D plane, it is revolving around it and going up and down as well. Picture the Milky Way as a disc, totally flat (close enough..) then the sun and our solar system would be, at one point, below that disc, and then, as time passes, it moves up, passing through the disc, continues upwards, reaches its peak, and then comes back down. Kinda like a sine wave. Razz
Why, oh, why, is that? Eh
Tony




PostPosted: Mon Oct 25, 2004 6:48 pm   Post subject: (No subject)

well you need to give the ball a little push at first to make it spin around the center...

code:

ball.dx := 1.75
ball.dy := 0

gravityfield.strength := 200

that works out much nicer Wink though the code is still not perfect, as you can tell yourself from the resulting animation... Though it was enough back in the day Laughing
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Cervantes




PostPosted: Mon Oct 25, 2004 6:51 pm   Post subject: (No subject)

Oh, I know, in order to get the orbit it would need that push. But, what I was trying to show, is that, without the push, you'd think it would go straight towards the gravity field, but in fact it wavers back and forth on its way there.
Catalyst




PostPosted: Mon Oct 25, 2004 7:42 pm   Post subject: (No subject)

this might be of some interest


grav.rar
 Description:

Download
 Filename:  grav.rar
 Filesize:  4.32 KB
 Downloaded:  185 Time(s)

Paul




PostPosted: Mon Oct 25, 2004 10:20 pm   Post subject: (No subject)

Orbits as I understand them are the result of a warping of spacetime due to a large mass present. Since there isn't friction to slow an object down, and given an initial velocity, the object just follows the simplest path, in an orbit. And wasn't there the gravitational force formula, y'know with the mass, distance and the universal gravitational constant. Posted Image, might have been reduced in size. Click Image to view fullscreen.
It doesn't sound easy though, but you like math Wink

and if you look at catalysts program wouldn't the direction and magnitude of the force being exerted on the moving circles have to be somehow balanced with the circle's initial velocity to have an orbit?
Cervantes




PostPosted: Tue Oct 26, 2004 5:53 pm   Post subject: (No subject)

What is the universal gravitational constant?
And, catalyst, is what you posted this only open source instead of .exe? My winRAR hates me, and gives me annoying error messages whenever I try to extract something. Could you, or anyone willing, perhaps send it to me as a winzip?
I don't want to get offtopic here, but does anyone know where to get a free full version of winRAR (not a trail version)?
Andy




PostPosted: Tue Oct 26, 2004 6:17 pm   Post subject: (No subject)

6.67300 × 10-11 m3 kg-1 s-2 kepler discovered that
Display posts from previous:   
   Index -> General Programming
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 20 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: