Clipping 15. Clipping Procedures for eliminating all parts of primitives outside of the specified view volume are referred to as clipping algorithms or simply clipping This takes place as part of the Projection and Perspective Division transformations Eye Coordinates Projection Matrix Projection Transformation Clip Coordinates Perspective Division Normalized Device Coordinates Projection is actually a two step process that is not completed until after the Perspective Division operation Clipping is done following the perspective normalization transformation E.R. Bachmann & P.L. McDowell MV 4202 Page 1 of 6 Clipping • Normalized View Volumes Clipping against a regular parallelepiped is simplified because each clipping plane is perpendicular to one of the coordinate axes - Finding the intersection of a line with a plane at an arbitrary spatial orientation requires finding the equation for the plane and floating point division - In a parallelepiped: ◊ bottom and top clipping planes have a constant y coordinate ◊ right and left clipping planes have a constant x coordinate ◊ near and far clipping planes have a constant z coordinate ♦ Perspective Normalization Transformation Prior to clipping, the frustum, used for perspective projection, is reduced to a rectangular parallelepiped using shearing and scaling - Shearing in the x and y directions puts the center of projection on a line perpendicular to the projection plane - Scaling converts the sides of the frustum into rectangular sides of a parallelepiped - All points in the frustum are moved into the parallelepiped E.R. Bachmann & P.L. McDowell MV 4202 Page 2 of 6 Clipping • Perspective Projection Revisited The perspective projection matrix used in OpenGL 2n 0 r −1 2n 0 P= t −b 0 0 0 0 r +1 r −1 t +b t −b − ( f + n) f −n −1 0 0 − 2 fn f −n 0 (15.1) is the result of a multiplication by a shear matrix, H, a scaling matrix, S, and finally a projection normalization matrix, N. P = NSH (15.2) Following multiplication by this matrix, the viewing volume becomes a parallelepiped which is bounded by the planes E.R. Bachmann & P.L. McDowell x = ±1 (15.3) y = ±1 (15.4) z=0 (15.5) z =1 (15.6) MV 4202 Page 3 of 6 Clipping (x, y, z) center of proj. proj. plane (x’, y’, z’) viewing volume center of proj. near far proj. plane near far • Clipping Lines Against a Normalized View Volume Once primitives have been converted to normalized coordinates each vertex is checked against each of the six clipping planes Each vertex is assigned a six bit region code that identifies the relative position with respect to the viewing volume bit 1 = 1, if x < xvmin (left) - least significant bit bit 2 = 1, if x > xvmax (right) bit 3 = 1, if y < yvmin (below) bit 4 = 1, if y > yvmax (top) bit 5 = 1, if z < zvmin (front) bit 6 = 1, if z > zvmax (back) - A code of 000000 identifies a point within the viewing volume E.R. Bachmann & P.L. McDowell MV 4202 Page 4 of 6 Clipping - A code of 101000 identifies a point as above and behind the viewing volume - A line segment for which both end points have a region code of 000000 is entirely within the viewing volume - If only one end point is within the viewing volume, the line must be clipped In order to clip a line, the intersection of the line with the clipping plane must be found Recall the parametric equation for a line x = (x2 - x1) * t + x1 (15.7) y = (y2 - y1) * t + y1 (15.8) z = (z2 - z1) * t + z1 (15.9) for t in the range [0,1] To find the intersection, substitute the constant coordinate of the clipping plane into the appropriate parametric equation and solve for t E.R. Bachmann & P.L. McDowell MV 4202 Page 5 of 6 Clipping For the near clipping plane t= min − z1 z 2 − z1 zv (15.10) The x and y coordinates of the intersection are given by zv min -z1 xI = x1 + ( x2 − x1 ) z 2 − z1 (15.11) zv min − z1 y I = y1 + ( y2 − y1 ) z 2 − z1 (15.12) If either xI or yI is not in the range of the boundaries of the viewing volume, the line intersects the front plane outside the volume • Polygon Clipping Polygon clipping algorithms must deal with many different cases - New edges must be added - Existing edges must be discarded, retained or divided - Multiple polygons may result from clipping a single polygon E.R. Bachmann & P.L. McDowell MV 4202 Page 6 of 6
© Copyright 2026 Paperzz