Menu

#6 find intersection of two open paths (lines)

1.0
closed
nobody
None
2016-06-20
2015-09-25
Anonymous
No

Hi there,

This might be a silly question, but I am struggling to work out how to use clipper to determine if two open paths (lines) intersect or not. Eg with these paths:
var topHoriz = [{"X":10,"Y":10},{"X":110,"Y":10}];
var bottomHoriz = [{"X":10,"Y":110},{"X":110,"Y":110}];
var diag1 = [{"X":20,"Y":20},{"X":100,"Y":100}];
var diag2 = [{"X":20,"Y":100},{"X":100,"Y":20}];

How do i use clipper to determine that topHoriz and bottomHoriz do NOT intersect, whereas diag1 and diag2 DO?
(and neither diag line intersects with horiz lines)

Discussion

  • Timo Kähkönen

    Timo Kähkönen - 2015-09-25

    If those open paths consist only of one line segment, you could use line intersection algorithm (I made an example here: http://jsbin.com/gixufe/1/edit?html,js,output ). If those open paths consists of multiple segments, you could ask your question again in original Clipper's discussion forum (https://sourceforge.net/p/polyclipping/discussion/?source=navbar) because Javascript Clipper is nearly direct port of C# Clipper.

    However I assume that Clipper cannot make an intersection if both subject and clip are open paths. If I remember right, the clip has to be always closed path (polygon). If this is true, you can override this limitation by offsetting clip path by small amount to allow clipping. If your scale factor is eg. 1000, you can use eg. 0.1 as an offset delta.

    You could consider using an experimental floating point (double) Clipper, which is 4.15x faster than IntPoint version and when big integers are needed in IntPoint version, the float version is 8.37x faster than IntPoint version (measured in Chrome OSX). The final speed is actually a bit higher because IntPoint Clipper needs that coordinates are first scaled up (to integers) and then scaled down (to floats) and this scaling time is not taken into account in the above measurements. However float version is not fully tested and should be used with care in production environments.

    The code of experimental float version: http://jsclipper.sourceforge.net/6.1.3.4b_fpoint/clipper_unminified_6.1.3.4b_fpoint.js

    Demo: http://jsclipper.sourceforge.net/6.1.3.4b_fpoint/main_demo3.html

    Playground: http://jsbin.com/sisefo/1/edit?html,javascript,output

     

    Last edit: Timo Kähkönen 2015-09-25
  • Timo Kähkönen

    Timo Kähkönen - 2016-06-20
    • status: open --> closed
     

Log in to post a comment.