Page 2 of 2 FirstFirst 12
Results 11 to 15 of 15

Thread: How to detect an intersection between two lines?

  1. #11

    How to detect an intersection between two lines?

    You will have to repaste your code. The posting process with Disable HTML unchecked mangles the code, so just unchecking the box does nothing by itself.

  2. #12

    How to detect an intersection between two lines?

    I see. Ok, what about now?
    Jarrod Davis
    Technical Director @ Piradyne Games

  3. #13

    How to detect an intersection between two lines?

    Okay, I've solved the problem. I checked out my math book and read that two segments with the same point intersect (i.e. 1;2 and 2;3). :shock:

    That was my bad from the very beginning. ops:

  4. #14

    How to detect an intersection between two lines?

    Hi Brainer :-)

    I'd just thought I'd let you know that the code you posted (http://pastebin.com/f4d5572a7) appears to be incorrect...

    I believe the code should be this (ignoring optimizations):

    [pascal]function LinesCross(x0, y0, x1, y1, x2, y2, x3, y3 : Integer): Boolean;
    var
    D, AB, CD: Single;
    begin
    D := (x1 - x0) * (y3 - y2) - (y1 - y0) * (x3 - x2);
    if (Abs(D) < 0.001) then
    begin
    Result := False;
    exit;
    end;
    AB := ((y0 - y2) * (x3 - x2) -(x0 - x2) * (y3 - y2)) / D;
    if (AB > 0.0) and (AB < 1.0) then
    begin
    CD := ((y0 - y2) * (x1 - x0) - (x0 - x2) * (y1 - y0)) / D;
    if (CD > 0.0) and (CD < 1.0) then
    begin
    Result := True;
    exit;
    end;
    end;
    Result := False;
    end;[/pascal]

    It should only get to the innermost Begin-End block and make the result true if the lines do cross...

    This page may help (http://local.wasp.uwa.edu.au/~pbourk...ry/lineline2d/)
    cheers,
    Paul

  5. #15

    How to detect an intersection between two lines?

    Hello, Paul.

    You know, right now I'm using a totally different code and everything seems working OK. Anyway, thanks for your post!

Page 2 of 2 FirstFirst 12

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •