BehaviourComposer: ignore everything before this.
Begin micro-behaviour:
Begin description:
Finds the center of mass of all the bodies active
End description
Find C.O.M
Begin NetLogo code:
let bodies objects with [my-mass > 0] let total-mass sum [ my-mass ] of bodies set the-center-of-mass-xcor sum [my-mass * xcor] of bodies / total-mass set the-center-of-mass-ycor sum [my-mass * ycor] of bodies / total-mass if the-world-is-3-d? [ set the-center-of-mass-zcor sum [my-mass * zcor] of bodies / total-mass ]
End NetLogo code
This mirco-behaviour finds the centre of mass of the active bodies by timesing the mass of the each body by their position ( xcor and ycor ) and the dividing by the total mass of all the bodies to be left with only an xcor and ycor value.
Authored by Maria Marinari and Ken Kahn.
BehaviourComposer: ignore everything after this.