Exemplo n.º 1
0
    public void GenerateRandomGraph()
    {
        var result = new GameObject($"GeneratedGraph-{count}-{nearJoint}");
        var graph  = result.AddComponent <GraphBehaviour>();

        graph.graph = PositionGraph.From(Vector3.Zero);
        Graph        zero = graph.graph;
        List <Graph> all  = graph.all;


        for (int i = 0; i < count; i++)
        {
            Graph g = PositionGraph.From(RandomPos());
            zero += g;
            all.Add(g);
        }


        //ループしつつ最近点2個のみの接続とする
        for (int i = count - 1; 0 <= i; i--)
        {
            //pick
            var origin = zero[i];
            //find2
            var picks =
                zero.Where(A =>
                           A != origin &&
                           A != zero
                           )
                .OrderBy(B =>
            {
                var d = Vector3.Distance(
                    origin.Position,
                    B.Position);
                return(d);
            }
                         )
                .Take(nearJoint)
                .ToList();

            Debug.Log($"{origin.id} =>{string.Join(",", picks.Select(pick => pick.id).ToArray())}");


            foreach (Graph pick in picks)
            {
                origin += pick;
            }
        }

        //zeroと縁を切る
        Debug.Log($"Zeroと縁切り {zero.Count}");
        //zeroと近傍のみ接続
        zero
        .Where(A => A != zero)
        .OrderByDescending(B =>
        {
            var d = Vector3.Distance(
                zero.Position,
                B.Position);
            return(d);
        })
        //近傍以外
        .Take(zero.Count - nearJoint)
        .ToList()
        .ForEach(g => zero -= g);
    }
Exemplo n.º 2
0
 public void ScaleToSize(float MaxSize)
 {
     Scale = new Vector3(MaxSize / Vector3.Distance(Vector3.Zero, BoundingBox.Bounds));
 }