+ Reply to Thread
Results 1 to 8 of 8

Thread: Making an orbit simulator

  1. #1
    Wirererer SamPerson12345's Avatar
    Join Date
    Jun 2007
    Posts
    277

    Default Making an orbit simulator

    I'm currently working on an orbital simulator based on Newton's gravity equation, where you can set the mass and initial velocities of multiple planets. It's working really well so far, but I would like it if someone would look my code over and make sure it implements the laws of physics properly before I add all of the arrays and loops necessary for this to work. It would also be a great help if someone would give me some tips on optimization, because I'm a bit worried about keeping this efficient enough to calculate the gravity between five or six planets at once.
    Here's my code so far:
    Code:
    @name Orbiter
    @inputs 
    @outputs
    @persist Ent:entity GravConstant Pos:vector Vel:vector Mass1 Mass2
    @trigger 
    if(first()|duped()){
        runOnTick(1)
        holoCreate(1)
        holoCreate(2)
        holoModel(1,"sphere")
        holoModel(2,"sphere")
        holoScale(1,vec(2,2,2))
        holoScale(2,vec(1,1,1))
        Ent = entity()
        GravConstant = 1
        Pos = vec(100,0,100)
        Mass1 = 500
        Mass2 = 1
        Vel = vec(-1,2,1)
    }
    holoPos(1,Ent:pos()+vec(0,0,100))
    Force = (GravConstant*Mass1)/(Pos:distance(vec(0,0,100))^2)
    Oldpos = Pos
    Pos = Vel+Pos+(vec(0,0,100)-Pos):normalized()*Force
    Vel = Pos-Oldpos
    holoPos(2,Ent:pos()+Pos)
    As soon as I get the loops going, that stationary planet will be able to move.
    Any help at all would be greatly appreciated. ^_^
    Last edited by SamPerson12345; 09-05-2009 at 09:40 AM.
    I code best at 3 A.M.

  2. #2
    Wire Sofaking Vbitz's Avatar
    Join Date
    Feb 2009
    Location
    NZ
    Posts
    685

    Default Re: Making an orbit simulator

    Very nice work, i am no e2 programmer but i am learning but just look on wikipedia for all your physics related things

    Sorry if it is broken but here is the forumla
    Questions, Comments and Concerns about any of
    my posts can be directed to my website which is at
    http://vbitz.wordpress.com on the comments post

    Quote Originally Posted by Bull View Post
    As example Jat Goodwin is "the official bastard of wiremod", but that isn't true.. He's very cute and huggable like a little puppy.

  3. #3
    Wiremod Supporter Joshieballz's Avatar
    Join Date
    Feb 2009
    Location
    Hull
    Posts
    97

    Default Re: Making an orbit simulator

    i made a orbiter.
    but i used sin() and cos()

    [highlight=e2]

    @name Planets
    @inputs
    @outputs
    @persist Counter Spin
    @trigger all

    interval(10)
    if(first()){
    holoCreate(1)
    holoCreate(2)
    holoCreate(3)
    }

    Spin+=2
    Counter++

    Sinearth = sin(Counter*1.2)
    Cosearth = cos(Counter*1.2)
    SinMoon = sin(Counter*10)
    CosMoon = cos(Counter*10)

    #Sun
    Pos1 = entity()os() + entity():up()*50
    holoPos(1,Pos1)
    holoModel(1,"sphere3")
    holoColor(1,vec(255,255,0))
    holoScale(1,vec(5,5,5))
    holoMaterial(1,"debug/debugdrawflat")

    #Earth
    Pos2 = entity()os() + entity():up()*50 + vec(Sinearth*100,Cosearth*100,0)
    holoPos(2,Pos2 )
    holoModel(2,"sphere3")
    holoColor(2,vec(0,255,150))
    holoScale(2,vec(1.2,1.2,1.2))
    holoAng(2,ang(0,Spin,0))
    holoMaterial(2,"debug/debugdrawflat")

    #Moon
    Pos3 = Pos2 + vec( SinMoon*15,CosMoon*15,0)
    holoPos(3,Pos3)
    holoModel(3,"sphere3")
    holoColor(3,vec(255,255,255))
    holoScale(3,vec(0.2,0.2,0.2))
    holoAng(3,ang(0,Spin,0))
    holoMaterial(3,"debug/debugdrawflat")
    [/highlight]



    If u have any questions or concerns contact me on www.tuggaming.co.uk

  4. #4
    billywitchdoctor.com Whosdr's Avatar
    Join Date
    Dec 2008
    Posts
    2,300

    Default Re: Making an orbit simulator

    Is it gravitationally correct?
    .siht daer ot gniyrt emit detsaw ev'uoY

  5. #5
    Wirererer SamPerson12345's Avatar
    Join Date
    Jun 2007
    Posts
    277

    Default Re: Making an orbit simulator

    Quote Originally Posted by Whosdr View Post
    Is it gravitationally correct?
    That's what I'm trying for. You can edit the values in the expression and it will come up with a different orbit, or the planet may even break free of the sun's gravity.
    I code best at 3 A.M.

  6. #6
    billywitchdoctor.com Whosdr's Avatar
    Join Date
    Dec 2008
    Posts
    2,300

    Default Re: Making an orbit simulator

    Force = (GravConstant*Mass)/(Pos:distance(vec(0,0,100))^2)
    You did *Mass nor *Mass1 or *Mass2
    .siht daer ot gniyrt emit detsaw ev'uoY

  7. #7
    Wirererer SamPerson12345's Avatar
    Join Date
    Jun 2007
    Posts
    277

    Default Re: Making an orbit simulator

    Quote Originally Posted by Whosdr View Post
    Force = (GravConstant*Mass)/(Pos:distance(vec(0,0,100))^2)
    You did *Mass nor *Mass1 or *Mass2
    Yes, I know. I did that because I think the gravitational force would be spread out through all of the mass in the planet, so you only need the mass of what it's orbiting around to find out how the gravity would change the velocity. Also, If I had put in both masses, then objects with different masses would fall at different speeds.
    I code best at 3 A.M.

  8. #8
    Wire Sofaking Solece's Avatar
    Join Date
    Jul 2008
    Location
    Pittsburgh, PA
    Posts
    673

    Default Re: Making an orbit simulator

    I actually already made a basic orbiter, using props though, not holos. The Source engine pretty much does all the work for me.
    Heres the code, feel free to modify it. Just give me some credit.
    Code:
    @name Haloguy's Orbiter
    @inputs 
    @outputs B
    @persist R:array A
    @trigger 
    
    interval(1)
    E=entity()
    O=owner()
    Rand=(cos(curtime()*10)*127.5)+127.5
    timer("update",500)
    if(first()){holoCreate(1)}
    if(clk("update")){
        holoScale(1,vec(15,15,15))
        holoModel(1,"sphere3")
    findInSphere(E:pos(),100000)
    findClipToClass("prop_physics")
    findIncludePlayerProps(O)
    R=findToArray()
    }
    holoPos(1,E:pos())
    A++
    if(A>R:count()){A=0}
    Prop=R:entity(A)
    Vec=E:pos()-Prop:pos()
    Prop:applyForce(Vec*Prop:mass()/600)
    holoColor(1,vec(Rand,255-Rand,Rand))
    B=R:count()
    Note that this was made for spacebuild, so it will only work for props if they have no gravity. You do have to manually throw the prop into orbit though ^_^

+ Reply to Thread

Similar Threads

  1. Orbit help.
    By darkpasts in forum Expression 2 Discussion & Help
    Replies: 15
    Last Post: 07-28-2009, 08:55 PM
  2. Need help making a chip orbit
    By crafton in forum Expression 2 Discussion & Help
    Replies: 9
    Last Post: 07-02-2009, 03:42 PM
  3. Help with orbit
    By sadow200 in forum Expression 2 Discussion & Help
    Replies: 11
    Last Post: 05-03-2009, 03:14 PM
  4. Cam Controller Orbit
    By Techni in forum Installation and Malfunctions Support
    Replies: 4
    Last Post: 09-21-2008, 08:35 AM
  5. Orbit?
    By -|Raveness|- in forum Installation and Malfunctions Support
    Replies: 1
    Last Post: 04-11-2008, 07:18 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
proceed-collector
proceed-collector
proceed-collector
proceed-collector
linguistic-parrots
linguistic-parrots
linguistic-parrots
linguistic-parrots