void GetAdjacent(Vertex u) { Vector2 uPos = new Vector2(u.position.x, u.position.y); Vector2 vPos; foreach (Vertex v in graph.graph) { if (u == v || v.IsAdjacent(u.id)) { continue; } vPos = new Vector2(v.position.x, v.position.y); Vector2 direction = vPos - uPos; float distance = direction.magnitude; direction.Normalize(); RaycastHit2D obstacle = Physics2D.CircleCast(uPos + (direction * agentRadius), agentRadius, direction, distance, 1 << 8); if (!obstacle) { u.AddAdjacent(v.id); v.AddAdjacent(u.id); } } }
public AdjacencyMatrix(Mesh mesh) { vertexNumber = mesh.vertices.Length; Vector3[] vertices = mesh.vertices; int[] triangles = mesh.triangles; bounds = mesh.bounds; this.vertices = new List <Vertex>(vertexNumber); for (int i = 0; i < vertexNumber; i++) { this.vertices.Add(new Vertex { vertex = vertices[i] }); } for (int i = 0; i < triangles.Length - 3; i += 3) { Vertex v1 = this.vertices[triangles[i + 0]]; Vertex v2 = this.vertices[triangles[i + 1]]; Vertex v3 = this.vertices[triangles[i + 2]]; Vertex.AddAdjacent(v1, v2); Vertex.AddAdjacent(v1, v3); Vertex.AddAdjacent(v2, v3); } }
// Adds and edge by setting start as adjacent to end and // viceversa public EdgeIfc AddEdge( Vertex start, Vertex end ) { start.AddAdjacent( end ); end.AddAdjacent( start ); return ( EdgeIfc ) start; }
// Adds and edge by setting end as adjacent to start vertices public EdgeIfc AddEdge(Vertex start, Vertex end) { start.AddAdjacent(end); return(start); }
// Adds and edge by setting end as adjacent to start vertices public EdgeIfc AddEdge( Vertex start, Vertex end ) { start.AddAdjacent( end ); return start; }