Пример #1
0
        /// <summary>
        /// 指定された倍率に最適化します。
        /// </summary>
        /// <param name="rate">倍率</param>
        public void Optimization(float rate)
        {
            Vector2D v = new Vector2D();

            foreach (VertexView item in vertex)
            {
                v.Set(center.X - item.GetPosition().X, center.Y - item.GetPosition().Y);
                v *= (1 - rate);
                item.SetPosition(item.GetPosition().X + v.X, item.GetPosition().Y + v.Y);
            }
        }
Пример #2
0
        /// <summary>
        /// Spring-Electrical-Layoutを適用します。
        /// </summary>
        /// <param name="width">描画領域幅</param>
        /// <param name="height">描画領域高</param>
        public void Spring_Electrical(float width, float height)
        {
            Vector2D[] velocity = new Vector2D[vertexNum]; //頂点ごとの速度
            Vector2D force = new Vector2D(); //頂点に作用する力
            Vector2D delta = new Vector2D(); //差分
            float rate = 0.9f; //比率

            for (int i = 0; i < vertexNum; i++)
            {
                force.Init();

                for (int j = 0; j < vertexNum; j++)
                {
                    if (i != j)
                    {
                        delta.Set(((VertexView)vertex[i]).GetPosition().X - ((VertexView)vertex[j]).GetPosition().X, ((VertexView)vertex[i]).GetPosition().Y - ((VertexView)vertex[j]).GetPosition().Y);
                        force += 500 * delta / (delta.Getnorm() * delta.Getnorm());
                    }
                }

                for (int j = 0; j < edgeNum; j++)
                {
                    int index;
                    if ((index = edge[j].FindContainIndex(vertex[i])) != -1)
                    {
                        float X1, Y1, X2, Y2;
                        X1 = ((VertexView)vertex[i]).GetPosition().X;
                        Y1 = ((VertexView)vertex[i]).GetPosition().Y;
                        X2 = ((VertexView)edge[j].GetEdgeVertex((index + 1) % 2)).GetPosition().X;
                        Y2 = ((VertexView)edge[j].GetEdgeVertex((index + 1) % 2)).GetPosition().Y;
                        delta.Set(X2 - X1, Y2 - Y1);
                        force += 0.06f * delta;
                    }
                }

                velocity[i] = new Vector2D(force.X * 0.85f, force.Y * 0.85f);
            }


            for (int i = 0; i < vertexNum; i++)
            {
                delta.Set(((VertexView)vertex[i]).GetPosition().X, ((VertexView)vertex[i]).GetPosition().Y);
                delta += velocity[i];
                delta.X = (float)Math.Min(width * rate, Math.Max(width * (1 - rate), delta.X));
                delta.Y = (float)Math.Min(height * rate, Math.Max(height * (1 - rate), delta.Y));
                ((VertexView)vertex[i]).SetPosition(delta.X, delta.Y);
            }
        }