Ejemplo n.º 1
0
        private Vector GetRepulsionForce(Point uPos, Point vPos, Size uSize, Size vSize, double repulsionRange)
        {
            var positionVector = (uPos - vPos);

            if (positionVector.Length == 0)
            {
                var compensationVector = new Vector(rnd.NextDouble(), rnd.NextDouble());
                positionVector = compensationVector * 2;
                uPos          += compensationVector;
                vPos          -= compensationVector;
            }
            positionVector.Normalize();

            var c_u = LayoutUtil.GetClippingPoint(uSize, uPos, vPos);
            var c_v = LayoutUtil.GetClippingPoint(vSize, vPos, uPos);

            var F = c_u - c_v;
            var isSameDirection = LayoutUtil.IsSameDirection(positionVector, F);
            var Fr = new Vector();

            if (isSameDirection && F.Length > repulsionRange)
            {
                return(new Vector());
            }
            double length = Math.Max(1, F.Length);

            //double length = F.LengthSquared;
            length = Math.Pow(isSameDirection ? length / (Parameters.IdealEdgeLength * 2.0) : 1 / length, 2);
            Fr     = Parameters.RepulsionConstant / length * positionVector * _phaseDependentRepulsionMultiplier;
            return(Fr);
        }
Ejemplo n.º 2
0
        public Vector GetRepulsionForce(Point uPos, Point vPos, Size uSize, Size vSize, double repulsionRange)
        {
            var c_u = LayoutUtil.GetClippingPoint(uSize, uPos, vPos);
            var c_v = LayoutUtil.GetClippingPoint(vSize, vPos, uPos);

            var positionVector = (uPos - vPos);

            if (positionVector.Length == 0)
            {
                return(new Vector());
            }
            positionVector.Normalize();
            var F = c_u - c_v;
            var isSameDirection = LayoutUtil.IsSameDirection(positionVector, F);
            var Fr = new Vector();

            /*if (isSameDirection)
             * {*/
            if (F.Length > repulsionRange)
            {
                return(new Vector());
            }
            double length = Math.Max(1, F.Length);

            length = Math.Pow(isSameDirection ? length : 1 / length, isSameDirection ? 2 : 1);
            Fr     = parameters.RepulsionConstant / length * positionVector;
            return(Fr);
        }
Ejemplo n.º 3
0
        private Vector GetSpringForce(double idealLength, Point uPos, Point vPos, Size uSize, Size vSize)
        {
            var positionVector = (uPos - vPos);

            if (positionVector.Length == 0)
            {
                var compensationVector = new Vector(_random.NextDouble(), _random.NextDouble());
                positionVector = compensationVector * 2;
                uPos          += compensationVector;
                vPos          -= compensationVector;
            }

            positionVector.Normalize();

            //get the clipping points
            var c_u = LayoutUtil.GetClippingPoint(uSize, uPos, vPos);
            var c_v = LayoutUtil.GetClippingPoint(vSize, vPos, uPos);

            Vector F = (c_u - c_v);
            bool   isSameDirection = LayoutUtil.IsSameDirection(positionVector, F);
            double length          = 0;

            if (isSameDirection)
            {
                length = F.Length - idealLength;
            }
            else
            {
                length = F.Length + idealLength;
            }

            if (F.Length == 0)
            {
                F = -positionVector;
            }
            F.Normalize();
            if (length > 0)
            {
                F *= -1;
            }

            var Fs = Math.Pow(length / (idealLength), 2) / Parameters.ElasticConstant * F;

            return(Fs);
        }
Ejemplo n.º 4
0
        public Vector GetSpringForce(Point uPos, Point vPos, Size uSize, Size vSize)
        {
            double idealLength = parameters.IdealEdgeLength;

            //get the clipping points
            var c_u = LayoutUtil.GetClippingPoint(uSize, uPos, vPos);
            var c_v = LayoutUtil.GetClippingPoint(vSize, vPos, uPos);

            var positionVector = (uPos - vPos);

            positionVector.Normalize();

            Vector F = (c_u - c_v);
            bool   isSameDirection = LayoutUtil.IsSameDirection(positionVector, F);
            double length          = 0;

            if (isSameDirection)
            {
                length = F.Length - idealLength;
            }
            else
            {
                length = F.Length + idealLength;
            }

            if (F.Length == 0)
            {
                F = -positionVector;
            }
            F.Normalize();
            if (length > 0)
            {
                F *= -1;
            }

            var Fs = Math.Pow(length, 2) / parameters.ElasticConstant * F;

            return(Fs);
        }