Closed tiansivive closed 1 year ago
Hello, @tiansivive ,
Method polygon.cut()
does not support line as input.
In fact, it accept multiline
, which is sequence of of rays and segments, and indeed, segment should start and end on polygon edges. The code that will work:
const { polygon, point, vector, line, multiline } = Flatten;
const poly = polygon([[0, 0], [100, 0], [100, 100], [0, 100]]);
const l = line(point(50, 0), vector(1, 0));
const ip = l.intersect(poly);
const ip_sorted = l.sortPoints(ip);
const ml = multiline([l]).split(ip_sorted);
const [p1, p2] = poly.cut(ml);
return [p1, p2];
See the notebook: https://observablehq.com/d/ca0842f3e3e1b35b
Later I will add support for line too.
Best, Alex
Thanks for the example! The docs mention that Multiline could be a Line as well, so if it's not expected to work with Line, maybe we could just update the docs for the time being?
I updated documentation Currently this option is not supported
From looking through the source code, it looks as if you're only able to cut a polygon into two if the "cutting line" is a segment with points on the polygon edges.
Anything else seems to fail, for example:
I'd expect this to split the polygon into 2, but instead
p2
is undefined andp1
is just a copy ofpolygon