+ Reply to Thread
Results 1 to 8 of 8

Thread: Making an orbit simulator

  1. #1
    Wirererer SamPerson12345 is on a distinguished road SamPerson12345's Avatar
    Join Date
    Jun 2007
    Posts
    157

    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 08:40 AM.
    I code best at 3 A.M.

  2. #2
    Wire Sofaking Vbitz will become famous soon enough Vbitz's Avatar
    Join Date
    Feb 2009
    Location
    NZ
    Posts
    527

    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 is on a distinguished road Joshieballz's Avatar
    Join Date
    Feb 2009
    Location
    Hull
    Posts
    86

    Default Re: Making an orbit simulator

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

    e2 Code:
    1. @name Planets
    2. @inputs
    3. @outputs
    4. @persist Counter Spin
    5. @trigger all
    6.  
    7. interval(10)
    8. if(first()){
    9. holoCreate(1)
    10. holoCreate(2)
    11. holoCreate(3)
    12. }
    13.  
    14. Spin+=2
    15. Counter++
    16.  
    17. Sinearth = sin(Counter*1.2)
    18. Cosearth = cos(Counter*1.2)
    19. SinMoon = sin(Counter*10)
    20. CosMoon = cos(Counter*10)
    21.  
    22. #Sun
    23. Pos1 = entity():pos() + entity():up()*50
    24. holoPos(1,Pos1)
    25. holoModel(1,"sphere3")
    26. holoColor(1,vec(255,255,0))
    27. holoScale(1,vec(5,5,5))
    28. holoMaterial(1,"debug/debugdrawflat")
    29.  
    30. #Earth
    31. Pos2 = entity():pos() + entity():up()*50 + vec(Sinearth*100,Cosearth*100,0)
    32. holoPos(2,Pos2 )
    33. holoModel(2,"sphere3")
    34. holoColor(2,vec(0,255,150))
    35. holoScale(2,vec(1.2,1.2,1.2))
    36. holoAng(2,ang(0,Spin,0))
    37. holoMaterial(2,"debug/debugdrawflat")
    38.  
    39. #Moon
    40. Pos3 = Pos2 + vec( SinMoon*15,CosMoon*15,0)
    41. holoPos(3,Pos3)
    42. holoModel(3,"sphere3")
    43. holoColor(3,vec(255,255,255))
    44. holoScale(3,vec(0.2,0.2,0.2))
    45. holoAng(3,ang(0,Spin,0))
    46. holoMaterial(3,"debug/debugdrawflat")



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

  4. #4
    Wire Sofaking Whosdr will become famous soon enough Whosdr's Avatar
    Join Date
    Dec 2008
    Posts
    1,376

    Default Re: Making an orbit simulator

    Is it gravitationally correct?
    Whatever you do, do not read this!

  5. #5
    Wirererer SamPerson12345 is on a distinguished road SamPerson12345's Avatar
    Join Date
    Jun 2007
    Posts
    157

    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
    Wire Sofaking Whosdr will become famous soon enough Whosdr's Avatar
    Join Date
    Dec 2008
    Posts
    1,376

    Default Re: Making an orbit simulator

    Force = (GravConstant*Mass)/(Pos:distance(vec(0,0,100))^2)
    You did *Mass nor *Mass1 or *Mass2
    Whatever you do, do not read this!

  7. #7
    Wirererer SamPerson12345 is on a distinguished road SamPerson12345's Avatar
    Join Date
    Jun 2007
    Posts
    157

    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 is on a distinguished road Solece's Avatar
    Join Date
    Jul 2008
    Posts
    449

    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
    You have to love chatbots:
    Ruηeηeǿ: who is more pretty, solece or me?
    Loki: Your mom.

+ Reply to Thread

Similar Threads

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