How to detect if two lines are intersecting?

So if you have two lines, and they both can be curvy or straight, how do you tell if they are intersecting? Is there a way to do it with colours?

Start by search collision here in the forum please

2 Likes
3 Likes

However: nothing in Thompson’s book will talk about “curvy” lines. If they are segments of a circle, you can use circle collision, but otherwise you are in for some more serious math that isn’t covered there. What kinds of “curvy lines” do you mean? Splines / Bezier curves? Are they defined by a mathematical formula, or are they being drawn using Processing functions like curveVertex()…?

1 Like

I meant circle. Sorry for confusion

Yes, sort of. This is called “picking.” You use a buffer, and you check a point or points to see if the value in the buffer matches. It doesn’t work as well or easily with lines as it does with closed shapes (circles, ellipses, rects, polygons, etc.) – it is better for testing the location of a mouse pointer than for line-line intersection.

Oh okay. What’s a buffer?

In this case, either an off-screen PImage / PGraphics object or a 2D array of numbers, one per pixel / point.

See for example the Picking Library http://n.clavaud.free.fr/processing/library/picking/