M
M
Mark Berezovsky2021-01-29 15:41:48
JavaScript
Mark Berezovsky, 2021-01-29 15:41:48

How to find the point of intersection of two segments?

Hello Habr!
Since I am a noob in geometry, I ask you to help with one case:
I have 4 points, these are two points of the beam (beginning and direction) and two points of the segment. I need, given these four points, to find the point of their intersection (and also to find out if they intersect at all). Very much I ask to result function for a finding. Function type:

const getCollisionPoint = (r1, r2, s1, s2) => ...
// где r1 и r2 - точки луча([x1, y1] и [x2, y2]),
// а s1 и s2 - точки отрезка([x3, y3] и [x4, y4])

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
hint000, 2021-01-29
@soiran

It is done in three simple steps:
1. write the equations of the lines on which the segments lie
2. find the point of intersection of the lines: https://www.google.com/search?q=intersection+of the lines...
3. determine if this line lies point within lines

Very much I ask to result function for a finding.
Then it will be a task, not a question. This is removed by the moderators - okay?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question