Jump to content

Parallel line segment intersection


Reicher
 Share

Recommended Posts

I'm working on a little game(http://trans-neptunian-studios.com/Snatris/Beta/) that uses Phaser 2.3.0.

In my game i have a chain of connected lines segments (Phaser.Line). I want to detect when any of these segments intersect. I have found a problem with how Phaser.Line.intersects work. A simple example:

var line1 = new Phaser.Line(0, 0, 100, 0);

var line2 = new Phaser.Line(40, 0, 60, 0);

console.log(line1.intersects(line2));

console.log(line2.intersects(line1));

The two segments line1 and line2 are not only parallel but also on top of each other. Phaser.Line.intersects does not recognize this type of intersection. I understand that in a pure "math-sense" parallel lines cannot intersect or rather they do intersect on infinite many places.

What is the easiest way to detect the "intersection"? Keep in mind that I have many lines in my game and need a general solution.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...