Skip to content

Commit

Permalink
Added example to the `regridding.geometry.two_line_segment_intersecti…
Browse files Browse the repository at this point in the history
…on_parameters()` documentation.
  • Loading branch information
byrdie committed Dec 3, 2023
1 parent ef8f0ac commit b59b906
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions regridding/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,48 @@ def two_line_segment_intersection_parameters(
y_q2
:math:`x` component of the second point in line :math:`q`
Examples
--------
Plot two lines and their intersection
.. jupyter-execute::
import matplotlib.pyplot as plt
import regridding
# line P
x_p1 = 0
y_p1 = 0
x_p2 = 2
y_p2 = 2
# line Q
x_q1 = 0
y_q1 = 1
x_q2 = 2
y_q2 = 0
sdet, tdet, det = regridding.geometry.two_line_segment_intersection_parameters(
x_p1=x_p1, y_p1=y_p1,
x_p2=x_p2, y_p2=y_p2,
x_q1=x_q1, y_q1=y_q1,
x_q2=x_q2, y_q2=y_q2,
)
s = sdet / det
x = (1 - s) * x_p1 + s * x_p2
y = (1 - s) * y_p1 + s * y_p2
plt.figure()
plt.plot([x_p1, x_p2], [y_p1, y_p2], label="line $p$")
plt.plot([x_q1, x_q2], [y_q1, y_q2], label="line $q$")
plt.scatter(x, y, color="black", zorder=10, label="intersection")
plt.legend();
|
References
----------
Expand Down

0 comments on commit b59b906

Please sign in to comment.