Beispiel #1
0
        public static Vector2 GetNearest(ILine line, Vector2 point)
        {
            var     grad       = (line.Point2.Y - line.Point1.Y) / (line.Point2.X - line.Point1.X);
            var     yint       = line.Point1.Y - grad * line.Point1.X;
            Vector2 vYint      = new Vector2(0, yint);
            Vector2 tempPoint  = point - vYint;
            var     tempLine   = new MinimalizedShapes.Line(line.Point1 - vYint, line.Point2 - vYint);
            var     orthogonal = new MinimalizedShapes.Line(tempPoint, new Vector2(tempPoint.X + tempLine.Grad * 10, tempPoint.Y - 10));

            return(GetIntersects(tempLine, orthogonal)[0] + vYint);
        }
Beispiel #2
0
        public static Vector2 GetNearest(ICircle cir, Vector2 point)
        {
            if (cir.Center == point)
            {
                // https://github.com/Big-BlueBerry/GCS.WPF/issues/8
                return(cir.Another);
            }
            var line = new MinimalizedShapes.Line(cir.Center, point);
            var res  = GetIntersects(line, cir);

            return(Distance(res[0], point) < Distance(res[1], point) ? res[0] : res[1]);
        }
Beispiel #3
0
        public static Vector2[] GetIntersects(ISegment seg, ICircle circle)
        {
            var lin = new MinimalizedShapes.Line(seg.Point1, seg.Point2);

            Vector2[] intersects = GetIntersects(lin, circle);
            float     len        = Distance(seg.Point1, seg.Point2);

            if (intersects.Length == 0)
            {
                return new Vector2[] { }
            }
            ;

            var d01 = Distance(intersects[0], seg.Point1);
            var d02 = Distance(intersects[0], seg.Point2);

            if (intersects.Length == 1)
            {
                if (d01 < len && d02 < len)
                {
                    return(intersects);
                }
                else
                {
                    return new Vector2[] { }
                };
            }
            else
            {
                var d11 = Distance(intersects[1], seg.Point1);
                var d12 = Distance(intersects[1], seg.Point2);
                if (d01 < len && d02 < len)
                {
                    if (d11 < len && d12 < len)
                    {
                        return(intersects);
                    }
                    else
                    {
                        return new Vector2[] { intersects[0] }
                    };
                }
                else if (d11 < len && d12 < len)
                {
                    return new Vector2[] { intersects[1] }
                }
                ;
                else
                {
                    return new Vector2[] { }
                };
            }
        }