CG 3
CG 3
CG 3
Translation
To reposition an object from one coordinate position to anoth er is known as
Translation. We translate a two-dimensional point by adding Translation
Vector (Distance) to the original coordinate position. The translation vector
(t x, ty) is the distance by which the x-coordinate and the y-coordinate are to be
translated.
If (x, y) is the original coordinate position, we add translation vector (t x, ty) to
move the point to a new position (x', y').
x' = x + tx y' = y + ty
We can express the above translation equations as a single matrix equation by
using column to represent coordinate positions and the translation vectors.
P = x P' = x' T = tx
y y' ty
So, the two-dimensional translation equation in matrix form can be written as:
P' = P + T
Translation is a rigid body transformation that moves objects without changing
the shape. Every point on the body is translated
by the same amount.
A straight line is translated by applying the
transformation equation to each end point and
redrawing the line again at the new endpoint
coordinate position. Similarly, a polygon can be
translated by adding the translation vector to
each vertex (end point) and regenerating the
polygon at the new set of vertex position. In case
of curved objects, such as circle, we translate the
centre coordinates and redraw the object at new
position.
Rotation
To reposition an object along a circular path in xy plane is known as Rotation.
To generate a rotation, we need a Rotation Angle and the position of the
Rotation Point. Rotation Point (x r, yr) is the point about which the object has to
be rotated and Rotation Angle θ is the angle by which the object has to be
rotated about the rotation point. Positive values of rotation angle rotate the
object in counter clockwise direction about the rotation point and negative value s
rotate the abject in clockwise direction.
We first determine the transformation equations for rotation of a point P when
the rotation point (x r, y r ) is at the origin.
Compiled By: Navtej Bhatt V.P. & R.P.T.P. Science College 1|P age
Computer Graphics Unit - 3
Scaling
To change the size of an object is known as Scaling. Scaling can be performed
by multiplying coordinate value (x, y) of each vertex by Scaling Factor (S x, S y )
to produce transformed coordinate (x', y'). Scaling Factor S x scales objects in the
x direction and Sy in y direction.
x' = x.S x
y' = y.S y
Compiled By: Navtej Bhatt V.P. & R.P.T.P. Science College 2|P age
Computer Graphics Unit - 3
Or, P' = S. P
Numbers more than 1 for scaling factors increase the
size of the object whereas values less than 1 reduce
the size of object. Specifying value of 1 for both S x and
Sy leaves the size of object unchanged. When S x and Sy
are same value, then it is Uniform Scaling and unequal values of Sx and Sy
results in Differential Scaling.
Reflection
A Reflection is a transformation that produces a mirror image of an object. The
mirror image for a two-dimensional reflection is generated relative to an Axis of
Reflection by rotating the object 180 about the reflection axis.
We can choose an axis of reflection in the xy plane or perpendicular to the xy plane.
When the reflection axis is a line in the xy plane, the rotation path about this axis
is in a plane perpendicular to the xy plane. For reflection axes that are perpendicular
to the xy plane, the rotation path is in the xy plane. Following are examples of some
common reflections.
(b)
Reflected
x
x
Reflection of an object (a)about the y-axis(b)about the axis of reflection y=x
Compiled By: Navtej Bhatt V.P. & R.P.T.P. Science College 3|P age
Computer Graphics Unit - 3
Shear
A transformation that changes the shape of an object such that the transformed
shape appears as if the object was made of layers that had been caused to slide
over each other, is called a Shear. Two common shearing transformations are
those that shift coordinate x value and those that shift y values.
y y y y
x x x x
(a) (b)
An object after (a ) x -direction shear and (b) y -direction shear
Viewing Pipeline
Some graphics packages that provide window and viewport operations allow only
standard rectangles, but a more general approach is to allow the rectangular
window to have any orientation. In this case, we carry out the viewing
transformation in several steps, as indicated in following figure.
First, we construct the scene in world coordinates using the output primitives and
attributes. Next, to obtain a particular orientation for the window, we can set up
a two-dimensional viewing-coordinate system in the world-coordinate plane, and
define a window in the viewing-coordinate system. The viewing coordinate
reference frame is used to provide a method for setting up arbitrary orientations
for rectangular windows. Once the viewing reference frame is established, we can
transform descriptions in world coordinates to viewing coordinates. We then
define a viewport in normalized coordinates (in the range from O to 1) and map
the viewing-coordinate description of the scene to normalized coordinat es. At the
final step, all parts of the picture that he outside the viewport are clipped, and
the contents of the viewport are transferred to device coordinates. Following
Figure illustrates a rotated viewing-coordinate reference frame and the mapping
to normalized coordinates.
Compiled By: Navtej Bhatt V.P. & R.P.T.P. Science College 4|P age
Computer Graphics Unit - 3
Window
A rectangular box to view only a part of a real-world object we to draw on the
screen, is called a Window.
In other words, a world-coordinate area selected for display on a display device is
called a Window.
Window to
Real-World view only
Object Window
part of an
object
Viewport
A rectangular region of screen selected for displaying an object or part of an
object, which has been specified in a window, is called a Viewport.
In other words, an area on a display device to which a window is mapped is called
a Viewport.
Viewport
Display
Screen Viewport to
define the
part of the
screen to be
Compiled By: Navtej Bhatt V.P. & R.P.T.P. Science College 5|P age
Computer Graphics Unit - 3
Viewport
yv max
Window
yw max (xv, yv)
yv min
(xw, yw)
yw min
Compiled By: Navtej Bhatt V.P. & R.P.T.P. Science College 6|P age
Computer Graphics Unit - 3
Solving these expressions for the viewport position (xv, yv), we have
xw max – xw min
Sy = yv max – yv min
yw max – yw min
If the scaling factors, S x and Sy are same, relative proportions are maintained.
Otherwise, world objects will be stretched or contracted in either x or y direction,
that is, its shape will be distorted, when displayed on the output device.
Clipping
Generally, any procedure that identifies those portions of a picture that are either
inside or outside of a specified region of space is referred to as a clipping
algorithm, or simply clipping. The region against which an object is to clip is
called a clip window.
Applications of clipping
Extracting part of a defined scene for viewing
Identifying visible surfaces in three-dimensional views
Antialiasing line segments or object boundaries
Creating objects using solid-modeling procedures
Displaying a multiwindow environment
Drawing and painting operations that allow parts of a picture to be selected
for copying, moving, erasing, or duplicating.
Point Clipping
Assuming that the clip window is a rectangle in standard position, we save a
point P = (x, y) for display if the following inequalities are satisfied:
Where the edges of the clip window (XW min ,XW max ,YW min ,YW max ) can be either the
world-coordinate window boundaries or viewport boundaries. If any one of these
four inequalities is not satisfied, the point is clipped (not saved for display).
Although point clipping is applied less often than line or polygon clipping, some
applications may require a point clipping procedure. For example, point clipping
can be applied to scenes involving explosions or sea foam t hat is modeled with
particles (points) distributed in some region of the scene.
Compiled By: Navtej Bhatt V.P. & R.P.T.P. Science College 7|P age
Computer Graphics Unit - 3
Line Clipping
A line clipping procedure involves several parts. First, we can test a given line
segment to determine whether it lies completely inside the clipping window. If it
does not, we try to determine whether it lies completely outside the window.
Finally, if we cannot identify a line as completely inside or completely outside, we
must perform intersection calculations with one or more clipping boundaries. We
process lines through the "inside-outside'' tests by checking the line endpoints.
A line with both endpoints inside all clipping boundaries, such as the line from P 1
to P2 is saved. A line with both endpoints outside any one of the clip boundaries
(line P 3P4 in Figure) is outside the window. All other lines cross one or more
clipping boundaries, and may require calculation of multiple intersection points.
To minimize calculations, we try to devise clipping algorithms that can efficiently
identify outside lines and reduce intersection calculations.
For a line segment with endpoints (x 1, y1) and (x 2, y2) and one or both
endpoints outside the clipping rectangle, the parametric representation
x = x1 + u(x 2 -x 1 )
y = y1 + u(y 2-y1), 0≤u≤1
Compiled By: Navtej Bhatt V.P. & R.P.T.P. Science College 8|P age
Computer Graphics Unit - 3
Each bit position in the region code is used to indicate one of the four relative
coordinate positions of the point with respect to the clip window: to the left,
right, top, or bottom. By numbering the bit positions in the region code as 1
through 4 from right to left, the coordinate regions can be correlated with the bit
positions as
bit 1: left
bit 2: right
bit 3: below
bit 4: above
A value of 1 in any bit position indicates that the point is in that relative position;
otherwise, the bit position is set to 0. If a point is within the clipping rectangle,
the region code is 0000. A point that is below and to the left of the rectangle has
a region code of 0101.
Bit values in the region code are determined by comparing endpoint coordinate
values (x, y) to the clip boundaries. Bit 1 is set to 1 if x < XW min . The other three
bit values can be determined using similar comparisons. For languages in which
bit manipulation is possible, region-code bit values can be determined with the
following two steps: (1) Calculate differences between endpoint coordinates and
clipping boundaries. (2) Use the resulta nt sign bit of each difference calculation
to set the corresponding value in the region code. Bit 1 is the sign bit of X-XW min
bit 2 is the sign bit of XW max -X; bit 3 is the sign bit of Y-YW min ; and bit 4 is the
sign bit of YW max -Y.
Once we have established region codes for all line endpoints, we can quickly
determine which lines are completely inside the clip window and which are clearly
outside. Any lines that are completely contained within the window boundaries
have a region code of 0000 for both endpoints, and we trivially accept these
lines.
Compiled By: Navtej Bhatt V.P. & R.P.T.P. Science College 9|P age
US05CBCA02 – Computer Graphics Unit - 3
Any lines that have a 1 in the same bit position in the region codes for each
endpoint are completely outside the clipping rectangle, and we trivially re ject
these lines. We would discard the line that has a region code of 1001 for one
endpoint and a code of 0101 for the other endpoint. Both endpoints of this line
are left of the clipping rectangle, as indicated by the 1 in the first bit position of
each region code. A method that can be used to test lines for to tal clipping is to
perform the logical and operation with both region codes. If the result is not
0000, the line is completely outside the clipping region.
Polygon Clipping
A polygon boundary processed with a line clipper may be displayed as a series of
unconnected line segments, depending on the orientation of the polygon to the
clipping window. What we really want to display is a bounded area after clipping,
as in Figure. For polygon clipping, we require an algorithm that will generate one
or more closed areas that are then scan converted for the appropriate area fill.
The output of a polygon clipper should be a sequence of vertices that defines the
clipped polygon boundaries.
10 | P a g e
US05CBCA02 – Computer Graphics Unit - 3
We illustrate this method by processing the area in figure against the left window boundary.
Vertices I and 2 are found to be on the outside of the boundary. Moving along to vertex 3,
which is inside, we calculate the intersection and save both the intersection point and vertex
3. Vertices 4 and 5 are determined to by inside, arid they also are saved. The sixth and final
vertex is outside, so we find and save the intersection point. Using the five saved points, we
would repeat the process for the next window boundary.
Text Clipping
There are several techniques that can be used to provide text clipping in a
graphics package. The clipping technique used will depend on the methods used
to generate characters and the requirements of a particular application. The
simplest method for processing character strings relative to a window boundary is
to use the all-or-none string-clipping strategy shown in Figure. If all of the string
is inside a clip window, we keep it. Otherwise, the string is discarded. This
procedure is implemented by considering a bounding rectangle around the text
pattern. The boundary positions of the rectangle are then compared to the
window boundaries, and the string is rejected if there is any overlap. This method
produces the fastest text clipping. An alternative to rejecting an entire character
string that overlaps a window boundary is to use the all-or-none character-
clipping strategy. Here we discard only those characters that are not completely
inside the window.
11 | P a g e
US05CBCA02 – Computer Graphics Unit - 3
In this case, the boundary limits of individual characters are compared to the window.
Any character that either overlaps or is outside a window boundar y is clipped. A final
method for handling text clipping is to clip the components of individual characters.
We now treat characters in much the same way that we treated lines. If an
individual character overlaps a clip window boundary, we clip off the parts of the
character that are outside the window. Outline character fonts formed with line
segments can be processed in this way using a line clipping algorithm. Characters
defined with bit maps would be clipped by comparing the relative position of the
individual pixels in the character grid patterns to the clipping boundaries.
12 | P a g e