/// <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); }
//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()); }
/// <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); }
/// <summary>Returns true if this point overlaps any part of the <pararef name='lineSegment'/>.</summary> public bool Overlaps(WLineSegment lineSegment) { return(lineSegment.Overlaps(this)); }