Utility functions for computing intersections between geometry in 2D space.

Taken mostly from the euclid package available at https://pypi.org/project/euclid/

Get the two closest end Point2Ds between two LineSegment2D objects.

The result will always be composed of endpoints of the segments and will not account for cases where the closest point lies in the middle of a segment. For cases where such middle points are important, the closest_point2d_between_line2d method should be used.

Parameters
• line_a – A LineSegment2D object.

• line_b – Another LineSegment2D to which closest points will be determined.

Returns

A tuple with two elements

• dist: The distance between the two endpoints objects.

• pts: A tuple of two Point2D objects representing:

1. The end point on line_a that is closest to line_b

2. The end point on line_b that is closest to line_a

Get the two closest Point2D between two LineSegment2D objects.

When the closest point on one of the segments lies in the middle of the segment, this will be accounted for. Also note that the line segments should not intersect for the result to be valid.

Parameters
• line_ray_a – A LineSegment2D object.

• line_ray_b – Another LineSegment2D to which closest points will be determined.

Returns

A tuple with two elements

• dists[0]: The distance between the two LineSegment2D objects.

• pts[0]: A tuple of two Point2D objects representing:

1. The point on line_ray_a that is closest to line_ray_b

2. The point on line_ray_b that is closest to line_ray_a

Get the closest Point2D on a Arc2D to the input point.

Parameters
• point – A Point2D object.

• arc – An Arc2D object along which the closest point will be determined.

Returns

Point2D for the closest point on arc to point.

Get the closest Point2D on a LineSegment2D or Ray2D to the input point.

Parameters
• point – A Point2D object.

• line_ray – A LineSegment2D or Ray2D object along which the closest point will be determined.

Returns

Point2D for the closest point on the line_ray to point.

Get the closest Point2D on a Ray2D/LineSegment2D extended infinitely.

Parameters
• point – A Point2D object.

• line_ray – A LineSegment2D or Ray2D object that will be extended infinitely to determine where the closest point lies.

Returns

Point2D for the closest point on the line_ray to point.

Boolean denoting whether an intersection exists between Ray2D or LineSegment2D.

This is slightly faster than actually computing the intersection but should only be used in cases where the actual point of intersection is not needed.

Parameters
• line_ray_a – A LineSegment2D or Ray2D object.

• line_ray_b – Another LineSegment2D or Ray2D to intersect.

Returns

True if an intersection exists. False if no intersection exists.

Get the intersection between any Ray2D or LineSegment2D objects as a Point2D.

This function calculates scaling parameters for ua and ub where:

A.p + ua * A.v = B.p + ub * B.v

Which represents the intersection point between line A and line B.

The derivation of ua is achieved by crossing both sides of the above equation with the direction vector of B, and rearranging the formula:

```A.p + ua * A.v = B.p + ub * B.v
(A.p + ua * A.v) x B.v = (B.p + ub * B.v) x B.v # Cross both sides with B.v
(A.p x B.v) + (ua * A.v x B.v) = (B.p x B.v) + (ub * B.v x B.v) # B.v x B.v = 0
ua = (B.p - A.p) x B.v / (A.v x B.v)
```
Parameters
• line_ray_a – A LineSegment2D or Ray2D object.

• line_ray_b – Another LineSegment2D or Ray2D to intersect.

Returns

Point2D of intersection if it exists. None if no intersection exists.

Get the intersection between any Ray2D/LineSegment2D and an Arc2D.

Parameters
• line_ray – A LineSegment2D or Ray2D object.

• arc – An Arc2D object along which the closest point will be determined.

Returns

A list of 2 Point2D objects if a full intersection exists. A list with a single Point2D object if the line is tangent or intersects only once. None if no intersection exists.

Get intersection between a Ray2D/LineSegment2D and another extended infinitely.

Parameters
• line_ray_a – A LineSegment2D or Ray2D object.

• line_ray_b – A LineSegment2D or Ray2D that will be extended infinitely for intersection.

Returns

Point2D of intersection if it exists. None if no intersection exists.

Get intersection between an Arc2D and a Ray2D/LineSegment2D extended infinitely.

Parameters
• line_ray – A LineSegment2D or Ray2D that will be extended infinitely for intersection.

• arc – An Arc2D object along which the closest point will be determined.

Returns

A list of 2 Point2D objects if a full intersection exists. A list with a single Point2D object if the line is tangent or intersects only once. None if no intersection exists.