Exemplo n.º 1
0
    private void Update()
    {
        ConvexPolygon p1 = polygon1.Polygon;
        ConvexPolygon p2 = polygon2.Polygon;

        if (p1 == null || p2 == null)
        {
            return;
        }
        ConvexPolygon polygon = IntersectionOperation.Execute(p1, p2, lineFactory);

        //DrawLine
        if (polygon == null)
        {
            return;
        }
        List <Vector3> vertices = polygon.GetVertices3Copy();

        vertices.Add(vertices[0]);                      //末尾に先頭を追加
        if (line != null)
        {
            lineFactory.DeleteLine(line);
        }
        //line = lineFactory.CreateLine(vertices, Color.green);

        //DrawEdgeLine
        //DrawEdgeLine(p1, leftEdge);
    }
Exemplo n.º 2
0
    /// <summary>
    /// ボロノイ図生成コルーチン
    /// </summary>
    private IEnumerator Voronoi()
    {
        PseudoHalfPlaneGenerator halfPlaneGenerator = new PseudoHalfPlaneGenerator(100f);

        while (true)
        {
            List <Vector2>       sites   = new List <Vector2>(siteTranses.Select(elem => (Vector2)elem.position));
            List <ConvexPolygon> results = new List <ConvexPolygon>();
            List <ChainLine>     lines   = new List <ChainLine>();

            for (int i = 0; i < sites.Count; ++i)
            {
                Vector3       s1     = sites[i];
                ConvexPolygon region = null;                    //途中計算結果格納用の領域
                for (int j = 0; j < sites.Count; ++j)
                {
                    Vector3 s2 = sites[j];
                    if (i == j)
                    {
                        continue;
                    }

                    //s1とs2の垂直二等分線を求める
                    Line line = Line.PerpendicularBisector(s1, s2);
                    //垂直二等分線による半平面のうち,s1を含む方を求める
                    ConvexPolygon halfPlane = halfPlaneGenerator.Execute(line, s1);

                    if (region == null)
                    {
                        //初回計算時
                        region = IntersectionOperation.Execute(areaPolygon, halfPlane);
                    }
                    else
                    {
                        //二回目以降
                        region = IntersectionOperation.Execute(region, halfPlane);
                    }
                    Debug.Log(region + " : " + halfPlane);

                    //halfPlaneを可視化
                    List <Vector3> vertices = halfPlane.GetVertices3Copy();
                    vertices.Add(vertices[0]);                          //末尾を追加
                    ChainLine subl = lineFactory.CreateLine(vertices, subColor);

                    //regionを可視化
                    vertices = region.GetVertices3Copy();
                    vertices.Add(vertices[0]);                          //末尾を追加
                    ChainLine l = lineFactory.CreateLine(vertices, lineColor.Evaluate((float)j / sites.Count));
                    yield return(StartCoroutine(Wait()));

                    lineFactory.DeleteLine(subl);
                    lineFactory.DeleteLine(l);
                }
            }
            Debug.Log("Complete");

            yield return(StartCoroutine(Wait()));
        }
    }
Exemplo n.º 3
0
    private void Update()
    {
        List <Vector2>       sites   = new List <Vector2>(siteTranses.Select(elem => (Vector2)elem.position));
        List <ConvexPolygon> results = new List <ConvexPolygon>();

        //線の削除
        if (lines.Count > 0)
        {
            for (int i = 0; i < lines.Count; ++i)
            {
                lineFactory.DeleteLine(lines[i]);
            }
            lines.Clear();
        }

        foreach (Vector2 s1 in sites)
        {
            ConvexPolygon region = null;                //途中計算結果格納用の領域
            foreach (Vector2 s2 in sites)
            {
                if (s1 == s2)
                {
                    continue;
                }
                //s1とs2の垂直二等分線を求める
                Line line = Line.PerpendicularBisector(s1, s2);
                //垂直二等分線による半平面のうち,s1を含む方を求める
                ConvexPolygon halfPlane = halfPlaneGenerator.Execute(line, s1);
                if (region == null)
                {
                    //初回計算時
                    region = IntersectionOperation.Execute(areaPolygon, halfPlane);
                }
                else
                {
                    //二回目以降
                    region = IntersectionOperation.Execute(region, halfPlane);
                }
            }
            if (region != null)
            {
                results.Add(region);
            }
            else
            {
                Debug.Log("Region is null");
            }
        }

        for (int i = 0; i < results.Count; ++i)
        {
            results[i].Scale(sites[i], 0.9f);
            List <Vector3> vertices = results[i].GetVertices3Copy();
            vertices.Add(vertices[0]);
            lines.Add(lineFactory.CreateLine(vertices, Color.green));
        }
    }
Exemplo n.º 4
0
    /// <summary>
    /// 図の更新
    /// </summary>
    private void UpdateDiagram(List <Vector2> sites)
    {
        //ボロノイ図の作成
        areaPolygon      = ConvexPolygon.SquarePolygon(10f);
        voronoiGenerator = new VoronoiDiagramGenerator();
        regions          = voronoiGenerator.Execute(areaPolygon, sites);

        //線の削除
        for (int i = 0; i < lines.Count; ++i)
        {
            lineFactory.DeleteLine(lines[i]);
        }
        lines.Clear();

        for (int i = 0; i < regions.Count; ++i)
        {
            ConvexPolygon region = regions[i];

            //線の描画
            if (drawRegionLine)
            {
                List <Vector3> vertices = region.GetVertices3Copy();
                vertices.Add(vertices[0]);
                lines.Add(lineFactory.CreateLine(vertices));
            }

            //メッシュ
            meshes[i] = region.Scale(sites[i], 0.5f).ToMesh();            //AngleSubdivisionOperation.Execute(region, 170f).Scale(sites[i], 1f).ToMesh();

            //あたり判定の設定
            colliders[i].sharedMesh = meshes[i];
        }
    }
Exemplo n.º 5
0
    private void Update()
    {
        List <Vector2> vertices = new List <Vector2> (this.vertices.Select(elem => (Vector2)elem.position));

        //Convex Polygon
        polygon = new ConvexPolygon(vertices);

        //DrawLine
        List <Vector3> points = polygon.GetVertices3Copy();

        points.Add(points[0]);          //末尾に先頭を追加
        if (line != null)
        {
            lineFactory.DeleteLine(line);
        }

        line = lineFactory.CreateLine(points, lineColor);
    }
Exemplo n.º 6
0
    private void Update()
    {
        List <Vector2> sites = new List <Vector2>(siteTranses.Select(elem => (Vector2)elem.position));

        //ボロノイ図の作成
        areaPolygon      = ConvexPolygon.SquarePolygon(10f);
        voronoiGenerator = new VoronoiDiagramGenerator();
        List <ConvexPolygon> regions = voronoiGenerator.Execute(areaPolygon, sites);

        List <Vector3> vertices;

        for (int i = 0; i < lines.Count; ++i)
        {
            lineFactory.DeleteLine(lines[i]);
        }
        //lines.Clear();

        for (int i = 0; i < regions.Count; ++i)
        {
            ConvexPolygon region = regions[i];
            if (drawRegionLine)
            {
                vertices = region.GetVertices3Copy();
                vertices.Add(vertices[0]);
                lines.Add(lineFactory.CreateLine(vertices));
            }
            //描画
            Mesh mesh = null;
            if (angled)
            {
                mesh = AngleSubdivisionOperation.Execute(region, 170f).Scale(sites[i], 0.9f).ToAltMesh();
            }
            else
            {
                mesh = LerpSubdivisionOperation.Execute(region, i, lerpT).Scale(sites[i], 0.9f).ToAltMesh();
            }
            UnityEngine.Graphics.DrawMesh(mesh, Matrix4x4.identity, mat, 0);
        }
    }
Exemplo n.º 7
0
    private void Update()
    {
        List <WaitedVoronoiSite> sites =
            new List <WaitedVoronoiSite>(siteObjects.Select(elem => new WaitedVoronoiSite(elem.transform.position, elem.Wait)));

        //ボロノイ図の作成
        List <ConvexPolygon> regions = voronoiGenerator.Execute(areaPolygon, sites);

        List <Vector3> vertices;

        for (int i = 0; i < lines.Count; ++i)
        {
            lineFactory.DeleteLine(lines[i]);
        }
        lines.Clear();

        for (int i = 0; i < regions.Count; ++i)
        {
            ConvexPolygon region = regions[i];
            vertices = region.GetVertices3Copy();
            vertices.Add(vertices[0]);
            lines.Add(lineFactory.CreateLine(vertices));
        }
    }