INTERSECTLINEPOLYGON Intersection points between a line and a polygon. P = intersectLinePolygon(LINE, POLY) Returns the intersection points of the lines LINE with polygon POLY. LINE is a 1-by-4 row vector containing parametric representation of the line (in the format [x0 y0 dx dy], see the function 'createLine' for details). POLY is a NV-by-2 array containing coordinates of the polygon vertices P is a K-by-2 array containing the coordinates of the K intersection points. P = intersectLinePolygon(LINE, POLY, TOL) Specifies the tolerance for geometric tests. Default is 1e-14. [P, INDS] = intersectLinePolygon(...) Also returns the indices of edges involved in intersections. INDS is a K-by-1 column vector, such that P(i,:) corresponds to intersection of the line with the i-th edge of the polygon. If the intersection occurs at a polygon vertex, the index of only one of the two neighbor edges is returned. Note that due to numerical approximations, the use of function 'isPointOnEdge' may give results not consistent with this function. Examples % compute intersections between a square and an horizontal line poly = [0 0;10 0;10 10;0 10]; line = [5 5 1 0]; intersectLinePolygon(line, poly) ans = 10 5 0 5 % also return indices of edges [inters, inds] = intersectLinePolygon(line, poly) inters = 10 5 0 5 inds = 4 2 % compute intersections between a square and a diagonal line poly = [0 0;10 0;10 10;0 10]; line = [5 5 1 1]; intersectLinePolygon(line, poly) ans = 0 0 10 10 See Also lines2d, polygons2d, intersectLines, intersectRayPolygon, polygonEdges
Package: matgeom