/// <summary>
 /// Returns true if any part of this circle overlaps any part of line segment <paramref name='b'/>.
 /// </summary>
 /// <remarks>
 /// If line <paramref name='b'/> lies within the circle, that counts as overlapping.
 /// </remarks>
 public bool Overlaps(WLineSegment b)
 {
     WPoint[] lineIntersectionPoints = GetIntersectionPoints(b.ToWLine());
     if (lineIntersectionPoints == null)
     {
         return(false);
     }
     foreach (WPoint point in lineIntersectionPoints)
     {
         if (b.Overlaps(point))
         {
             return(true);
         }
     }
     if (lineIntersectionPoints.Length == 2)
     {
         //if b lies entirely within the circle
         WLineSegment intersectionLine = new WLineSegment(lineIntersectionPoints[0], lineIntersectionPoints[1]);
         if (intersectionLine.Length > b.Length && intersectionLine.Overlaps(b))
         {
             return(true);
         }
     }
     return(false);
 }
Example #2
0
 /// <summary>
 /// Returns true if the arc overlaps any part of the <paramref name='lineSegment'/>.
 /// </summary>
 public bool ArcOverlaps(WLineSegment lineSegment)
 {
     //find intersection points between full circle and line segment
     WPoint[] fullCircleIntersections = Circle.GetIntersectionPoints(lineSegment);
     if (fullCircleIntersections == null)
     {
         return(false);
     }
     //find degrees from circle center to intersection points
     //are any of those degrees within the wedge degree range?
     foreach (WPoint point in fullCircleIntersections)
     {
         double degrees = Circle.DegreesAtPoint(point);
         if (Degrees.Overlaps(degrees))
         {
             return(true);
         }
     }
     return(false);
 }
        //todo: is it worth making a Degree and a Radian struct? for being precise in what data is expected/returned?

        /// <summary>Find the intersection points between the edge of this circle and the <paramref name='lineSegment'/>.</summary>
        /// <returns>Null (no intercepts), or array of length 1, or array of length 2.</returns>
        public WPoint[] GetIntersectionPoints(WLineSegment lineSegment)
        {
            WPoint[] lineIntersectionPoints = GetIntersectionPoints(lineSegment.ToWLine());
            if (lineIntersectionPoints == null)
            {
                return(null);
            }
            List <WPoint> segmentIntersectionPoints = new List <WPoint>();

            foreach (WPoint point in lineIntersectionPoints)
            {
                if (lineSegment.Overlaps(point))
                {
                    segmentIntersectionPoints.Add(point);
                }
            }
            if (segmentIntersectionPoints.Count == 0)
            {
                return(null);
            }
            return(segmentIntersectionPoints.ToArray());
        }
Example #4
0
        /// <summary>Returns true if this line segments overlaps line segment <paramref name='b'/> at any point.</summary>
        public bool Overlaps(WLineSegment b)
        {
            Intersection intersection = GetIntersection(b);

            return(intersection != Intersection.NONE);
        }
Example #5
0
        /// <summary>Returns intersection between a line segment and another line segment.</summary>
        public override Intersection GetIntersection(WLineSegment that)
        {
            if (this.Parallel(that))
            {
                bool thisAOnThat = this.A.Overlaps(that);
                bool thisBOnThat = this.B.Overlaps(that);
                bool thatAOnThis = that.A.Overlaps(this);
                bool thatBOnThis = that.B.Overlaps(this);

                if (!thisAOnThat && !thisBOnThat && !thatAOnThis && !thatBOnThis)
                {
                    return(Intersection.NONE);
                }

                if (thisAOnThat && thisBOnThat)
                {
                    return(new Intersection(this));
                }

                if (thatAOnThis && thatBOnThis)
                {
                    return(new Intersection(that));
                }

                WPoint overlapThis = null;
                WPoint overlapThat = null;
                if (thisAOnThat)
                {
                    overlapThis = this.A;
                }
                else if (thisBOnThat)
                {
                    overlapThis = this.B;
                }
                if (thatAOnThis)
                {
                    overlapThat = that.A;
                }
                else if (thatBOnThis)
                {
                    overlapThat = that.B;
                }

                if (overlapThis == null || overlapThat == null)
                {
                    //should not reach this, but just in case
                    return(Intersection.NONE);
                }

                if (overlapThis == overlapThat)
                {
                    return(new Intersection(overlapThis));
                }

                return(new Intersection(new WLineSegment(overlapThis, overlapThat)));
            }

            Intersection possibleIntersection = (this.ToWLine()).GetIntersection(that.ToWLine());

            if (possibleIntersection.IsPoint && this.Overlaps(possibleIntersection.Point) && that.Overlaps(possibleIntersection.Point))
            {
                return(possibleIntersection);
            }

            return(Intersection.NONE);
        }
Example #6
0
 /// <summary>Returns true if lines are coincidental to each other.</summary>
 /// <remarks>Coincidental means that every point on this line is also on the other, and vice versa. In short, the lines are equal.</remarks>
 public override bool Coincidental(WLineSegment b)
 {
     return(this.A == b.A && this.B == b.B);
 }
 /// <summary></summary>
 public Intersection(WLineSegment lineSegment)
 {
     Type             = IntersectionType.LineSegment;
     this.lineSegment = lineSegment;
 }
Example #8
0
 /// <summary>Returns false. An infinite line cannot be coincidental to a finite line.</summary>
 public virtual bool Coincidental(WLineSegment b)
 {
     return(false);
 }
Example #9
0
 /// <summary>Returns intersection between a line segment and a line.</summary>
 public virtual Intersection GetIntersection(WLineSegment b)
 {
     return(b.GetIntersection(this));
 }
Example #10
0
 /// <summary>Returns true if this point overlaps any part of the <pararef name='lineSegment'/>.</summary>
 public bool Overlaps(WLineSegment lineSegment)
 {
     return(lineSegment.Overlaps(this));
 }