two_line_segment_intersection#

regridding.geometry.two_line_segment_intersection(p1, p2, t)[source]#

Compute the point of intersection between two line segments.

Uses the parameter computed by two_line_segment_intersection_parameters() as an input.

Parameters:
  • p1 (tuple[float, float]) – The starting point of the line segment.

  • p2 (tuple[float, float]) – The ending point of the line segment.

  • t (float) – The intersection parameter corresponding to p1 and p2.

Return type:

tuple[float, float]

Examples

Plot two lines and their intersection.

import numpy as np
import matplotlib.pyplot as plt
import regridding

# line P
p = (
    (0, 0),
    (2, 2),
)

# line Q
q = (
    (0, 1),
    (2, 0),
)

t, u = regridding.geometry.two_line_segment_intersection_parameters(
    p1=p[0],
    p2=p[1],
    q1=q[0],
    q2=q[1],
)

x, y = regridding.geometry.two_line_segment_intersection(
    p1=p[0],
    p2=p[1],
    t=t,
)

# Convert the lines to arrays for easier plotting
p = np.array(p)
q = np.array(q)

plt.figure()
plt.plot(p[..., 0], p[..., 1], label="line $p$")
plt.plot(q[..., 0], q[..., 1], label="line $q$")
plt.scatter(x, y, color="black", zorder=10, label="intersection")
plt.legend();
../_images/regridding.geometry.two_line_segment_intersection_0_0.png