Anda di halaman 1dari 51

COMPUTER GRAPHICS

DRAWING 2D PRIMITIVES
Institute of Information and Communication Technology
University of Sindh, Jamshoro

Dr. Zeeshan Bhatti

BSIT-PIV
Chapter 2
BY: DR. ZEESHAN BHATTI

CHAPTER CONTENTS
Interactive Graphic Systems
Drawing lines
Drawing circles
Filling polygons

INTERACTIVE GRAPHIC SYSTEM

INTERACTIVE GRAPHIC SYSTEM


Application Model
Represents data and objects to be displayed on the output
device

Application Program
Creates, stores into, and retrieves from the application model
Handles user-inputs
Sends output commands to the graphics system:
Which geometric object to view (point, line, circle, polygon)
How to view it (color, line-style, thickness, texture)

GRAPHICS SYSTEM
Intermediates between the application program and the
interface hardware:
Output flow
Input flow

Causes the application program to be device


independent.

DISPLAY HARDWARE
CRT - CATHODE RAY TUBE

RASTER SCAN (CRT)

DISPLAY HARDWARE
FED - FIELD EMISSION DISPLAY

IMAGE REPRESENTATION IN RASTER


DISPLAYS

RASTER DISPLAY

TERMINOLOGY
Pixel: Picture element.
Smallest accessible element in picture
Assume rectangular or circular shape

Aspect Ratio: Ratio between physical dimensions of a pixel (not necessarily


1)
Dynamic Range: The ratio between the minimal (not zero!) and the
maximal light intensity a display pixel can emit

Resolution: The number of distinguishable rows and columns in the device.


Measured in:
Absolute values (1K x 1K) or,
Density values (300 dpi [=dots per inch])

Screen Space: A discrete Cartesian coordinate system of the screen pixels


Object Space: The Cartesian coordinate system of the universe, in which the
objects (to be displayed) are embedded

SCAN CONVERSION
The conversion from a geometrical representation of an
object to pixels in a raster display . OR
The process of representing continuous graphical objects
as a collection of discrete pixels by identifying their
locations and setting them ON is called scan conversion.

REPRESENTATIONS

LINE IN 2 DIMENSIONS

SCAN CONVERSION
Generally Four types:
1.

Polynomial method

2.

DDA (Digital Difference Analyzer) method

3.

Bresenhams method

4.

Midpoint method

SCAN CONVERSION
Most of the standard type of graphical pbjects like lines, circles, etc.,
are defined by a mathematical function.

For example, a straight line segment is defined by the following


equation:
Where m is the slope of the line and b is the y-intercept on the
positive Y-axis.
Similar are the cases with circles, ellipses, parabolas, etc.

SCAN CONVERSION
POLYNOMIAL METHOD FOR LINES

SCAN CONVERSION - LINES


Incremental Algorithm

SCAN CONVERSION - LINES

PSEUDO CODE FOR BASIC LINE


DRAWING
Assume x1>x0 and line slope absolute value is 1

BASIC LINE DRAWING

MIDPOINT (BRESENHAM) LINE


DRAWING

MIDPOINT (BRESENHAM) LINE


DRAWING

MIDPOINT (BRESENHAM) LINE


DRAWING

MIDPOINT (BRESENHAM) LINE


DRAWING

MIDPOINT (BRESENHAM) LINE


DRAWING

PSEUDO CODE FOR MIDPOINT LINE


DRAWING

SCAN CONVERSION - CIRCLES

SCAN CONVERSION - CIRCLES

SCAN CONVERSION - CIRCLES

SCAN CONVERSION - CIRCLES

CIRCLE MIDPOINT (FOR ONE OCTANT)

CIRCLE MIDPOINT (FOR ONE OCTANT)


Threshold Criteria:

CIRCLE MIDPOINT (FOR ONE OCTANT)

PSEUDO CODE FOR CIRCLE MIDPOINT

PSEUDO CODE FOR CIRCLE MIDPOINT

PSEUDO CODE FOR CIRCLE MIDPOINT

CIRCLE MIDPOINT

POLYGON FILL

SCAN CONVERSION - POLYGON FILL

FLOOD FILL ALGORITHM

FLOOD FILL ALGORITHM

FILL POLYGON

SCAN CONVERSION BASIC


ALGORITHM

SCAN CONVERSION FILL


POLYGON

SCAN CONVERSION FILL


POLYGON

FILL POLYGON OPTIMIZED


ALGORITHM

FILL POLYGON OPTIMIZED


ALGORITHM

FLOOD FILL VS. SCAN CONVERSION

THANKYOU

Q&A
Referred Book
Computer Graphics: Principles and Practice in C,
by J. D. Foley, A. Van Dam, S. K. Feiner, J. F. Hughes.
Hardcover, 1200 pages, Addison-Wesley Pub Co; 2nd edition,

For Course Slides and Handouts


web page:

https://sites.google.com/site/drzeeshanacademy/
Blog:

http://zeeshanacademy.blogspot.com/
Facebook:

https://www.facebook.com/drzeeshanacademy

BY: DR. ZEESHAN BHATTI

52

Anda mungkin juga menyukai