Previous: clppg2 Up: ../plot79_c.html Next: clpph
SUBROUTINE CLPPG3 (P1,P2, XVERTX,INCX, YVERTX,INCY, ZVERTX,INCZ, X NVERTX, ALPHA,NALPHA) C$ (3-Dimensional Clip to General Polygon) C$ Clip a line segment defined by its endpoints in C$ 3-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,z) coordinates of first point. C$ P2(*)..........(x,y,z) 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$ ZVERTX(*)......z coordinates of polygon vertices. C$ INCZ...........Increment between successive coordinates in C$ ZVERTX(*) (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, INCY, or INCZ is negative, the C$ starting vertex is taken as (1-NVERTX)*INC + 1 instead of C$ 1, so that 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, INCY, INCZ parameters, in C$ order to get an interior polygon, then taking the C$ complement of the set of alpha's returned to obtain the C$ exterior line segments. This could be used to advantage in C$ a mapping application to clip against regions containing C$ embedded islands. C$ C$ Although the z coordinates are specified, the edge normals C$ are defined to have z = 0 (i.e., the polygon is assumed to C$ lie in the xy plane). However, the z coordinates **are** C$ used in determining whether the line segment intersects an C$ edge. C$ (17-SEP-81)