Languages
[Edit]
EN

JavaScript - calculate intersection point of two lines for given 4 points

6 points
Created by:
Blythe-F
650

Intersection point formula for given two points on each line should be calculated in the following way:

Intersection point formula for given two points on each line
Intersection point formula for given two points on each line

Where: L1 and L2 represent points on line 1 and line 2 calculated with linear parametric equation. Points (x1, y1) and (x2, y2) are located on line 1(x3, y3) and (x4, y4) are located on line 2.

Practical example

Edit
Example intersection point calculated in JavaScript.
Example intersection point calculated in JavaScript.

Using JavaScript it is possible to calculate intersection points using the above formula in the following way:

 

1. Intersection point + drawing result example

Edit

In this section, we can see example calculations and visualization of a cross point on the canvas.

An Animated version of this article has been presented here.

See also

Edit
  1. JavaScript - how to draw point on canvas element?

Alternative titles

  1. JavaScript - how to calculate cross point of two lines for given 4 points?
  2. JavaScript - how to calculate intersection point of two lines for given 4 points?
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join