CG-UNIT-II
CG-UNIT-II
Computer Graphics
UNIT-II
UNIT- 2 Contents
Output Primitives
1. Points and Lines
Introduction:
A picture can be described in several ways. a picture is completely specified by the set of
intensities for the pixel positions in the display. At the other extreme, we can describe a picture
as a set of complex objects, such as trees and terrain or furniture and walls, positioned at
specified coordinate locations within the scene.
Shapes and colors of the objects can be described internally with pixel arrays or with sets of
basic geometric structures, such as straight line segments and polygon color areas.
Points and straight line segments are the simplest geometric components of pictures. Additional
output primitives that can be used to construct a picture include circles and other conic sections.
Points:
With a CRT monitor, for example, the electron beam is turned on to illuminate the
screen phosphor at the selected location. How the electron beam is positioned depends
on the display technology.
A random-scan (vector) system stores point-plotting instructions in the display list, and
coordinate values in these instructions are converted to deflection voltages that position
the electron beam at the screen locations to be plotted during each refresh cycle.
For a black and-white raster system, on the other hand, a point is plotted by setting the
bit value corresponding to a specified screen position within the frame buffer to 1.
Department of CSE
Subject: Computer Graphics III-II CSE –A1
With an RGB system, the frame buffer is loaded with the color Points and lines codes
for the intensities that are to be displayed at the screen pixel positions.
Lines:
In computer graphics, a line is a mark that connects two points, or a mark that extends from a
single point. Lines are a fundamental element of visual art and are used to create structure and
movement in designs.
Line drawing is accomplished by calculating intermediate positions along the line path between
two specified endpoint positions. An output device is then directed to fill in these positions
between the endpoints.
Digital devices display a straight line segment by plotting discrete points between the two
endpoints. Discrete coordinate positions along the line path are calculated from the equation of
the line.
For a raster video display, the line color (intensity) is then loaded into the frame buffer at the
corresponding pixel coordinates.
A computed line position of (10.48, 20.51), for example, would be converted to pixel position
(10,21). Tlus rounding of coordinate values to integers causes lines to be displayed with a
stairstep appearance ("the jaggies"), as represented in Fig 3-1.
To load a specified color into the frame buffer at a position corresponding to column x along
scan line y, we will assume we have available a low-level procedure of the form.
For the raster-graphics device-level algorithms discussed in this chapter, object positions are
specified directly in integer device coordinates. For the time being, we will assume that pixel
positions are referenced according to scan-line number and column number (pixel position
across a scan line). This addressing scheme is illustrated in Fig. 3-2.
Scan lines are numbered consecutively from 0, starting at the bottom of the screen; and pixel
columns are numbered from 0, left to right across each scan line.
Department of CSE
Subject: Computer Graphics III-II CSE –A1
We sometimes will also want to be able to retrieve the current frame-buffer intensity setting
for a specified location. We accomplish this with the low-level function.
With m representing the slope of the line and b as they intercept. Given that the two endpoints
of a h e segment are specified at positions (x1, y1,) and (x2, y2), as shown in Fig. 3-3, we can
determine values for the slope m and y intercept b with the following calculations
Algorithms for displaying straight lines are based on the line equation 3-1 and the calculations
given in Eqs. 3-2 and 3-3.
For any given x interval ∆x along a line, we can compute the corresponding ∆y interval from
equation 3-2 as
These equations form the basis for determining deflection voltages in analog devices.
Raster Systems: On raster systems, lines are plotted with pixels, and step sizes in the
horizontal and vertical directions are constrained by pixel separations. That is, we must
Department of CSE
Subject: Computer Graphics III-II CSE –A1
"sample" a line at discrete positions and determine the nearest pixel to the / line at each sampled
position.
This scan conversion process for straight lines is illustrated, lustrated in Fig. 3-4, for a near
horizontal line with discrete sample positions along the x axis.
DDA Algorithm:
The digital differential analyser (DDA) is a scan-conversion line algorithm based on
calculating either ∆y or ∆x, using Eq. 3-4 or Eq. 3-5. We sample the line at unit in Straight line
segment with intervals in one coordinate and determine corresponding integer values nearest
the five sampling positions along line path for the other coordinate.
2. Determine the number of steps needed, based on the greater absolute difference
between Δx and Δy Steps=max(∣Δx∣,∣Δy∣)
4. Starting at (x1,y1) iterate through each step and compute the next point by adding the
increments. X= X+ Xincrement ; Y = Y + Yincrement
Department of CSE
Subject: Computer Graphics III-II CSE –A1
This algorithm is summarized in the following procedure, which accepts as input the two end
point. pixel positions. Horizontal and vertical differences between the endpoint positions are
assigned to parameters dx and dy. The difference with the greater magnitude determines the
value of parameter steps. Starting with pixel position (xa, ya), we determine the offset needed
at each step to generate the next pixel position along the line path. We loop through this process
steps times.
# Calculate increments
x_increment = dx / steps
y_increment = dy / steps
# Example usage
dda_line(2, 3, 10, 8)
Output:
The output will list the points that form the line:Points on the line:
(2, 3)
(3, 3)
(4, 4)
(5, 4)
(6, 5)
(7, 5)
(8, 6)
(9, 7)
(10, 8)
1. Δx=x2−x1, Δy =y2−y1
=8 =5
2. Steps=max(∣Δx∣,∣Δy∣)
Steps = max(8,5) = 8
3. Xincrement=Δx / Steps, Yincrement=Δy/Steps
= 8/8 =1 = 5/8 = 0.62
4. for first iteration X = 2+1 Y= 3+0.62
For second iteration X= 3+1 Y= 4.02 + 0.62
…..
After 8 iterations X=10 , Y=8.62
Students can also refer the following link for additional information:
https://www.youtube.com/watch?v=EWOlUxvVtNg
Department of CSE
Subject: Computer Graphics III-II CSE –A1
The decision parameters required to calculate the discrete points on the line to draw are
computed as follows
Department of CSE
Subject: Computer Graphics III-II CSE –A1
Department of CSE
Subject: Computer Graphics III-II CSE –A1
2.3
Reference: https://www.youtube.com/watch?v=h3gDB89h0os
Department of CSE
Subject: Computer Graphics III-II CSE –A1
CIRCLE-GENERATING ALGORITHM
Properties of Circles A circle is defined as the set of points that are all at a given distance r
from a center position (x,, y,) (Fig. 3-12). This distance relationship is expressed by the
Pythagorean theorem in Cartesian coordinates as
Computation can be reduced by considering the symmetry of circles. The shape of the circle is
similar in each quadrant. Circle sections in adjacent octants within one quadrant are symmetric
with respect to the 45o line dividing the two octants. These symmetry conditions are illustrated
in Fig.3-14, where a point at position (x, y) on a one-eighth circle sector is mapped into the
seven circle points in the other octants of the xy plane.
Department of CSE
Subject: Computer Graphics III-II CSE –A1
Department of CSE
Subject: Computer Graphics III-II CSE –A1
Department of CSE
Subject: Computer Graphics III-II CSE –A1
Department of CSE
Subject: Computer Graphics III-II CSE –A1
Students can also refer for additional problem the following link:
https://www.youtube.com/watch?v=LduamxjhD6E
Department of CSE
Subject: Computer Graphics III-II CSE –A1
An ellipse is defined as the set of points such that the sum of the distances from two fixed
positions (foci) is the same for all points (Fig. 3-17). If the distances to the two foci from any
point P = (x, y) on the ellipse are labeled d1 and d2, then the general equation of an ellipse can
be stated as
d1 + d2 = constant
Department of CSE
Subject: Computer Graphics III-II CSE –A1
we select the next pixel along the ellipse according to the sign of the ellipse function evaluated
at the midpoint between the two candidate pixels.
Starting at (0, r,), we take unit steps in the x direction until we reach the boundary between
region 1 and region 2-(Fig. 3-20).
Department of CSE
Subject: Computer Graphics III-II CSE –A1
Department of CSE
Subject: Computer Graphics III-II CSE –A1
Department of CSE
Subject: Computer Graphics III-II CSE –A1
Department of CSE
Subject: Computer Graphics III-II CSE –A1
Department of CSE
Subject: Computer Graphics III-II CSE –A1
Students can also refer the following link for additional example
https://www.youtube.com/watch?v=KbDN4WOZ3f8
Department of CSE