Previous: clpp4 Up: ../plot79_c.html Next: clppg3
SUBROUTINE CLPPG2 (P1,P2, XVERTX,INCX, YVERTX,INCY, NVERTX, X ALPHA,NALPHA) C$ (2-Dimensional Clip to General Polygon) C$ Clip a line segment defined by its endpoints in C$ 2-dimensional coordinates to a general (convex or concave) C$ polygon defined by its vertices. The clipping may produce C$ zero or more line segments defined by a vector ALPHA(*) of C$ parameter pairs such that points are defined by P(ALPHA) = C$ P1 + ALPHA(I)*(P2 - P1). C$ C$ The input arguments are: C$ C$ P1(*)..........(x,y) coordinates of first point. C$ P2(*)..........(x,y) coordinates of second point. C$ XVERTX(*)......x coordinates of polygon vertices. C$ INCX...........Increment between successive coordinates in C$ XVERTX(*) (normally 1). C$ YVERTX(*)......y coordinates of polygon vertices. C$ INCY...........Increment between successive coordinates in C$ YVERTX(*) (normally 1). C$ NVERTX.........Number of polygon vertices. Vertex NVERTX C$ is implicitly connected to vertex 1 to close C$ the polygon. C$ C$ The output arguments are: C$ C$ ALPHA(*).......Parameters for the endpoints of line C$ segments in the parametric line C$ representation (1-ALPHA)*P1 + ALPHA*P2. On C$ output, values will be in strictly ascending C$ order, each pair defining a visible segment. C$ The array must be large enough to contain at C$ least 2*NVERTX values. C$ NALPHA.........Number of parameters returned in ALPHA(*). C$ The output value is always even. C$ C$ If an increment INCX or INCY is negative, the starting C$ vertex is taken as (1-NVERTX)*INC + 1 instead of 1, so that C$ the array is stepped through in reverse order. C$ C$ The polygon vertices are assumed to be arranged so that the C$ interior lies to the left of each line segment between C$ vertices i and i+1. Thus, reversing the order of the C$ vertices will exchange the exterior and interior. The set C$ of alpha's returned will be correct only if the polygon is C$ an interior one. Determination of whether a point is C$ inside or outside requires counting edges to the left of C$ the point, and the parity of the count is odd for an inside C$ point in an interior polygon, and even for an exterior C$ polygon. Thus, the interior/exterior character of a C$ polygon cannot be determined without examining all of its C$ edges. This routine can be used for this determination if C$ a tiny line segment just inside the visible side of one C$ edge is passed for clipping. If NALPHA = 0 on return, the C$ polygon is an exterior polygon. If NALPHA = 2, it must be C$ an interior polygon. C$ C$ Clipping against an exterior polygon may be done by C$ reversing the order of the vertices explicitly, or C$ implicitly with negative INCX and INCY parameters, in order C$ to get an interior polygon, then taking the complement of C$ the set of alpha's returned to obtain the exterior line C$ segments. This could be used to advantage in a mapping C$ application to clip against regions containing embedded C$ islands. C$ C$ (03-APR-82)