Esempio n. 1
0
    private GridPoint GetNearestPoint(Vector2 point, CityGraph graph)
    {
        float lowest       = float.MaxValue;
        int   nearestIndex = -1;

        for (int i = 0; i < graph.GetVertexCount(); i++)
        {
            float curDist = Vector2.Distance(graph.GetVertexAt(i).position.ConvertToWorldPoint(m_PointSpacing), point);

            if (curDist < lowest)
            {
                lowest       = curDist;
                nearestIndex = i;
            }
        }

        return(graph.GetVertexAt(nearestIndex).position);
    }
Esempio n. 2
0
    private CityGraph BuildRRT(CityGraph init, int numVerticesK, float incDist)
    {
        CityGraph outputGraph = init;

        RemoveObstructedPoints();

        if (restrictToCircle)
        {
        }

        for (int k = 0; k < numVerticesK; k++)
        {
            Vector2   qRand  = GetRandomPoint();
            GridPoint qNear  = GetNearestPoint(qRand, init);
            float     curInc = incDist - ((outputGraph.GetVertexCount() / reduceIncEvery) * reduceBy);
            curInc = Mathf.Max(curInc, minIncrement);
            GridPoint qNew = NewConfig(qNear.ConvertToWorldPoint(m_PointSpacing), qRand, curInc);
            outputGraph.AddVertex(qNew);
            outputGraph.AddEdge(qNear, qNew);
        }

        return(outputGraph);
    }