four-body-problem
Model was written in NetLogo 6.1.1
•
Viewed 76 times
•
Downloaded 11 times
•
Run 0 times
Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)
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 body1 body2 body3 body4 force ; vetores do copo 1 em relação ao corpo 2 fx1_2 ; x-component of force vector fy1_2 ; y-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 ; vetores do copo 2 em relação ao corpo 1 fx1_4 ; x-component of force vector fy1_4 ; y-component of force vector ; vetores do copo 2 em relação ao corpo 1 fx2_1 ; x-component of force vector fy2_1 ; y-component of force vector ; vetores do copo 2 em relação ao corpo 3 fx2_3 ; x-component of force vector fy2_3 ; y-component of force vector ; vetores do copo 3 em relação ao corpo 1 fx2_4 ; x-component of force vector fy2_4 ; y-component of force vector ; vetores do copo 2 em relação ao corpo 3 fx3_1 ; x-component of force vector fy3_1 ; y-component of force vector ; vetores do copo 3 em relação ao corpo 2 fx3_2 ; x-component of force vector fy3_2 ; y-component of force vector fx3_4 ; x-component of force vector fy3_4 ; y-component of force vector fx4_1 ; x-component of force vector fy4_1 ; y-component of force vector fx4_2 ; x-component of force vector fy4_2 ; y-component of force vector fx4_3 ; x-component of force vector fy4_3 ; y-component of force vector ; vetores do copo 3 em relação ao corpo 2 ; vetores do copo 3 em relação ao corpo 2 vx ; x-component of velocity vector vy ; y-component of velocity vector ] to Clean ;; poem os valores padrao ca set X1 0 set Y1 0 set X2 5 set Y2 0 set X3 0 set Y3 4 set X4 4 set Y4 0 set Mass1 1 set Mass2 1 set Mass3 1 set Mass4 1 set VelocityX1 0 set VelocityX2 0 set VelocityX3 0 set VelocityX4 0 set VelocityY1 0 set VelocityY2 0 set VelocityY3 0 set VelocityY4 0 ;; plot standard position set-default-shape turtles "circle" create-bodys 1 [set body1 self set color white setxy X1 Y1 set pen-size 1 pen-down ] create-bodys 1 [set body2 self set color yellow setxy X2 Y2 set pen-size 1 pen-down] create-bodys 1 [set body3 self set color red setxy X3 Y3 set pen-size 1 pen-down] create-bodys 1 [set body4 self set color green setxy X4 Y4 set pen-size 1 pen-down ] end to Plot_bodies ca ;; plot standard position set-default-shape turtles "circle" create-bodys 1 [set body1 self set color white setxy X1 Y1 set pen-size 1 pen-down ] create-bodys 1 [set body2 self set color yellow setxy X2 Y2 set pen-size 1 pen-down] create-bodys 1 [set body3 self set color red setxy X3 Y3 set pen-size 1 pen-down] create-bodys 1 [set body4 self set color blue setxy X4 Y4 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 -2 set Y1 0 set X2 2 set Y2 0 set X3 20 set Y3 0 set X4 -20 set Y4 0 set VelocityX1 0 set VelocityX2 0 set VelocityX3 0 set VelocityX4 0 set VelocityY1 0.1 set VelocityY2 -0.1 set VelocityY3 0.07 set VelocityY4 -0.07 set Mass1 1 set Mass2 1 set Mass3 0.1 set Mass4 0.1 ;; plot position set-default-shape turtles "circle" create-bodys 1 [set body1 self set color white setxy X1 Y1 set pen-size 1 pen-down ] create-bodys 1 [set body2 self set color yellow setxy X2 Y2 set pen-size 1 pen-down] create-bodys 1 [set body3 self set color red setxy X3 Y3 set pen-size 1 pen-down] create-bodys 1 [set body4 self set color blue setxy X3 Y3 set pen-size 1 pen-down] end to Stable_2 ;; three planets and one sun clear-all ;; set the default values ca set X1 -23 set Y1 0 set X2 8 set Y2 0 set X3 0 set Y3 0 set X4 0 set Y4 0 set VelocityX1 0 set VelocityX2 0 set VelocityX3 0 set VelocityX4 0 set VelocityY1 1.5 set VelocityY2 3.5 set VelocityY3 0 set VelocityY4 0 set Mass1 1 set Mass2 1 set Mass3 1000 set Mass4 1000 ;; plot position set-default-shape turtles "circle" create-bodys 1 [set body1 self set color white setxy X1 Y1 set pen-size 1 pen-down ] create-bodys 1 [set body2 self set color yellow setxy X2 Y2 set pen-size 1 pen-down] create-bodys 1 [set body3 self set color red setxy X3 Y3 set pen-size 1 pen-down] create-bodys 1 [set body3 self set color green setxy X4 Y4 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 body1 = nobody [ stop ] if body2 = nobody [ stop ] if body3 = nobody [ stop ] if body4 = nobody [ stop ] ;Calculate force ask body1 [ update-force1_2 update-force1_3 update-force1_4 ] ask body2 [ update-force2_1 update-force2_3 update-force2_4 ] ask body3 [ update-force3_2 update-force3_1 update-force3_4 ] ask body4 [ update-force4_1 update-force4_2 update-force4_3 ] ;; move the particles at the same time , to not influence the results ask body1 [move1] ask body2 [move2] ask body3 [move3] ask body4 [move4] ; end ; bode1 to update-force1_2 ;body distance 1 to 2 let r distance body2 ; 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 body2 set fx1_2 force * dx set fy1_2 force * dy end to update-force1_3 ;body distance 1 to 2 let r distance body3 ; 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 body3 set fx1_3 force * dx set fy1_3 force * dy end to update-force1_4 ;body distance 1 to 4 let r distance body4 ; avoiding infinity if (r < 0.5 and r > -0.5) [set r 0.5] ;Calculating body force 1_2 set force 0.1 * (Mass1 * Mass4)/(r ^ 2) ; separating the force in the components x e y face body4 set fx1_4 force * dx set fy1_4 force * dy end ; bode2 to update-force2_1 ;body distance 2 ao 1 let r distance body1 ; 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 body1 set fx2_1 force * dx set fy2_1 force * dy end to update-force2_3 ;body distance 2 to 3 let r distance body3 ; 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 body3 set fx2_3 force * dx set fy2_3 force * dy end to update-force2_4 ;body distance 2 to 4 let r distance body4 ; avoiding infinity if (r < 0.5 and r > -0.5) [set r 0.5] ;Calculating body force 2_4 set force 0.1 * (Mass2 * Mass4)/(r ^ 2) ; separating the force in the components x and y face body4 set fx2_4 force * dx set fy2_4 force * dy end ; bode3 to update-force3_1 ;body distance 3 to 1 let r distance body1 ; 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 body1 set fx3_1 force * dx set fy3_1 force * dy end to update-force3_2 ;body distance 3 to 2 let r distance body2 ; 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 body2 set fx3_2 force * dx set fy3_2 force * dy end to update-force3_4 ;body distance 3 to 4 let r distance body4 ; avoiding infinity if (r < 0.5 and r > -0.5) [set r 0.5] ;Calculating body force 2_4 (we know that is equal to - body strength 3_4) set force 0.1 * (Mass3 * Mass4)/(r ^ 2) ; separating the force in the components x and y face body4 set fx3_4 force * dx set fy3_4 force * dy end ; bode4 to update-force4_1 ;body distance 4 to 1 let r distance body1 ; avoiding infinity if (r < 0.5 and r > -0.5) [set r 0.5] ;Calculating body force 4_1 (we know that is equal to - body strength 4_1) set force 0.1 * (Mass4 * Mass1)/(r ^ 2) ; separating the force in the components x and y face body1 set fx4_1 force * dx set fy4_1 force * dy end to update-force4_2 ;body distance 4 to 2 let r distance body2 ; avoiding infinity if (r < 0.5 and r > -0.5) [set r 0.5] ;Calculating body force 4_1 (we know that is equal to - body strength 4_2) set force 0.1 * (Mass4 * Mass2)/(r ^ 2) ; separating the force in the components x and y face body2 set fx4_2 force * dx set fy4_2 force * dy end to update-force4_3 ;body distance 4 to 3 let r distance body3 ; avoiding infinity if (r < 0.5 and r > -0.5) [set r 0.5] ;Calculating body force 4_1 (we know that is equal to - body strength 4_3) set force 0.1 * (Mass4 * Mass3)/(r ^ 2) ; separating the force in the components x and y face body3 set fx4_3 force * dx set fy4_3 force * dy 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) + (fx1_4 / Mass1) set VelocityY1 VelocityY1 + (fy1_2 / Mass1) + (fy1_3 / Mass1) + (fy1_4 / Mass1) ; disappears if it goes off the edge if abs (ycor + vy) > max-pycor or abs (xcor + vx) > max-pxcor [ die ] ; update particle position set X1 X1 + VelocityX1 set Y1 Y1 + VelocityY1 setxy X1 Y1 end to move2 ; move the particles ;updates particle speed and adds force set VelocityX2 VelocityX2 + (fx2_1 / Mass2) + (fx2_3 / Mass2) + (fx2_4 / Mass2) set VelocityY2 VelocityY2 + (fy2_1 / Mass2) + (fy2_3 / Mass2) + (fy2_4 / Mass2) ; disappears if it goes off the edge if abs (ycor + vy) > max-pycor or abs (xcor + vx) > max-pxcor [ die ] ; update particle position set X2 X2 + VelocityX2 set Y2 Y2 + VelocityY2 setxy X2 Y2 end to move3 ; move the particles ;updates particle speed and adds force set VelocityX3 VelocityX3 + (fx3_1 / Mass3) + (fx3_2 / Mass3) + (fx3_4 / Mass3) set VelocityY3 VelocityY3 + (fy3_1 / Mass3) + (fy3_2 / Mass3) + (fy3_4 / Mass3) ; disappears if it goes off the edge if abs (ycor + vy) > max-pycor or abs (xcor + vx) > max-pxcor [ die ] ; update particle position set X3 X3 + VelocityX3 set Y3 Y3 + VelocityY3 setxy X3 Y3 end to move4 ; move the particles ;updates particle speed and adds force set VelocityX4 VelocityX4 + (fx4_1 / Mass4) + (fx4_2 / Mass4) + (fx4_3 / Mass4) set VelocityY4 VelocityY4 + (fy4_1 / Mass4) + (fy4_2 / Mass4) + (fy4_3 / Mass4) ; disappears if it goes off the edge if abs (ycor + vy) > max-pycor or abs (xcor + vx) > max-pxcor [ die ] ; update particle position set X4 X4 + VelocityX4 set Y4 Y4 + VelocityY4 setxy X4 Y4 end
There is only one version of this model, created over 3 years ago by Zain Alsharari.
Attached files
File | Type | Description | Last updated | |
---|---|---|---|---|
four-body-problem.png | preview | Preview for 'four-body-problem' | over 3 years ago, by Zain Alsharari | Download |