212
X-Machines for Agent-Based Modeling: FLAME Perspectives
newPosition = xRightBorder;
}
return newPosition;
}
int getDirection(double aX, double aY, double tX, double tY) {
double tmp = aY;
aY = tY;
tY = tmp;
double vx = tX - aX;
double vy = tY - aY;
double length = sqrt((vx * vx) + (vy * vy));
double alpha = acos(vy / length) * (180.0 / 3.142);
if (vx < 0) {
alpha = 360 - alpha;
}
int result = (int) round(alpha / 360 * 8);
if (result == 0) {
return 8;
}
return result;
}
void updatePosition(double* aX, double* aY, int direction) {
double b = sqrt(antStepSize * antStepSize / 2.0);
switch (direction) {
case 8:
*aY -= antStepSize;
break;
case 4:
*aY += antStepSize;
break;
case 1:
*aX += b;
*aY -= b;
break;
case 2:
*aX += antStepSize;
break;
case 3:
*aX += b;
*aY += b;
break;
case 5:
*aX -= b;
*aY += b;
break;
case 6:
*aX -= antStepSize;
break;
case 7:
*aX -= b;
*aY -= b;
Précédent

- 241/329

Suivant