AForge.Math.Geometry.LineSegment.GetIntersectionWith C# (CSharp) Method

GetIntersectionWith() public method

Finds, provided it exists, the intersection point with the specified Line.

If the line and the segment do not intersect, the method returns . If the line and the segment share multiple points, the method throws an InvalidOperationException.

Thrown if this segment is a portion of /// line.
public GetIntersectionWith ( Line other ) : DoublePoint?
other Line to find intersection with.
return DoublePoint?
        public DoublePoint? GetIntersectionWith( Line other )
        {
            DoublePoint? result;

            if ( ( line.Slope == other.Slope ) || ( line.IsVertical && other.IsVertical ) )
            {
                if ( line.Intercept == other.Intercept ) throw new InvalidOperationException( "Segment is a portion of the specified line." );

                // unlike Line.GetIntersectionWith(Line), this does not throw on parallel distinct lines
                result = null;
            }
            else
            {
                result = line.GetIntersectionWith( other );
            }

            if ( ( result.HasValue ) && ( LocateProjection( result.Value ) != ProjectionLocation.SegmentAB ) )
            {
                // the intersection is on this segment's extended line, but not on the segment itself
                result = null;
            }

            return result;
        }

Same methods

LineSegment::GetIntersectionWith ( LineSegment other ) : DoublePoint?

Usage Example

Example #1
0
 /// <summary>
 /// Finds, provided it exists, the intersection point with the specified <see cref="LineSegment"/>.
 /// </summary>
 ///
 /// <param name="other"><see cref="LineSegment"/> to find intersection with.</param>
 ///
 /// <returns>Returns intersection point with the specified <see cref="LineSegment"/>, or <see langword="null"/>,
 /// if this line does not intersect with the segment.</returns>
 ///
 /// <remarks><para>If the line and segment do not intersect, the method returns <see langword="null"/>.
 /// If the line and segment share multiple points, the method throws an <see cref="InvalidOperationException"/>.
 /// </para></remarks>
 ///
 /// <exception cref="InvalidOperationException">Thrown if <paramref name="other"/> is a portion
 /// of this line.</exception>
 ///
 public Point?GetIntersectionWith(LineSegment other)
 {
     return(other.GetIntersectionWith(this));
 }
All Usage Examples Of AForge.Math.Geometry.LineSegment::GetIntersectionWith