Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find if a line intersects itself in JTS?

Is there any way to find out if a LineString intersects itself in JTS? Like in the following image how can i find if the line intersects itself? I am creating that line by just giving coordinates of its 4 edges.

enter image description here

Thanks in advance.

like image 595
Piscean Avatar asked Nov 16 '25 02:11

Piscean


1 Answers

No line can intersect itself. You don't have "a line"; you have four lines. You want to see if two of them intersect each other.

You can either calculate the intersection explicitly or look at how the coordinates are labeled. If you start in the lower right and number the points as A, B, C, and D by going counterclockwise, you can see that you have an intersection if there are lines connect AC and BD. If they connect AB, BC, CD, and DA there's no intersection possible except at the common points.

like image 99
duffymo Avatar answered Nov 18 '25 19:11

duffymo