Beispiel #1
0
        public static Point GetEdgeEndpointOnEllipse(Point oVertexALocation, double dVertexARadiusWidth, double dVertexARadiusHeight, Point oVertexBLocation, double angle = 0)
        {
            Debug.Assert(dVertexARadiusWidth >= 0);
            Debug.Assert(dVertexARadiusHeight >= 0);

            var sourcePoint = oVertexALocation;
            var targetPoint = oVertexBLocation;

            var dEdgeAngle = MathHelper.GetAngleBetweenPoints(sourcePoint, targetPoint);

            if (angle != 0)
            {
                dEdgeAngle = (dEdgeAngle.ToDegrees() + angle).ToRadians();
            }

            var pt = new Point(
                sourcePoint.X + (dVertexARadiusWidth * Math.Cos(dEdgeAngle)),
                sourcePoint.Y - (dVertexARadiusHeight * Math.Sin(dEdgeAngle))
                );

            if (angle != 0)
            {
                pt = MathHelper.RotatePoint(pt, oVertexALocation, angle);
            }
            return(pt);
        }
Beispiel #2
0
        public static Point GetEdgeEndpointOnRectangle(Point sourcePos, Rect sourceBounds, Point targetPos, double angle = 0)
        {
            Func <Point, double, Point> rotate = (p, a) => angle == 0.0 ? p : MathHelper.RotatePoint(p, sourceBounds.Center(), a);

            var tgt_pt = rotate(targetPos, -angle);

            if (tgt_pt.X <= sourcePos.X)
            {
                var leftSide = Intersects(sourcePos.ToVector(), tgt_pt.ToVector(), sourceBounds.TopLeft().ToVector(), sourceBounds.BottomLeft().ToVector());
                if (leftSide.HasValue)
                {
                    return(rotate(new Point(leftSide.Value.X, leftSide.Value.Y), angle));
                }
            }
            else
            {
                var rightSide = Intersects(sourcePos.ToVector(), tgt_pt.ToVector(), sourceBounds.TopRight().ToVector(), sourceBounds.BottomRight().ToVector());
                if (rightSide.HasValue)
                {
                    return(rotate(new Point(rightSide.Value.X, rightSide.Value.Y), angle));
                }
            }

            if (tgt_pt.Y <= sourcePos.Y)
            {
                var topSide = Intersects(sourcePos.ToVector(), tgt_pt.ToVector(), sourceBounds.TopLeft().ToVector(), sourceBounds.TopRight().ToVector());
                if (topSide.HasValue)
                {
                    return(rotate(new Point(topSide.Value.X, topSide.Value.Y), angle));
                }
            }
            else
            {
                var bottomSide = Intersects(sourcePos.ToVector(), tgt_pt.ToVector(), sourceBounds.BottomLeft().ToVector(), sourceBounds.BottomRight().ToVector());
                if (bottomSide.HasValue)
                {
                    return(rotate(new Point(bottomSide.Value.X, bottomSide.Value.Y), angle));
                }
            }

            return(rotate(new Point(sourcePos.X, sourcePos.Y), angle));
        }
Beispiel #3
0
        public static Point GetEdgeEndpointOnRectangle(Point sourcePos, Rect sourceBounds, Point targetPos, double angle = 0)
        {
            var tgt_pt = targetPos;

            if (angle != 0)
            {
                tgt_pt = MathHelper.RotatePoint(targetPos, sourceBounds.Center(), -angle);
            }

            var leftSide   = Intersects(sourcePos.ToVector(), tgt_pt.ToVector(), sourceBounds.TopLeft().ToVector(), sourceBounds.BottomLeft().ToVector());
            var bottomSide = Intersects(sourcePos.ToVector(), tgt_pt.ToVector(), sourceBounds.BottomLeft().ToVector(), sourceBounds.BottomRight().ToVector());
            var rightSide  = Intersects(sourcePos.ToVector(), tgt_pt.ToVector(), sourceBounds.TopRight().ToVector(), sourceBounds.BottomRight().ToVector());
            var topSide    = Intersects(sourcePos.ToVector(), tgt_pt.ToVector(), sourceBounds.TopLeft().ToVector(), sourceBounds.TopRight().ToVector());

            var pt = new Point(sourcePos.X, sourcePos.Y);

            // Get the rectangle side where intersection of the proposed Edge path occurred.
            if (leftSide != null)
            {
                pt = new Point(leftSide.Value.X, leftSide.Value.Y);
            }
            else if (bottomSide != null)
            {
                pt = new Point(bottomSide.Value.X, bottomSide.Value.Y);
            }
            else if (rightSide != null)
            {
                pt = new Point(rightSide.Value.X, rightSide.Value.Y);
            }
            else if (topSide != null)
            {
                pt = new Point(topSide.Value.X, topSide.Value.Y);
            }

            if ((leftSide != null || bottomSide != null || rightSide != null || topSide != null) && angle != 0)
            {
                pt = MathHelper.RotatePoint(pt, sourceBounds.Center(), angle);
            }
            return(pt);
        }