Compute the coordinates of the intersection between a line and a polygon.
[I,IP] = NL_F_InterPolygonLine(P,a,b,Lx,Ly,d)
Polygon.
slope of the line.
y-intercept of the line.
Area width.
Area height.
Precision.
Vector of intersection points.
Vector of intersection points inluded in P.
NL_F_InterPolygonLine computes the list of intersection point between the convex polygon P=(P1x P1y P2x P2y ... Pnx Pny) defined by the list of its successive points' coordinates and the line defined by its equation y=a.x+b. We consider each segment of the polygon and compute the list I of intersection points between the previous line and all segments of P whose coordinates belong to the rectangle of size (Lx,Ly). IP is a subset of I where intersection points also belongs to the polygon P.
P=[200 400 300 600 500 600 700 500 800 200 500 100]; nx=P(1:2:$); ny=P(2:2:$); a=1; b=0; Lx=1000; Ly=1000; d=0.01; [I,IP]=NL_F_InterPolygonLine(P,a,b,Lx,Ly,d);//application of NL_F_InterPolygonLine g=NL_G_MakeGraph('NL_F_InterPolygonLine',length(nx),[],[],nx,ny); f=NL_G_ShowGraphN(g,1); xpoly(nx,ny,"lines",close=1); e=gce(); set(e,"foreground",5); ix=linspace(0,Lx,10); iy=a*ix+b; plot2d(ix,iy); | ![]() | ![]() |