If we are extracting data from the given dataset and we are able to plot two line segments based on that data. How to find the intersection point of those two line segments?
Asked
Active
Viewed 112 times
2
-
you can: a)Look at the plot, or b) get the equations of both lines and intersect them analitically (I would go for b) – E.Serra Jun 08 '20 at 15:15
-
There is also [this sublime post](https://stackoverflow.com/questions/46909373/how-to-find-the-exact-intersection-of-a-curve-as-np-array-with-y-0/46911822#46911822) to find intersections between curves (which are represented by short linear segments in numpy arrays). – JohanC Jun 08 '20 at 16:30
1 Answers
1
From the two lines' slope and intersections, you can analytically derive and solve for their mutual intersection point in the following manner:
# slopes and interceptions
m1, b1 = .5, 2.0 # line 1
m2, b2 = 3.0, -3.0 # line 2
# mutual intersection point, x and y coordinate:
xi = (b1-b2) / (m2-m1)
yi = m1 * xi + b1
print(f"(xi, yi) = ({xi}, {yi})")
Returns
(xi, yi) = (2, 3)
See the lines with mutual intersection below for illustration:
And should you not have the slopes or intersections directly available, these can be computed from any two points from each line, see for example http://www.math.com/school/subject2/lessons/S2U4L2GL.html#:~:text=The%20equation%20of%20any%20straight,line%20crosses%20the%20y%20axis.

Gustav Rasmussen
- 3,720
- 4
- 23
- 53