Quantcast
Channel: How can I check if two segments intersect? - Stack Overflow
Browsing all 27 articles
Browse latest View live

Answer by Bram Cohen for How can I check if two segments intersect?

Here is some Python code which is bulletproof against all the colinearity edge cases and roundoff error problems.epsilon = 0.000001def is_intersecting(x1, y1, x2, y2, x3, y3, x4, y4): c_area = area(x1,...

View Article



Answer by MBV for How can I check if two segments intersect?

if anybody wants to do a C-like speed look up for multiple lines intersections you could use this code done in numba and pythonNotethe epsilon argument should be proportional to your line distance....

View Article

Answer by Angus Johnson for How can I check if two segments intersect?

Digging up an old thread and modifying Grumdrig's code ...template <typename T>struct Point { T x; T y; Point(T x_, T y_) : x(x_), y(y_) {};};template <typename T>inline T...

View Article

Answer by NY Reno for How can I check if two segments intersect?

Using OMG_Peanuts solution, I translated to SQL.(HANA Scalar Function)Thanks OMG_Peanuts, it works great.I am using round earth, but distances are small, so I figure its okay.FUNCTION GA_INTERSECT" (...

View Article

Answer by BenMan95 for How can I check if two segments intersect?

Here's a solution using dot products:# assumes line segments are stored in the format [(x0,y0),(x1,y1)]def intersects(s0,s1): dx0 = s0[1][0]-s0[0][0] dx1 = s1[1][0]-s1[0][0] dy0 = s0[1][1]-s0[0][1] dy1...

View Article


Answer by asylumax for How can I check if two segments intersect?

The answer by Georgy is the cleanest to implement, by far. Had to chase this down, since the brycboe example, while simple as well, had issues with colinearity.Code for testing:#!/usr/bin/python##...

View Article

Answer by user1766438 for How can I check if two segments intersect?

One of the solutions above worked so well I decided to write a complete demonstration program using wxPython. You should be able to run this program like this: python "your file name"# Click on the...

View Article

Image may be NSFW.
Clik here to view.

Answer by Georgy for How can I check if two segments intersect?

Checking if line segments intersect is very easy with Shapely library using intersects method:from shapely.geometry import LineStringline = LineString([(0, 0), (1, 1)])other = LineString([(0, 1), (1,...

View Article


Answer by Jason Hoffoss for How can I check if two segments intersect?

This is my way of checking for line crossing and where the intersection occurs. Lets use x1 through x4 and y1 through y4Segment1 = ((X1, Y1), (X2, Y2))Segment2 = ((X3, Y3), (X4, Y4))Then we need some...

View Article


Answer by user3003999 for How can I check if two segments intersect?

We can also solve this utilizing vectors. Let's define the segments as [start, end]. Given two such segments [A, B] and [C, D] that both have non-zero length, we can choose one of the endpoints to be...

View Article

Answer by Matej Ukmar for How can I check if two segments intersect?

I thought I'd contribute a nice Swift solution:struct Pt { var x: Double var y: Double}struct LineSegment { var p1: Pt var p2: Pt}func doLineSegmentsIntersect(ls1: LineSegment, ls2: LineSegment) ->...

View Article

Answer by Fabian Ying for How can I check if two segments intersect?

Here is another python code to check whether closed segments intersect. It is the rewritten version of the C++ code in http://www.cdn.geeksforgeeks.org/check-if-two-given-line-segments-intersect/. This...

View Article

Answer by achyuthan_jr for How can I check if two segments intersect?

Since you do not mention that you want to find the intersection point of the line, the problem becomes simpler to solve. If you need the intersection point, then the answer by OMG_peanuts is a faster...

View Article


Answer by dmitri for How can I check if two segments intersect?

Based on Liran's and Grumdrig's excellent answers here is a complete Python code to verify if closed segments do intersect. Works for collinear segments, segments parallel to axis Y, degenerate...

View Article

Answer by Vlad for How can I check if two segments intersect?

Here is C++ code to check if two points are on the opposite sides of the line segment. Using this code you can check if two segments intersect as well.// true if points p1, p2 lie on the opposite sides...

View Article


Answer by Wanderer for How can I check if two segments intersect?

Implemented in JAVA. However It seems that it does not work for co-linear lines (aka line segments that exist within each other L1(0,0)(10,10) L2(1,1)(2,2)public class TestCode{ public class Point {...

View Article

Answer by Love Sharma for How can I check if two segments intersect?

Resolved but still why not with python... :)def islineintersect(line1, line2): i1 = [min(line1[0][0], line1[1][0]), max(line1[0][0], line1[1][0])] i2 = [min(line2[0][0], line2[1][0]), max(line2[0][0],...

View Article


Answer by Grumdrig for How can I check if two segments intersect?

User @i_4_got points to this page with a very efficent solution in Python. I reproduce it here for convenience (since it would have made me happy to have it here):def ccw(A,B,C): return (C.y-A.y) *...

View Article

Answer by Anonymous for How can I check if two segments intersect?

for segments AB and CD, find the slope of CDslope=(Dy-Cy)/(Dx-Cx)extend CD over A and B, and take the distance to CD going straight updist1=slope*(Cx-Ax)+Ay-Cydist2=slope*(Dx-Ax)+Ay-Dycheck if they are...

View Article

Answer by Daniel for How can I check if two segments intersect?

This is what I've got for AS3, don't know much about python but the concept is there public function getIntersectingPointF($A:Point, $B:Point, $C:Point, $D:Point):Number { var A:Point = $A.clone(); var...

View Article
Browsing all 27 articles
Browse latest View live




Latest Images