Questions tagged [line-intersection]

A common problem in is to find the intersection of two lines.

In the common case in two dimensions, the result is a point, which can be expressed as a parameter along one or both of the lines. For rays and line segments, the intersection of the containing lines is computed, then its parameters are checked to see whether the intersection falls within the subset of the line.

Common approaches produce poor answers for lines that are (nearly) parallel, so often an angle test is performed first. Parallel rays and line segments can intersect in a ray or line segment rather than a point.

Special search structures exist for finding intersections among many line segments.

In more than two dimensions, almost all pairs of lines have no intersection, but skew lines can be projected into the unique plane (through the origin) parallel to each. The intersection in that plane identifies the point of closest approach between the lines.

125 questions
515
votes
27 answers

How do you detect where two line segments intersect?

How do I determine whether or not two lines intersect, and if they do, at what x,y point?
KingNestor
  • 65,976
  • 51
  • 121
  • 152
52
votes
10 answers

Test if two lines intersect - JavaScript function

I've tried searching for a javascript function that will detect if two lines intersect each other. The function will take the x,y values of both the start end points for each line (we'll call them line A and line B). Is to return true if they…
Jarrod
  • 9,349
  • 5
  • 58
  • 73
39
votes
12 answers

Numpy and line intersections

How would I use numpy to calculate the intersection between two line segments? In the code I have segment1 = ((x1,y1),(x2,y2)) and segment2 = ((x1,y1),(x2,y2)). Note segment1 does not equal segment2. So in my code I've also been calculating the…
Xavier
  • 8,828
  • 13
  • 64
  • 98
21
votes
6 answers

Find the shortest distance between a point and line segments (not line)

I have set of line segments (not lines), (A1, B1), (A2, B2), (A3, B3), where A,B are ending points of the line segment. Each A and B has (x,y) coordinates. QUESTION: I need to know the shortest distance between point O and line segments as shown in…
Spider
  • 967
  • 3
  • 14
  • 35
20
votes
1 answer

Find the intersection points of all the line segments

Given a list of line segments, the easiest way to find the intersection points is to loop through the line segment list, check whether they are intersecting and record the intersection point if they do. But the runtime of this method is O(n^2),…
Graviton
  • 81,782
  • 146
  • 424
  • 602
12
votes
4 answers

Intersection between line and triangle in 3D

I have a line and a triangle somewhere in 3D space. In other words, I have 3 points ([x,y,z] each) for the triangle, and two points (also [x,y,z]) for the line. I need to figure out a way, hopefully using C++, to figure out if the line ever crosses…
Kaito Kid
  • 983
  • 4
  • 15
  • 34
10
votes
3 answers

How to find out the intersection of two coplanar lines in C

I have two 3D lines which lie on the same plane. line1 is defined by a point (x1, y1, z1) and its direction vector (a1, b1, c1) while line2 is defined by a point (x2, y2, z2) and its direction vector (a2, b2, c2). Then the parametric equations for…
Jin Yan
  • 199
  • 12
10
votes
2 answers

Line Drawing + Intersection of that line with self and also detect CCSprites inside that drawn Line

I am drawing the line using following code, it works just amazing, http://www.merowing.info/2012/04/drawing-smooth-lines-with-cocos2d-ios-inspired-by-paper/ Now I want to..... 1> Detect if the line Intersect with itself. 2) Detect if CCSprite is…
Anand
  • 1,129
  • 7
  • 29
9
votes
3 answers

Bentley-Ottmann Algorithm Implementation

Is there any existing Bentley-Ottmann Algorithm Implementation/library in C# or Java?
Sam
  • 933
  • 5
  • 14
  • 26
8
votes
2 answers

Algorithm to find intersections between polylines

Bentley-Ottmann algorithm works for finding intersections of set of straight lines. But I have lot of polylines: Is there a way to find intersections of the set of polylines? I'm figuring out, but in the meanwhile, if someone can give some pointers…
Sam
  • 933
  • 5
  • 14
  • 26
6
votes
0 answers

determine whether line intersects other lines on google map

I know there are various discussions on SO about line intersections and the math behind it. I am familiar with the math. This post nicely explains an algorithm one can implement: Determine if two lines intersect However, I was wondering whether one…
codingknob
  • 11,108
  • 25
  • 89
  • 126
6
votes
4 answers

Bentley-Ottmann algorithm for two groups of lines segments

The Bentley-Ottmann algorithm is used for the computation of intersection of line segments. However, instead of finding the intersecting points of all the lines among themselves, I want to find the intersecting points between two groups of lines.…
Graviton
  • 81,782
  • 146
  • 424
  • 602
5
votes
1 answer

Intersection point of QPainterPath and line (find QPainterPath y by x)

I have QPainterPath. I need to find y coordinate of QPainterPath by x. I found intersected() method in QPainterPath. So, I created new QPainterPath, which is line from left to right edge of my path's bounding rect with x coordinate, to find point as…
Funt
  • 399
  • 8
  • 23
5
votes
2 answers

Line/Plane intersection based on points

I have two points in space, L1 and L2 that defines two points on a line. I have three points in space, P1, P2 and P3 that 3 points on a plane. So given these inputs, at what point does the line intersect the plane? Fx. the plane equation…
5
votes
1 answer

Reduce time taken to find N line intersection

There are N line segments which are either Horizontal or vertical. Now I need to find out total number of Intersections and total number of Intersections per line segment. N can go upto 100000. I tried checking every pair of lines. The answer is…
sammy
  • 75
  • 8
1
2 3
8 9