We are about to switch to a new forum software. Until then we have removed the registration on this forum.
The little sketch shows two random lines, my question is how to check do the lines intersect or not?
float x1;
float y1;
float x2;
float y2;
float x3;
float y3;
float x4;
float y4;
void setup()
{
size(800,800);
x1 = random(100,width-100);
y1 = random(100,height-100);
x2 = random(100,width-100);
y2 = random(100,height-100);
x3 = random(100,width-100);
y3 = random(100,height-100);
x4 = random(100,width-100);
y4 = random(100,height-100);
}
void draw()
{
stroke(155,0,0);
line(x1,y1,x2,y2);
stroke(0,0,155);
line(x3,y3,x4,y4);
}
Answers
@djevazi --
Use line-line collision detection:
http://www.jeffreythompson.org/collision-detection/line-line.php
Also checking whether all points are on different sides of the other line works
@jeremydouglass , thanks, I almost forgot that you sent me that article about collisions few month ago : )
@prince_polka, thank you.