Graphics 3
Graphics 3
Transformations,
Viewing &
Clipping
Introduction of
Transformations
Computer Graphics provide the facility of viewing
object from different angles. The architect can study
building from different angles i.e.
Front Evaluation
Side elevation
Top plan
A Cartographer can change the size of charts and
topographical maps. So if graphics images are coded as
numbers, the numbers can be stored in memory.
These numbers are modified by mathematical
operations called as Transformation.
The purpose of using computers for drawing is to
provide facility to user to view the object from
different angles, enlarging or reducing the scale or
shape of object called as Transformation.
Two essential aspects of transformation are given
below:
Each transformation is a single entity. It can be denoted by
a unique name or symbol.
It is possible to combine two transformations, after
connecting a single transformation is obtained, e.g., A is a
transformation for translation. The B transformation
performs scaling. The combination of two is C=AB. So C is
obtained by concatenation property.
There are two complementary points of view for
describing object transformation.
Geometric Transformation: The object itself is
transformed relative to the coordinate system or
background. The mathematical statement of this
viewpoint is defined by geometric transformations applied
to each point of the object.
Coordinate Transformation: The object is held stationary
while the coordinate system is transformed relative to the
object. This effect is attained through the application of
coordinate transformations.
Types of Transformations:
Translation
Scaling
Rotating
Reflection
Shearing
1. Translation
Similarly, after the clipping algorithms have been applied, the normalized
square with edge length equal to 2 is transformed into a specified
viewport.
The last step in the viewing process is to position the viewport area in the
display window.
Typically, the lower-left corner of the viewport is placed at a coordinate
position specified relative to the lower-left corner of the display window.
Problems
Point clipping
Curve clipping
Text clipping
I. Point clipping
For a clipping rectangle in standard position, we save 2D point P = (x, y)
for display.
The points are said to be interior to the clipping window if:
If any of these four inequalities is not satisfied, the point is clipped (not
saved for display).
The equal sign indicates that points on the window boundary are included
within the window.
II. Line Clipping
But if both these tests fail, the line segment intersects at least one
clipping boundary and it may or may not cross into the interior of the
clipping window.
One way to formulate the equation for a straight-line segment is to use
the following parametric representation, where the coordinate positions
(x0, y0) and (xend, yend) designate the two line endpoints:
x = x0 + u(xend − x0)
y = y0 + u(yend − y0) 0≤u≤1
We can use this parametric representation to determine where a line
segment crosses each clipping-window edge by assigning the coordinate
value for that edge to either x or y and solving for parameter u.
However, if the value of u is within the range from 0 to 1, part of the line
is inside that border.
We can then process this inside portion of the line segment against the
other clipping boundaries until either we have clipped the entire line or
we find a section that is inside the window.
Processing line segments in a scene using the simple clipping approach
described in the preceding paragraph is straightforward, but not very
efficient.
II. Line Clipping: Cohen-
Sutherland
This is one of the earliest algorithms to be developed
for fast line clipping, and variations of this method are
widely used.
Processing time is reduced in the Cohen-Sutherland
method by performing more tests before proceeding to
the intersection calculations.
Initially, every line endpoint in a picture is assigned a
four-digit binary value, called a region code, and each
bit position is used to indicate whether the point is
inside or outside one of the clipping-window
boundaries.
For this ordering, the rightmost position (bit
1) references the left clipping-window
boundary, and the leftmost position (bit 4)
references the top window boundary.
Right
Bottom
Top
Any line that is parallel to one of the clipping-window edges has pk = 0 for
the value of k corresponding to that boundary, where k = 1, 2, 3, and 4
correspond to the left, right, bottom, and top boundaries, respectively.
Liang-Barsky Line Clipping
Algorithm
Advantages:
Thus, we can clip a polygon fill area by determining the new shape for the
polygon as each clipping-window edge is processed.
The interior fill for the polygon would not be applied until the final
clipped border has been determined.
We first tested a line segment to determine whether it could be
completely saved or completely clipped, that will be the same with a
polygon fill area by checking its coordinate extents.
If the minimum and maximum coordinate values for the fill area are inside
all four clipping boundaries, the fill area is saved for further processing.
2. If both input vertices are inside this clipping-window border, only the
second vertex is sent to the next clipper.
3. If the first vertex is inside this clipping-window border and the second
vertex is outside, only the polygon edge-intersection position with the
clipping-window border is sent to the next clipper.
Process the edges of the polygon fill area in a counterclockwise order until
an inside-outside pair of vertices is encountered for one of the clipping
boundaries; that is, the first vertex of the polygon edge is inside the clip
region and the second vertex is outside the clip region.
Form the vertex list for this section of the clipped fill area.
The edge defined by points 2 and 3 crosses to the outside of the left
boundary, but points 2 and 2’ are above the top clipping-window border
and point 2’ and 3 are to the left of the clipping region.
Also, the edge with endpoints 3 and 4 is outside the left clipping boundary,
but the next edge (from endpoint 4 to endpoint 5) re-enters the clipping
region and we pick up intersection point 4’.
The edge with endpoints 5 and 6 exits the window at intersection position
5’, so we detour the left clipping boundary to obtain the closed vertex list
{4’, 5, 5’}.
At this point, all polygon vertices and edges have been processed, so the fill
area is completely clipped.
IV. Curve Clipping
We can first test the coordinate extents of an
object against the clipping boundaries to
determine whether it is possible to accept or
reject the entire object trivially.
If not, we could check for object symmetries
that we might be able to exploit in the initial
accept/reject tests.
For example, circles have symmetries
between quadrants and octants.
An intersection calculation involves substituting a
On the first pass, we could compare the bounding rectangle of the object
with the bounding rectangle of the clipping region.
If this does not save or eliminate the entire object, we next solve the
simultaneous line-curve equations to determine the clipping intersection
points.
V. Text Clipping
Outline character fonts defined with line segments are processed in this
way using a polygon-clipping algorithm.
Characters defined with bit maps are clipped by comparing the relative
position of the individual pixels in the character grid patterns to the
borders of the clipping region.