Agents in Social Science
117
{
diffx=myx-leader_personx;
diffy=myy-leader_persony;
diffvelx=myvelx-leader_velx;
diffvely=myvely-leader_vely;
//using vector equations calculate the dot root function of the difference
dotRoot=sqrt(dot(diffxy,diffxy));
//posDiff is a data structure of two variables x and y
if(dotRoot!=0.0)
{
posDiff=normalize(diffxy); //normalise the difference
springForce=-(dotRoot-restLength)*strength;
dampingForce=-damping*dot(posDiff,diffvel);//add damping to slow down
posDiff*=(springForce+dampingForce);
posDiff*=0.1;
X+=posDiff.x;
Y+=posDiff.y;
}
}
return 0;
}
The new x and y positions are calculated using principles from vector
transformations and force movements. The dot product between two vectors
A · B calculates the new cartesian positions in the Euclidean vector space.
A · B =
A i B i , f or all i to n
(5.2)
FIGURE 5.14: Using vector equations to calculate resulting movement.
Figure 5.14 summarizes calculations involved in calculating next positions
x and y for agents. The agent will calculate, based on its own velocity and
its leader’s velocity vector, to get a resulting vector. The goal weights and
117
{
diffx=myx-leader_personx;
diffy=myy-leader_persony;
diffvelx=myvelx-leader_velx;
diffvely=myvely-leader_vely;
//using vector equations calculate the dot root function of the difference
dotRoot=sqrt(dot(diffxy,diffxy));
//posDiff is a data structure of two variables x and y
if(dotRoot!=0.0)
{
posDiff=normalize(diffxy); //normalise the difference
springForce=-(dotRoot-restLength)*strength;
dampingForce=-damping*dot(posDiff,diffvel);//add damping to slow down
posDiff*=(springForce+dampingForce);
posDiff*=0.1;
X+=posDiff.x;
Y+=posDiff.y;
}
}
return 0;
}
The new x and y positions are calculated using principles from vector
transformations and force movements. The dot product between two vectors
A · B calculates the new cartesian positions in the Euclidean vector space.
A · B =
A i B i , f or all i to n
(5.2)
FIGURE 5.14: Using vector equations to calculate resulting movement.
Figure 5.14 summarizes calculations involved in calculating next positions
x and y for agents. The agent will calculate, based on its own velocity and
its leader’s velocity vector, to get a resulting vector. The goal weights and
