+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: Orbit Simulator

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

    Default Orbit Simulator

    This expression can simulate up to six planets orbiting in space without hitting the tick quota. It uses Newton's formula for the gravity and some vector math for the rest. It can be pretty fun to put in random values to see if any interesting orbits come out of it. If you find any interesting orbit patterns, be sure to post them here. This is my first expression using loops and arrays, so be sure to post if you see any way I could improve or optimize this. ^_^

    Code:
    @name Orbiter
    @persist Ent:entity GravConstant Masses:array Positions:array
    @persist Velocities:array Forces:array Colors:array Planets
    if(first()|duped()){
        runOnTick(1)
        #All values between this line
        GravConstant = 1
        Planets = 6
        #Planet 1
        Masses[1,number] = 1000
        Positions[1,vector] = vec(0,0,100)
        Velocities[1,vector] = vec(0,0,1)
        Colors[1,vector] = vec(255,0,0)
        #Planet 2
        Masses[2,number] = 100
        Positions[2,vector] = vec(100,0,100)
        Velocities[2,vector] = vec(2,2,0)
        Colors[2,vector] = vec(0,255,0)
        #Planet 3
        Masses[3,number] = 100
        Positions[3,vector] = vec(-100,0,100)
        Velocities[3,vector] = vec(-2,-2,0)
        Colors[3,vector] = vec(0,0,255)
        #Planet 4
        Masses[4,number] = 100
        Positions[4,vector] = vec(-200,0,100)
        Velocities[4,vector] = vec(-2,-2,0)
        Colors[4,vector] = vec(255,255,0)
        #Planet 5
        Masses[5,number] = 100
        Positions[5,vector] = vec(200,0,100)
        Velocities[5,vector] = vec(-2,-2,0)
        Colors[5,vector] = vec(255,0,255)
        # Planet 6
        Masses[6,number] = 100
        Positions[6,vector] = vec(300,0,100)
        Velocities[6,vector] = vec(-2,-2,0)
        Colors[6,vector] = vec(0,255,255)
        #and this line can be changed
        Ent = entity()
        Count = 1
        while(Count<=Planets){
            holoCreate(Count)
            holoModel(Count,"icosphere3")
            holoColor(Count,Colors[Count,vector])
            holoScale(Count,log10(Masses[Count,number])*vec(1,1,1))
            holoEntity(Count):setTrails(40,0,25,"trails/laser",Colors[Count,vector],100)
            Count=Count+1
        }
    }else{
        Count = 1
        while(Count<=Planets){
            Count2 = 1
            Forces[Count,vector] = vec()
            while(Count2<=Planets){
                if(Count!=Count2){
                    Force = (GravConstant*Masses[Count2,number])/
                    (Positions[Count,vector]:distance(Positions[Count2,vector])^2)
                    Forces[Count,vector] = Forces[Count,vector]+(Positions[Count2,vector]-Positions[Count,vector]):normalized()*Force
                }
                Count2=Count2+1
            }
            Count=Count+1
        }
        Count=1
        while(Count<=Planets){
            Oldpos = Positions[Count,vector]
            Positions[Count,vector] = Velocities[Count,vector]+Positions[Count,vector]+Forces[Count,vector]
            Velocities[Count,vector] = Positions[Count,vector]-Oldpos
            holoPos(Count,Ent:pos()+Positions[Count,vector])
            Count=Count+1
        }
    }
    Pictures!

    Last edited by SamPerson12345; 09-06-2009 at 07:15 PM.
    I code best at 3 A.M.

  2. #2
    Wiremod Helper Lyinginbedmon's Avatar
    Join Date
    Mar 2009
    Location
    England
    Posts
    2,659

    Default Re: Orbit Simulator

    It'd be easier to tell what it actually does if there were trails attached to the planets. I also recommend using either "sphere3" or "icosphere3" over "sphere", as the model is much smoother in both cases.

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

    Default Re: Orbit Simulator

    Quote Originally Posted by Lyinginbedmon View Post
    It'd be easier to tell what it actually does if there were trails attached to the planets. I also recommend using either "sphere3" or "icosphere3" over "sphere", as the model is much smoother in both cases.
    Ok, Those would be fairly easy to implement. I'll start working on it now.
    I code best at 3 A.M.

  4. #4
    Ursus maritimus Drunkie's Avatar
    Join Date
    Feb 2009
    Location
    Canada
    Posts
    5,645
    Blog Entries
    1

    Default Re: Orbit Simulator

    It doesn't look so visually appealing. You should get creative with trails and model attachments/parent's.

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

    Default Re: Orbit Simulator

    I added trails, and used a better model. It does look pretty nice.




    I'll update the code in the first post.
    I code best at 3 A.M.

  6. #6
    Wire Amateur Undomian's Avatar
    Join Date
    Nov 2008
    Posts
    87

    Default Re: Orbit Simulator

    I'd hate to be living on those colliding planets.

  7. #7
    Wire Noob Phillypos's Avatar
    Join Date
    Jul 2008
    Posts
    27

    Default Re: Orbit Simulator

    Is it possible to make the colliding planets explode or merge to a bigger one?

  8. #8
    Wire Amateur Undomian's Avatar
    Join Date
    Nov 2008
    Posts
    87

    Default Re: Orbit Simulator

    I would imagine that it would be possible to do that simply by checking the distances between the two planets in question, then making use of holoDelete and holoCreate. It wouldn't be too difficult.

  9. #9
    Wirererer chiss's Avatar
    Join Date
    Feb 2008
    Posts
    207

    Default Re: Orbit Simulator

    Quote Originally Posted by Undomian View Post
    I would imagine that it would be possible to do that simply by checking the distances between the two planets in question, then making use of holoDelete and holoCreate. It wouldn't be too difficult.
    Would not!

    Just need two nested while loops checking for collisions between every pair of planets, if collision, delete the 2 holos and create a new one with the sum of their velocity/mass ratio at combined size. Wazoo



  10. #10
    Wiremod Helper Lyinginbedmon's Avatar
    Join Date
    Mar 2009
    Location
    England
    Posts
    2,659

    Default Re: Orbit Simulator

    Quote Originally Posted by chiss View Post
    Would not!

    Just need two nested while loops checking for collisions between every pair of planets, if collision, delete the 2 holos and create a new one with the sum of their velocity/mass ratio at combined size. Wazoo
    Or delete one and rescale the remainder.

    The Olympus Technologies drones, totally not SkyNet in Gmod form.
    Cronus: The Ultimate Drone, definitely SkyNet in Gmod form.
    The gBrain Project, the drone controls system that thinks it's better than you

+ Reply to Thread
Page 1 of 2 12 LastLast

Similar Threads

  1. Making an orbit simulator
    By SamPerson12345 in forum Expression 2 Discussion & Help
    Replies: 7
    Last Post: 09-05-2009, 12:03 PM
  2. Orbit help.
    By darkpasts in forum Expression 2 Discussion & Help
    Replies: 15
    Last Post: 07-28-2009, 08:55 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