new Vector2D(bodyPos),
new Vector2D(bodyPos).translate(sensorLOV));
//find closest agent
Double minDistance = Double.POSITIVE_INFINITY;
AbstractAgent2D closestAgent = null;
for (Iterator<Integer> iterator = agentsToCheck.iterator(); iterator.hasNext();) {
Integer agentID = iterator.next();
//for all remaining agents check for intersection
List<Vector2D> isPoints = env.getAgentShapeInEnvironment(agentID).intersectAll(sensorLine);
if(!isPoints.isEmpty()){
//find intersection point with least distance
for (Vector2D isPoint : isPoints) {
isPoint.sub(bodyPos);
if(Double.compare(isPoint.length(), minDistance) < 0){
minDistance = isPoint.length();
closestAgent = env.getAgent(agentID);
}
}
}
}
if(closestAgent != null)
return new SimpleEntry<Integer, Color>((int) Math.round(minDistance), closestAgent.getAgentColor());
return new SimpleEntry<Integer, Color>((int) Math.round(cSensorReach), Color.BLACK);
}