bool BelongToSameGroup(AAgent a, AAgent b) { bool belong = false; // Condition 1: same position float dist = Vector2.Distance(a.position, b.position); belong = dist < ed; //// Condition 2: same velocity magnitude belong &= Mathf.Abs(a.velocity.sqrMagnitude - b.velocity.sqrMagnitude) < ev * ev; //// Condition 3: same move direction Vector2 dirA = (a.goal - a.position).normalized; Vector2 dirB = (b.goal - b.position).normalized; belong &= Vector2.Angle(dirA, dirB) < eav; return(belong); }
// Deteccion de puntos extremos tangentes static void GetTangents(List <int> group, Dictionary <int, float> ttc, Vector2 position, Vector2 dir, float radius, out Vector2 closestAgentPosition, out Vector2 closestAgentVelocity, out List <Point> tangentsPoints, out List <Tuple <Point, Point> > points, int povID, out int turnTo, out List <int> members) { float minimoTTC = Mathf.Infinity, minDst = MAX_DISTANCE; Point agentPos = new Point(position); Point outer1_p1, outer1_p2, outer2_p1, outer2_p2; tangentsPoints = new List <Point>(); points = new List <Tuple <Point, Point> >(); members = new List <int>(); closestAgentPosition = Vector2.zero; closestAgentVelocity = Vector2.zero; turnTo = 0; foreach (int id in group) { if (group.Contains(povID)) { break; } if (!ttc.ContainsKey(id)) { continue; } // Calculamos el agente mas cercano al observador AAgent agent_tmp = Engine.Instance.GetAgent(id); float dst = Vector2.Distance(position, agent_tmp.position); turnTo += agent_tmp.TurnTo; // Si este agente esta mas cerca de lo permitido entonces // no es tomado en cuenta if (dst < MIN_DISTANCE) { continue; } if (!Behaviours.ItsInFront(dir, agent_tmp.position - position)) { continue; } if (dst < minDst) { closestAgentPosition = agent_tmp.position; minDst = dst; } if (ttc[id] < minimoTTC) { closestAgentVelocity = agent_tmp.velocity; minimoTTC = ttc[id]; } members.Add(id); // Find tangents points from this agent to actual iteration neighbour Global.FindCircleCircleTangents(agentPos, radius, new Point(agent_tmp.position), agent_tmp.radius, out outer1_p1, out outer1_p2, out outer2_p1, out outer2_p2); // agregamos el vector tangente en direccion del agente observador dst = Point.Distance(outer1_p1, agentPos); float dst_2 = Point.Distance(outer1_p2, agentPos); if (dst < dst_2) { tangentsPoints.Add(outer1_p2); points.Add(new Tuple <Point, Point>(outer1_p1, outer1_p2)); } else { tangentsPoints.Add(outer1_p1); points.Add(new Tuple <Point, Point>(outer1_p2, outer1_p1)); } // agregamos el vector tangente en direccion del agente observador dst = Point.Distance(outer2_p1, agentPos); dst_2 = Point.Distance(outer2_p2, agentPos); if (dst < dst_2) { tangentsPoints.Add(outer2_p2); points.Add(new Tuple <Point, Point>(outer2_p1, outer2_p2)); } else { tangentsPoints.Add(outer2_p1); points.Add(new Tuple <Point, Point>(outer2_p2, outer2_p1)); } } }