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

Thread: Orbit Simulator

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

    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 06:15 PM.
    I code best at 3 A.M.

  2. #2
    Drone Madman
    Lyinginbedmon has a spectacular aura about Lyinginbedmon has a spectacular aura about Lyinginbedmon's Avatar
    Join Date
    Mar 2009
    Location
    England
    Posts
    2,651

    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
    Lurker SamPerson12345 is on a distinguished road SamPerson12345's Avatar
    Join Date
    Jun 2007
    Posts
    278

    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
    <title>eh?</title>


    Drunkie is a jewel in the rough Drunkie is a jewel in the rough Drunkie is a jewel in the rough Drunkie's Avatar
    Join Date
    Feb 2009
    Location
    Canada
    Posts
    2,410

    Default Re: Orbit Simulator

    It doesn't look so visually appealing. You should get creative with trails and model attachments/parent's.
    Tutorials: Wire GPU | 3D Projections

    Black Phoenix: drun KIE
    Black Phoenix: PLEASE CONFIRM THIS MESSAGE DRUN KIE
    Drunkie: confirmed
    Black Phoenix: THE INTERGALACTIC CONTINIUM WANTS DRUN KIE TO GO ON A SPECIAL MISSION
    Black Phoenix: this will be AN EASY mission TO THE UNKNOWN AND beyonD
    <HP> ... I can't believe I'm talking to a fucking script at 4 am

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

    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
    Lurker Undomian is on a distinguished road 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 is on a distinguished road 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
    Lurker Undomian is on a distinguished road 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
    Lurker chiss will become famous soon enough chiss's Avatar
    Join Date
    Feb 2008
    Posts
    209

    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
    Drone Madman
    Lyinginbedmon has a spectacular aura about Lyinginbedmon has a spectacular aura about Lyinginbedmon's Avatar
    Join Date
    Mar 2009
    Location
    England
    Posts
    2,651

    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

    Need to learn how to make your own drones? Check out Drones with a Mad Scientist for my tutorials on how to do it.

+ Reply to Thread
Page 1 of 2 1 2 LastLast

Similar Threads

  1. Making an orbit simulator
    By SamPerson12345 in forum Expression 1 & 2
    Replies: 7
    Last Post: 09-05-2009, 11:03 AM
  2. Orbit help.
    By darkpasts in forum Expression 1 & 2
    Replies: 15
    Last Post: 07-28-2009, 07:55 PM
  3. Help with orbit
    By sadow200 in forum Expression 1 & 2
    Replies: 11
    Last Post: 05-03-2009, 02:14 PM
  4. Cam Controller Orbit
    By Techni in forum Technical Support
    Replies: 4
    Last Post: 09-21-2008, 07:35 AM
  5. Orbit?
    By -|Raveness|- in forum Technical 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
proceed-collector
proceed-collector
proceed-collector
proceed-collector
linguistic-parrots
linguistic-parrots
linguistic-parrots
linguistic-parrots