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

GetIntersectionWith() public method

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

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

Thrown if is a portion /// of this line.
public GetIntersectionWith ( LineSegment other ) : Point?
other LineSegment to find intersection with.
return Point?
		public Point? GetIntersectionWith( LineSegment other )
		{
			return other.GetIntersectionWith( this );
		}

Same methods

Line::GetIntersectionWith ( Line secondLine ) : Point?

Usage Example

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