12, Chap 6
Course Delivery by Dr. K. Satyanarayan Reddy
Text Book Computer Graphics: Principles and Practice in C, 2nd edition Pearson education. By James D. Foley, A. Van Dam, S.K. Feiner, and J.F. Hughes
The application programmer specifies a rectangular region in world coordinates called the World coordinate Window, and at corresponding rectangular region in Screen Coordinates, called the Viewport into which the world-coordinate window is to be mapped. The transformation that maps the World coordinate Window into the Viewport is applied to all of the output primitives in world coordinates, thus mapping them into screen coordinates. Following Figure shows this transformation.
November 22, 2013 BITS WASE Computer Graphics: Course Delivered by Dr. K. Satyanarayan Reddy 2
As seen in this figure, if the WINDOW and VIEWPORT do not have the same height-to-width ratio, a non-uniform scaling occurs.
The effect of drawing output primitives with two viewports. Output primitives specifying the house were first drawn with viewport 1, the viewport was changed to viewport 2, and then the application program again called the graphics package to draw the output primitives.
November 22, 2013 BITS WASE Computer Graphics: Course Delivered by Dr. K. Satyanarayan Reddy 4
THE WINDOW - TO - VIEWPORT TRANSFORMATION contd. Question: Given a Window and Viewport, what is the transformation matrix that maps the window from world coordinates into the viewport in screen coordinates? Answer: This matrix can be developed as a 3 - step Transformation composition, as suggested in following Figure
Geometrical Transformations
The window, specified by its Lower - left and Upperright comers, is first translated to the origin of world coordinates. Next, the size of the window is scaled to be equal to the size of the viewport.
CLIPPING LINES
Lines intersecting a rectangular clip region (or any convex polygon) are always clipped to a single line segment; lines lying on the clip rectangles border are considered inside and hence are displayed. Figure below shows several examples of clipped lines.
Rectangular Clip Region
Clipping Endpoints
lf the x coordinate boundaries of the clip rectangle are at xmin and xmax, and the y coordinate boundaries are at ymin and ymax, then four inequalities must be satisfied for a point at (x, y) to be inside the clip rectangle: xmin x xmax and ymin y ymax lf any of the four inequalities does not hold, the point is outside the clip rectangle.
10
11
The brute-force approach to clipping a line that cannot be trivially accepted is to intersect that Line with each of the four clip-rectangle edges to see whether any intersection points lie on those edges; if so, the line cuts the clip rectangle and is partially inside. For each line and clip-rectangle edge, the two mathematically infinite lines are taken which contain them and intersect them. Next, it is tested whether this intersection point is "interior"that is, whether it lies within both the clip rectangle edge and the line; if so, there is an intersection with the clip rectangle. In Fig in previous slide, intersection points G' and H are interior, but I' and J' are not.
November 22, 2013 BITS WASE Computer Graphics: Course Delivered by Dr. K. Satyanarayan Reddy 12
A parametric formulation for line segments is used: x = x0 + t(x1 x0); y = y0 + t(y0 y1) These equations describe (x, y) on the directed line segment from (x0, y0) to (x1, y1) for the parameter t in the range [0, 1] as simple substitution for t confirms. Two sets simultaneous equations of this parametric form can be solved tor parameters tedge for the edge and tline for the line segment. The values of tedge and tline can then be checked to see whether both lie in [0, 1]; if they do, the intersection point lies within both segments and is a true clip rectangle intersection.
November 22, 2013 BITS WASE Computer Graphics: Course Delivered by Dr. K. Satyanarayan Reddy 13
First bit outside halfplane of top edge, above top edge y > ymax Second bit outside halfplane of bottom edge, below bottom edge y < ymin Third bit outside halfplane of right edge. to the right of right edge x > xmax Fourth bit outside halfplane of left edge, to the left of left edge x < xmin,
November 22, 2013 BITS WASE Computer Graphics: Course Delivered by Dr. K. Satyanarayan Reddy 15
17
20
21
22
24
25
B
F E
C
A D
G H
Clip Rectangle
Division of Space
ymax
Clip Region
ymin
x min
x max
ymax
xmax
b0
b1
y ymin
b2
b3
x xmin
b1
1000
1010
0001
0000
0010
ymin
0101
0100
0110
x min
x max
1001
ymax
1000
1010
P1
0001
P0
0000
0010
ymin
0101
x min
0100
x max
0110
1001
ymax
P0
1000
1010
P1
P0
0001
0000
0010
ymin
P0 P1 P1
0101
x min
0100
x max
0110
Cohen-Sutherland Clipping:
1001
ymax
P0
O(P0) =0 , O(P1)
1000
1010
0001
P1
0000
P0
0010
P1
ymin
P0
0101
x min
0100
P1
0110
x max
1001
ymax
1000
B C
1010
0001
0000
0010
ymin
0101
x min
0100
x max
0110
1000
B C
1010
0001
0000
0010
ymin
0101
x min
0100
x max
0110
1000
1010
E
0001
0000
0010
ymin
A
0101
x min
0100
x max
0110
1000
1010
E
0001
0000
0010
ymin
0101
x min
0100
x max
0110
1000
1010
0001
0000
0010
ymin
0101
x min
0100
x max
0110
1000
1010
0001
0000
0010
ymin
0101
x min
0100
x max
0110
to the outcode for the z axis. Calculations then reduce to intersection of line with
plane Algorithm most efficient when most segments can
can clip in fewer steps than CohenSutherland try to increase number of trivial rejection cases
p1
p(1)
p0
p ( 0)
p( )
p( )
(1
)p 0
p1
Liang-Barsky Clipping
Consider the parametric form of a line segment
p( ) = (1- )p1+ p2 1
We can distinguish between the cases by looking at the ordering of the values of where the line determined by the line segment crosses the lines that determine the window p
2
p1
(p1 p 0 )
p Ei
Ni p( ) p Ei 0
p1
Ni p( ) p Ei 0
p0
Ni
Ni p( ) p Ei
p1 p1
p0
Ni
Potentially Entering (PE) Point
p0
Ni
Potentially Leaving (PL) Point
N i p1 p 0
N i p1 p 0
Ni p( ) p Ei
p( ) p0
(p1 p 0 )
Ni p0 p Ei
Let D (p1
Ni p1 p0
0
:
Ni p0
p Ei
Ni D
ymax
PL PL
p1
p1
PL PL
p0 p0
PE
PE
ymin
PE
p0
x min
x max
= Inside
Liang-Barsky Clipping: Algorithm Strategy Find the largest PE greater than zero. Find the smallest PL less than one. Reject the segment if PE > PL.
Viewing in 3D
The 3D viewing process is inherently more complex than is the 2D viewing process. The extra complexity of 3D viewing is caused in part by the added dimension and in part by the fact that display devices are only 2D.
The solution to the mismatch between 3D objects and 2D displays is accomplished by introducing projections, which transform 3D objects onto 2D projection plane.
November 22, 2013 BITS WASE Computer Graphics: Course Delivered by Dr. K. Satyanarayan Reddy 51
Viewing in 3D contd.....
In 3D viewing, a view volume is specified in the world, a projection onto a projection plane, and a viewport on the view surface. Conceptually, objects in the 3D world are clipped against the 3D view volume and are then projected. The contents of the projection of the view volume onto the projection plane, called the WINDOW, are then transformed (mapped) into the VIEWPORT for display. Figure 6.1 shows this conceptual model of the 3D viewing process, which is the model presented to the users of numerous 3D graphics subroutine packages.
52
PROJECTIONS
In general, projections transform points in a coordinate system of dimension n into points in a coordinate system of dimension less than n. The projection of a 3D object is defined by straight Projection Rays (called PROJECTORS) emanating from a center of projection, passing through each point of the object, and intersecting a projection plane to form the projection. Figure below shows two different projections of the same line. Fortunately, the projection of a line is itself a line, so only line endpoints need actually to be projected.
53
PROJECTIONS contd.
Planar geometric projections, hereafter referred to simply as projections, can be divided into two basic classes: PERSPECTIVE and PARALLEL. The distinction is in the relation of the Center of Projection (CoP)to the Projection Plane. If the distance from the CoP to the Projection Plane is Finite, then the projection is PERSPECTIVE; if the Distance is Infinite, the projection is PARALLEL.
November 22, 2013 BITS WASE Computer Graphics: Course Delivered by Dr. K. Satyanarayan Reddy 54
PROJECTIONS contd.
The parallel projection is so named because, with the center of projection infinitely distant, the projectors are parallel. When defining a Perspective Projection, its Center of Projection is explicitly specified; direction of projection is given for a parallel projection. The Center of Projection, being a point, it has homogeneous coordinates of the form (x, y, z, 1). Since the direction of projection is a vector (i.e. a difference between points). it can be computed by subtracting two points d = (x. y, z, 1) - (x' , y', z', 1) = (a, b, c, 0). A perspective projection whose center is a point at infinity becomes a parallel projection.
November 22, 2013 BITS WASE Computer Graphics: Course Delivered by Dr. K. Satyanarayan Reddy 55
Perspective Projections
The perspective projections of any set of parallel lines that are not parallel to the projection plane converge to a Vanishing Point. ln 3D, the parallel lines meet only at infinity, so the vanishing point can be thought of as the projection of a point at infinity. If the set of lines is parallel to one of the three principal axes, the vanishing point is called an axis vanishing point. There are at most three such points, corresponding to the number of principal axes cut by the projection plane. e.g. If the projection plane cuts only the z axis (and is therefore normal to it), only the z axis has a principal vanishing point, because lines parallel to either the y or x axes are also parallel to the projection plane and have no vanishing point.
November 22, 2013 BITS WASE Computer Graphics: Course Delivered by Dr. K. Satyanarayan Reddy 56
57
58
Parallel Projections
Parallel projections are categorized into two types, depending on the relation between the direction of projection and the normal to the projection plane. In Orthographic Parallel Projections, these directions are the same (or the reverse of each other), so the direction of projection is normal to the projection plane. For the Oblique Parallel Projection, they are not.
The most common types of orthographic projections are the Front Elevation, TopElevation (also called PlanElevation), and Side Elevation projections. In all these, the projection plane is perpendicular to a principal axis, which is therefore the direction of projection. Figure on right shows the construction of these three projections.
November 22, 2013 BITS WASE Computer Graphics: Course Delivered by Dr. K. Satyanarayan Reddy 59
61
Other faces of the object project also, allowing distances along principal axes but not angles, to be measured.
62
63
64
65
The view reference-coordinate system (VRC) is a right-handed system made up of the u, v, and n axes. The n axis is always the VPN. CW is the center of the window.
November 22, 2013
The semi-infinite pyramid view volume for perspective projection. CW is the center of the window.
67
69
70
EXAMPLES OF 3D VIEWING
How the basic viewing concepts can be applied to create a variety of projections, such as those shown in Figs. 1 and 2. Because the house shown in these figures is used throughout this section, it will be helpful to remember its dimensions and position, which are indicated in Fig. 3.
71
72
Perspective Projections
To obtain the front one point perspective view of the house shown in Fig. 1, the center of projection is positioned (which can be thought of as the position of the viewer) at x = 8, y = 6. and z = 84. The x value is selected to be at the horizontal center of the house and the y value to correspond to the approximate eye level of a viewer standing on the (x, z) plane; the z value is arbitrary. In this case, z is removed 30 units from the front of the house ( z = 54 plane). The window has been made quite large, to guarantee that the house fits within the view volume. All other viewing parameters have their default values, so the overall set of viewing parameters is as follows:
73
Parallel Projections
We create a front parallel projection of the house (Fig. 1) by making the direction of projection parallel to the z axis. Recall that the direction of projection is determined by the PRP and by the center of the window. With the default VRC system and a window of (-1, 17, -1, 17), the center of the window is (8, 8, 0). A PRP of (8, 8, 100) provides a direction of projection parallel to the z axis. Figure 2 shows the viewing situation that creates Fig. 1. The viewing parameters are as follows;
For Fig. 1
Fig. 2 Viewing situation that creates Fig1, a front view of the house. The PRP could be any point with x = 8 and y = 8.
November 22, 2013 BITS WASE Computer Graphics: Course Delivered by Dr. K. Satyanarayan Reddy 74
75
76
77
78
These equations are the correct results of Eq. (6.1), plus the transformed z coordinate of d, which is the position of the projection plane along the 2 axis.
November 22, 2013 BITS WASE Computer Graphics: Course Delivered by Dr. K. Satyanarayan Reddy 79
81
The Canonical View Volumes are defined to simplify the clipping equations and to provide the consistency between Parallel and Perspective projections. On the other hand, the PHIGS default View Volumes are defined to make 2D viewing be a special case of 3D viewing.
82
Parallel Projection
Deriving the normalizing transformation Npar for parallel projections in order to transform WORLD-COORDINATE positions such that the view volume is transformed into the Canonical View Volume defined by (6.22). x = -1, x = 1, y = -1, y = 1, z = 0, z = -1. (6.22) The transformed coordinates are clipped against this canonical view volume, and the clipped results are projected onto the z = 0 plane, then are transformed into the viewport for display. Transformation Npar is derived tor the most general case, the oblique (rather than Orthographic) parallel projection. Npar includes a Shear Transformation that causes the direction of projection in viewing coordinates to be parallel to z, even though in (u, v, n) coordinates,it is not parallel to VPN. By including the shear, the projection can taken onto the z = 0 plane simply by setting z= 0. If the parallel projection is orthographic, the shear component of the normalization transformation becomes the identity.
November 22, 2013 BITS WASE Computer Graphics: Course Delivered by Dr. K. Satyanarayan Reddy 83
85
86
87
88
89
90
91
92
Perspective Projection
To develop the normalizing transformation NPER, for perspective projections. NPER transforms world coordinate positions such that the view volume becomes the perspective- projection canonical view volume, the truncated pyramid with apex at the origin defined by Eq. (6.23). After NPER is applied, clipping is done against this canonical volume and the results are projected onto the view plane using MPER The series of transformations making up NPER, is as follows: 1. Translate VRP to the origin 2. Rotate VRC such that the n axis (VPN) becomes the z axis, the u axis becomes the x axis, and the v axis becomes the y axis 3. Translate such that the Center of Projection (COP), given by the PRP, is at the origin 4. Shear such that the center line of the view volume becomes the z axis 5. Scale such that the view volume becomes the canonical perspective view volume, the truncated right pyramid defined by the six planes of (6.23).
November 22, 2013 BITS WASE Computer Graphics: Course Delivered by Dr. K. Satyanarayan Reddy 93
94
95
97
98
99
100
To calculate the intersection of a line with the y = 1 plane of the view volume, replacing the variable y of Eq. (6.43) with 1 and solve for r to find t = (1 - y0)/(y1 - y0). lf t is outside the 0 to 1 interval, the intersection is on the infinite line through points P0 and P1 but is not on the portion of the line between P0 and P1 and hence is not of interest. lf t is in (0, 1), then its value is substituted into the equations for x and z to find the intersection`s coordinates:
November 22, 2013 BITS WASE Computer Graphics: Course Delivered by Dr. K. Satyanarayan Reddy 101
102
The Liang-Barsky 2D clipping Algorithm extended to the 3D canonical perspectiveprojection view volume.
103
THANK YOU
104