Three-body-problem in3d

Three-body-problem in3d preview image

2 collaborators

Default-person Zain Alsharari (Author)
Claudio Pavani (Team member)

Tags

(This model has yet to be categorized with any tags)
Visible to everyone | Changeable by the author
Model was written in NetLogo 3D 6.1.1 • Viewed 81 times • Downloaded 6 times • Run 0 times
Download the 'Three-body-problem in3d' modelDownload this modelEmbed this model

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)


## WHAT IS IT?

This is an example that demonstrates changing perspectives in NetLogo 3D.

Comments and Questions

Please start the discussion about this model! (You'll first need to log in.)

Click to Run Model

breed [bodys body]


globals [ ; variavel global todos podem alterar
  turtle1
  turtle2
  turtle3
  force ; modulo do vetor força

; vetores do copo 1 em relação ao corpo 2
  fx1_2     ; x-component of force vector
  fy1_2     ; y-component of force vector
  fz1_2     ; z-component of force vector
; vetores do copo 1 em relação ao corpo 3
  fx1_3     ; x-component of force vector
  fy1_3     ; y-component of force vector
  fz1_3
; vetores do copo 2 em relação ao corpo 1
  fx2_1     ; x-component of force vector
  fy2_1     ; y-component of force vector
  fz2_1
; vetores do copo 2 em relação ao corpo 3
  fx2_3     ; x-component of force vector
  fy2_3     ; y-component of force vector
  fz2_3
; vetores do copo 3 em relação ao corpo 1
  fx3_1     ; x-component of force vector
  fy3_1     ; y-component of force vector
  fz3_1
; vetores do copo 3 em relação ao corpo 2
  fx3_2     ; x-component of force vector
  fy3_2     ; y-component of force vector
  fz3_2
  vx     ; x-component of velocity vector
  vy     ; y-component of velocity vector
  vz     ; z-component of velocity vector
]

to Clean

  ;; poem os valores padrao
ca
set X1 0
set Y1 0
set z1 0

set X2 5
set Y2 0
set z2 0

set X3 0
set Y3 4
set z3 0

set Mass1 1
set Mass2 1
set Mass3 1

set VelocityX1 0
set VelocityX2 0
set VelocityX3 0
set VelocityY1 0
set VelocityY2 0
set VelocityY3 0
set Velocityz1 0
set Velocityz2 0
set Velocityz3 0

  ;; plot standard position
    set-default-shape turtles "circle"
  create-turtles 1 [set turtle1 self set color green setxyz X1 Y1 Z1 set pen-size 1 pen-down ]
  create-turtles 1 [set turtle2 self set color blue setxyz X2 Y2 Z2 set pen-size 1 pen-down]
  create-turtles 1 [set turtle3 self set color white setxyz X3 Y3 z3 set pen-size 1 pen-down ]
end 

to Plot_bodies
  ca
    ;; plot standard position
    set-default-shape turtles "circle"
  create-turtles 1 [set turtle1 self set color green setxyz X1 Y1 Z1 set pen-size 1 pen-down ]
  create-turtles 1 [set turtle2 self set color blue setxyz X2 Y2 Z2 set pen-size 1 pen-down ]
  create-turtles 1 [set turtle3 self set color white setxyz X3 Y3 Z3 set pen-size 1 pen-down ]
end 

to Stable  ;; mostra um exemplo de orbita estavel dois sois e um planeta

clear-all
  ;; poem os valores padrao
ca
set X1 8
set Y1 25
set Z1 0

set X2 7
set Y2 25
set Z2 0

set X3 0
set Y3 0
set Z3 0

set VelocityX1 -0.2
set Velocityy1 0
set Velocityz1 0
set Velocityx2 -0.2
set VelocityY2 0
set Velocityz2 0.05
set Velocityx3 0
set Velocityy3 0
set VelocityZ3 0
set Mass1 0.055
set Mass2 0.0001
set Mass3 20

  ;; plot position
  set-default-shape turtles "circle"
  create-turtles 1 [set turtle1 self set color green setxyz X1 Y1 Z1 set pen-size 1 pen-down ]
  create-turtles 1 [set turtle2 self set color blue setxyz X2 Y2 Z2 set pen-size 1 pen-down]
  create-turtles 1 [set turtle3 self set color white setxyz X3 Y3 Z3 set pen-size 1 pen-down]
end 

to Stable_2
    ;; two planets and one sun
clear-all
  ;; set the default values
ca
set X1 -23
set Y1 0
set Z1 0
set X2 8
set Y2 0
set Z2 -1
set X3 0
set Y3 0
set Z3 1

set VelocityX1 0
set VelocityX2 0
set VelocityX3 0
set VelocityY1 1.5
set VelocityY2 3.5
set VelocityY3 0
set VelocityZ1 0.1
set VelocityZ2 0.6
set VelocityZ3 1

set Mass1 1
set Mass2 1
set Mass3 1000

  ;; plot position
  set-default-shape turtles "circle"
  create-turtles 1 [set turtle1 self set color green setxyz X1 Y1 Z1 set pen-size 1 pen-down ]
  create-turtles 1 [set turtle2 self set color blue setxyz X2 Y2 Z2 set pen-size 1 pen-down]
  create-turtles 1 [set turtle3 self set color white setxyz X3 Y3 Z3 set pen-size 1 pen-down]
end 

to go

; integration time an improvement that can be added in the future
;  every 0.1
;  [

  ; check if the bodies are in the field of view
  if turtle1 = nobody [ stop ]
   if turtle2 = nobody [ stop ]
   if turtle3 = nobody [ stop ]


    ;Calculate force
    ask turtle1 [
    set size 1
      update-force1_2
      update-force1_3



    ]


     ask turtle2 [
    set size 0.5
      update-force2_1
      update-force2_3


    ]


     ask turtle3 [
    set size 10
      update-force3_2
      update-force3_1



    ]



  ;; move the particles at the same time , to not influence the results
  ask turtle1 [move1]
ask turtle2 [move2]
  ask turtle3 [move3]
;
end 


; bode1

to update-force1_2
  ;body distance 1 to 2
   let r distance turtle2
  ; avoiding infinity
  if (r < 0.5 and r > -0.5) [set r 0.5]
  ;Calculating body force  1_2
  set force 0.1 * (Mass1 * Mass2)/(r ^ 2) ;; has been multiplied by 0.1 so the particles don't leave the field of view
 ; separating the force in the components x and y
 face turtle2
 set fx1_2 force * dx
 set fy1_2 force * dy
 set fZ1_2 force * dZ
end 

to update-force1_3
  ;body distance 1 to 2
   let r distance turtle3
  ; avoiding infinity
  if (r < 0.5 and r > -0.5) [set r 0.5]
  ;Calculating body force 1_2
  set force 0.1 * (Mass1 * Mass3)/(r ^ 2)
 ; separating the force in the components x e y
 face turtle3
 set fx1_3 force * dx
 set fy1_3 force * dy
 set fZ1_3 force * dZ
end 


; bode2

to update-force2_1
  ;body distance 2 ao 1
   let r distance turtle1
  ; avoiding infinity
  if (r < 0.5 and r > -0.5) [set r 0.5]
  ;Calculating body force 2_1 (we know that is equal to - body strength 1_2, but in doubt, let's calculate)
  set force 0.1 * (Mass2 * Mass1)/(r ^ 2)
 ; separating the force in the components x and y
 face turtle1
 set fx2_1 force * dx
 set fy2_1 force * dy
 set fZ2_1 force * dZ
end 

to update-force2_3
  ;body distance 2 to 3
   let r distance turtle3
  ; avoiding infinity
  if (r < 0.5 and r > -0.5) [set r 0.5]
  ;Calculating body force 2_3
  set force 0.1 * (Mass2 * Mass3)/(r ^ 2)
 ; separating the force in the components x and y
 face turtle3
 set fx2_3 force * dx
 set fy2_3 force * dy
 set fZ2_3 force * dZ
end 

; bode3

to update-force3_1
  ;body distance 3 to 1
   let r distance turtle1
  ; avoiding infinity
  if (r < 0.5 and r > -0.5) [set r 0.5]
  ;Calculating body force 3_1 (we know that is equal to - body strength 1_3)
  set force 0.1 * (Mass3 * Mass1)/(r ^ 2)
 ; separating the force in the components x and y
 face turtle1
 set fx3_1 force * dx
 set fy3_1 force * dy
 set fZ3_1 force * dZ
end 

to update-force3_2
  ;body distance 3 to 2
   let r distance turtle2
  ; avoiding infinity
  if (r < 0.5 and r > -0.5) [set r 0.5]
  ;Calculating body force 2_3 (we know that is equal to - body strength 3_2)
  set force 0.1 * (Mass3 * Mass2)/(r ^ 2)
 ; separating the force in the components x and y
 face turtle2
 set fx3_2 force * dx
 set fy3_2 force * dy
 set fZ3_2 force * dZ
end 

to move1 ; move the particles
  ;updates particle speed and adds force;; F=m.a, then have to divide by mass
  set VelocityX1 VelocityX1 + (fx1_2 / Mass1) + (fx1_3 / Mass1)
  set VelocityY1 VelocityY1 + (fy1_2 /  Mass1) + (fy1_3 /  Mass1)
  set VelocityZ1 VelocityZ1 + (fZ1_2 /  Mass1) + (fZ1_3 /  Mass1)

  ; disappears if it goes off the edge
  if abs (ycor + vy) > max-pycor or abs (xcor + vx) > max-pxcor or abs (zcor + vz) > max-pzcor [ die ]

  ; update particle position
    set X1 X1 + VelocityX1
    set Y1 Y1 + VelocityY1
    set Z1 Z1 + VelocityZ1
    setxyz X1 Y1 Z1
end 

to move2 ;  move the particles
  ;updates particle speed and adds force
  set VelocityX2 VelocityX2 + (fx2_1 / Mass2) + (fx2_3 / Mass2)
  set VelocityY2 VelocityY2 + (fy2_1 / Mass2) + (fy2_3 / Mass2)
  set VelocityZ2 VelocityZ2 + (fZ2_1 / Mass2) + (fZ2_3 / Mass2)

  ; disappears if it goes off the edge
  if abs (ycor + vy) > max-pycor or abs (xcor + vx) > max-pxcor or abs (zcor + vz) > max-pzcor [ die ]

  ; update particle position
    set X2 X2 + VelocityX2
    set Y2 Y2 + VelocityY2
    set Z2 Z2 + VelocityZ2
    setxyz X2 Y2 Z2
end 

to move3 ;  move the particles
  ;updates particle speed and adds force
  set VelocityX3 VelocityX3 + (fx3_1 / Mass3) + (fx3_2 / Mass3)
  set VelocityY3 VelocityY3 + (fy3_1 / Mass3) + (fy3_2 / Mass3)
  set VelocityZ3 VelocityZ3 + (fZ3_1 / Mass3) + (fZ3_2 / Mass3)

  ; disappears if it goes off the edge
  if abs (ycor + vy) > max-pycor or abs (xcor + vx) > max-pxcor or abs (zcor + vz) > max-pzcor[ die ]

  ; update particle position
    set X3 X3 + VelocityX3
    set Y3 Y3 + VelocityY3
    set Z3 Z3 + VelocityZ3
    setxyz X3 Y3 Z3
end 

to setup
  clear-all
  create-turtles 3
  [
  setxy random-xcor random-ycor
  ]
end 

There is only one version of this model, created over 3 years ago by Zain Alsharari.

Attached files

File Type Description Last updated
Three-body-problem in3d.png preview Preview for 'Three-body-problem in3d' over 3 years ago, by Zain Alsharari Download

This model does not have any ancestors.

This model does not have any descendants.