Commit 90f6e848 authored by VAN TOLL Wouter's avatar VAN TOLL Wouter
Browse files

ObjectInteractionForces: Now ignoring certain obstacle segments, to prevent...

ObjectInteractionForces: Now ignoring certain obstacle segments, to prevent double effects at obstacle corners.
parent bfd24801
......@@ -28,7 +28,9 @@ Vector2D ObjectInteractionForces::ComputeForce(Agent* agent, const WorldBase * w
const Vector2D& Position = agent->getPosition();
const float rangeSquared = range_ * range_;
// loop over all neighbors; sum up the forces per neighbor
// loop over all neighbors; sum up the forces for all neighbors that are in range
// - agents
Vector2D AgentForces(0, 0);
const auto& neighbors = agent->getNeighbors();
for (const PhantomAgent& other : neighbors.first)
......@@ -37,10 +39,22 @@ Vector2D ObjectInteractionForces::ComputeForce(Agent* agent, const WorldBase * w
AgentForces += ComputeAgentInteractionForce(agent, other);
}
// - obstacles
Vector2D ObstacleForces(0, 0);
for (const LineSegment2D& obs : neighbors.second)
{
if (distanceToLineSquared(Position, obs.first, obs.second, true) <= rangeSquared)
// We know that obstacles are always closed polygons, whose boundary points are given in counter-clockwise order.
// 1. Ignore an obstacle segment if an agent lies on the wrong side of it. In this case, either the agent is inside the obstacle, or another segment is more relevant.
if (isPointLeftOfLine(Position, obs.first, obs.second))
continue;
// 2. Ignore an obstacle segment if the nearest point is its second endpoint. This prevents double forces at obstacle corners.
const Vector2D& nearest = nearestPointOnLine(Position, obs.first, obs.second, true);
if (nearest == obs.second)
continue;
if (distanceSquared(Position, nearest) <= rangeSquared)
ObstacleForces += ComputeObstacleInteractionForce(agent, obs);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment