예제 #1
0
        /// <summary>
        /// 计算点到Voronoi Edge的距离
        /// </summary>
        /// <param name="pt"></param>
        /// <param name="edge"></param>
        /// <returns></returns>
        internal static double Distance2ToMidPoint(GeoPoint pt, GraphEdge edge)
        {
            var midPt = new GeoPoint(
                (edge.Start.X + edge.End.X) / 2,
                (edge.Start.Y + edge.End.Y) / 2
                );

            var distance2 = Math.Pow((pt.X - midPt.X), 2)
                            + Math.Pow((pt.Y - midPt.Y), 2);

            return(distance2);
        }
예제 #2
0
        /// <summary>
        /// 垂线距离
        /// </summary>
        /// <param name="pt"></param>
        /// <param name="line"></param>
        /// <returns></returns>
        internal virtual double GetVerticalDistance
            (GeoPoint pt, GraphEdge line) //所在点到AB线段的垂线长度
        {
            var x  = pt.X;
            var y  = pt.Y;
            var x1 = line.Start.X;
            var y1 = line.Start.Y;
            var x2 = line.End.X;
            var y2 = line.End.Y;


            var  reVal   = 0.0;
            bool retData = false;

            var cross = (x2 - x1) * (x - x1) + (y2 - y1) * (y - y1);

            if (cross <= 0)
            {
                reVal   = Math.Sqrt((x - x1) * (x - x1) + (y - y1) * (y - y1));
                retData = true;
            }

            var d2 = (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1);

            if (cross >= d2)
            {
                reVal   = Math.Sqrt((x - x2) * (x - x2) + (y - y2) * (y - y2));
                retData = true;
            }

            if (!retData)
            {
                var r  = cross / d2;
                var px = x1 + (x2 - x1) * r;
                var py = y1 + (y2 - y1) * r;
                reVal = Math.Sqrt((x - px) * (x - px) + (py - y) * (py - y));
            }

            return(reVal);
        }