Cad Unit I

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 64

COMPUTER AIDED DESIGN

OVERVIEW OF SUBJECT

UNIT 1: Introduction of CAD, Difference between Conventional & CAD design,


Rasterization techniques frame buffer, N-bit plane buffers, Simple color frame buffer
algorithm for the generation of basic geometric entities like line, circle & ellipse by using
parametric & non-parametric equations.

UNIT 2: Introduction to windowing & clipping (excluding algorithm), Window and


Viewport, line clipping & polygon clipping
2D transformation: Translation, Scaling, Rotation, Reflection & Shear, Concept of
homogeneous representation & concatenation, Inverse Transformation (enumeration of
entity on graph paper)
3D Transformation ; Translation, Scaling, Rotation, Reflection etc.

UNIT 3: Techniques for Geometric Modeling: Graphic standards, parametric


representation of geometry, Bezier curves, Cubic spline curves, B-Spline curves,
constructive solid geometry, Feature Based modeling, Feature recognition, Design
by feature, Wire frame modeling, solid modeling of basic entities like box, cone,
cylinder. CSG & B- representation technique using set theory.
Assembly modeling: Representation, mating conditions, representation schemes,
generation of assembly sequences and importance of precedence diagram. 1
UNIT 4: Finite Element Analysis: One Dimensional Problem: Fundamental concept of
finite element method, Plain stress and strain, Finite Element Modeling, Potential Energy
Approach, Galerkin’s Approach, Coordinate and Shape function, Assembly of Global
Stiffness Matrix and Load Vector, Properties of Stiffness Matrix, Finite Element
Equations, Quadratic Shape Function, Temperature Effects, Torsion of a circular
shaft.

UNIT 5: Truss & Two Dimensional FEM:


Plane truss problems, two dimensional problems using Constant strain triangle. Derivation
of shape functions for CST element. Formulation of stiffness matrices for Truss and CST
element. Preprocessing and Post processing.

UNIT 6: Optimization in Design:


Objectives of optimum design, adequate and optimum design, Johnson’s Method of
optimum design, primary design equation, subsidiary design equations and limit
equations, optimum design with normal and redundant specifications of simple
machine elements like: tension bar, transmission shaft and helical spring.

2
INTRODUCTION TO COMPUTER AIDED
DESIGN AND DISPLAY DEVICES

HEMANT M. BANSOD
Assistant Professor, Mechanical Engineering
S. B. Jain Institute of Technology, Management
& Research, Nagpur

3
1. Introduction to Finite Element
Method for engineers –
Chadrupatla and Belegunde

2. Finite Element Analysis –Theory


Bhavikutti

4
UNIT-I
INTRODUCTION TO CAD, CONVENTIONAL
PROCESS,RASTERIZATION TECHNIQUES,
FRAME BUFFER.

DDA ALGORITHM FOR LINE GENERATION.

BRESENHUM’s ALGORITHM FOR LINE,


CIRCLE, ELLIPSE GENERATION.

5
Computer Aided Design (CAD):-
Computer Aided Design is defined as any design
activity that involves the effective use of the
computer to create, modify, analyze or document
an engineering design.

CAD is mostly associated with the use of an


interactive computer graphics system, referred to
as a CAD system. The term CAD/CAM system is
also used if it supports manufacturing as well as
design applications.

6
General Design process:-
The general process of design is characterized by “Mechanical Engineering
Design by Shigley” as an iterative process consisting of six phases:

RECOGNITION OF NEED

PROBLEM IDENTIFICATION

SYNTHESIS

ANALYSIS AND OPTIMIZATION

EVALUATION

PRESENTATION

7
Design Process using CAD:-
With reference to the six phases of design, a CAD can beneficially be used in
four of design phases, as indicated in table and illustrated in figure as an
overlay on the design process of Mechanical Engineering Design by Shigley.
RECOGNITION OF
NEED
CONVENTIONAL PROCESS

PROBLEM
IDENTIFICATION CAD PROCESS

SYNTHESIS
GEOMETRIC MODELING

ANALYSIS AND
OPTIMIZATION ENGINEERING ANALYSIS

EVALUATION DESIGN REVIEW & EVALUATION

PRESENTATION
AUTOMATED DRAFTING
8
1. Geometric modeling:-
Geometric modeling involves the use of a CAD system to develop
a mathematical description of the geometry of an object.

Wire frame model Solid Model

2. Engineering Analysis:-
The analysis may take the form of stress-strain calculations,
heat transfer analysis, or dynamic simulation. The availability of
software for engineering analysis on a CAD system greatly increases
the designer’s ability and willingness to perform a more types of
analysis. CAD systems include
i) Mass properties analysis
ii) Finite element analysis
iii) Kinematic and dynamic analysis
9
iv) Discrete-event simulation
3. Design Evaluation and Review:-
CAD features that are helpful in evaluating and reviewing a
proposed design include:
i) Automated Dimensioning
ii) Error Checking
iii) Animation of discrete event
iv) Automated Drafting
Benefits of CAD:-
1) Increased Productivity
2) Reduction in time, necessary for the development of conceptual
designing, analysis and documentation.
3) Integration between designing, analysis to manufacturer through
provision of a common data base.
4) Design errors can be eliminated at the early stages of design.
5) Improves documentation and standardization of engineering design.
6) Eliminates tedious task of performing long mathematical
calculations.
7) Provides opportunity for more alternative designs to be produced
before final production. 10
Input Devices:-
The input devices are mainly classified in two classes based
on possible ways of inputting (feeding) the information ,
1. Text input devices:-
Keyboard
Keyboards are used as entering text strings. It is efficient devices for
inputting such a non graphics data as picture label.

2. Graphic input devices:-


a) Locator like mouse:-
Mouse is small size hand-held box used to position screen cursor.

b) Digitizer:-
Digitizer is common device for drawing painting or interactively
selecting coordinates position on an object.

c) Scanner- Image input device:-


Image Scanner scan drawing, graph, color, & black and white photos
or text and can stored for computer processing by passing an optical scanning
mechanism over the information to be stored.
11
Output Devices:-
CRT (cathode ray tube) is the most commonly and has
produced a wide range of extremely effective graphics display other technologies,
utilize laser, flat panel display or plasma panel display

(CRT) Cathode Ray Tube:-

Reference:- National Program on Technology Enhancement Learning


(www.nptel.ac.in) 12
The graphical display can be divided into two types based
on the scan technologies used to control the electron beam when
generating graphics on the screen.
1. In random scan (also referred to as the stroke writing , vector
writing or calligraphy scan), graphics can be generated by
drawing vectors or line segments on the screen in the random
order which is controlled by the user input and the software.
The world RANDOM indicates the screen is not scanned in a
particular order.

13
2. In the Raster scan system, the screen is scanned from left to
right, top to bottom, all the time to generate graphics. This is
similar to the home television scan system, the suggesting the
name “Digital scan”.

14
In raster display, the display screen area is divided horizontally and vertically
into the matrix of small elements called picture element or pixels.
A pixel is the smallest addressable area on the screen.
An N×M resolution defines a screen with N rows and M columns. Each row
defines a scan line.
A rasterization process is needed in order to display either a shaded area or
graphics entities.
In the process, the area or entities are converted into their corresponding
pixels whose intensity and color are controlled by the image display systems.

Pixel

X 15
Difference Between Raster and Random Scan System
Base of Difference Raster Scan System Random Scan System
Electron Beam The electron beam is swept across the
The electron beam is directed only to the parts
screen, one row at a time, from top to
of screen w here a picture is to be drawn.
bottom.
Resolution Its resolution is poor because raster system
Its resolution is good because this system
in contrast produces zigzag lines that are
produces smooth lines drawings because
plotted as discrete point sets.
CRT beam directly follows the line path.
Picture Definition Picture definition is stored as a set of Picture definition is stored as a set of line
intensity values for all screen points, called drawing instructions in a display file.
pixels in a refresh buffer area.
The capability of this system to store
These systems are designed for line-
intensity values for pixel makes it well
Realistic Display drawing and can’t display realistic shaded
suited for the realistic display of scenes
scenes.
contain shadow and color pattern.
Screen points/pixels are used to draw an Mathematical functions are used to draw an
Draw an Image
image. image.

16
Display Devices:-
The three existing CRT display that are based on
the random and raster scan technique of scan are as follows,

1. Refresh (calligraphic) display or direct beam refresh tube


(DBRT)

17
2. Direct view storage tube (DVST):-

18
3. Raster display

19
Frame Buffer :-
In raster scan displays a special area of memory is
dedicated to graphics only. This memory is called.
Frame buffer holds set of intensity values for all the
screen points.
That intensity is retrieved from frame buffer and
display on screen one row at a time.
On a black and white system with one bit per pixel
the frame buffer is commonly called a Bitmap.

20
LINE GENERATION ALGORITHM :-
There are two types of algorithm used for line generation
1. Digital Differential analyzer (DDA)
2. Bresenhem Algorithm
In both these algorithms certain common features are incorporated.
When two end points are known, slope of the line is

m=Δy/Δx
Therefore, Δy = mΔx --- 1

In equation 1, if any two terms are known, third can be calculated.


It is possible to set change in X-coordinate or Y-coordinate i.e., Δ x or Δ y to be
unity and then calculating the change in other co-ordinate and hence co-ordinate of
succeeding point.
1. If slope of line is ≤ 1 then, change in X-coordinate i.e., Δ x is more than Δ y.
It is desired to keep Δ x to be unity so that more no. of pixels on the path of
the line can be found out.
2. If slope of line is ≥ 1then, set Δ y to be unity so that more no. of pixels on the
path of the line can be found out.

21
1. DIGITAL DIFFERENTIAL ANALYZER (DDA) LINE
GENERATION ALGORITHM

Case 1:- Slope of line is +ve & ≤ 1 & line starting from left to right

Case 2:- Slope of line is +ve & ≤ 1 & line starting from right to left

Case 3:- Slope of line is +ve & ≥ 1 & line starting from left to right

Case 4:- Slope of line is +ve & ≥ 1 & line starting from right to left

Case 5:- Slope of line is –ve

Xi+1 ,Yi+1

Δy
Line having m > 1

Xi , Yi Δx

22
Case 1:- Slope of line is +ve & ≤ 1 & line starting from left to right

Let (xi, yi) be any point on the line, as slope of line is less than 1, increment in X-
coordinate is set to unity i.e., Δ x = 1.

The X- coordinate of next point is xi+1 and Y-coordinate of next point i.e., yi+1 is
found out using the basic equation of slope i.e.,

m=Δy/Δx
m =Δy (as Δ x= 1)
Thus, the equation can be written as,
yi+1 – yi = m
yi+1 = yi + m

Using the above equation, it is possible to calculate Y-coordinate of next point, the
procedure is continued till the other end point of the line is reached.

It is necessary to round off the value of Y-coordinate to the next higher integer
because pixel on computer screen are oriented in integer fashion. This is the
disadvantage associated with DDA algorithm. Rounding off the numbers takes
longer time compared to execution of simple arithmetic operations.
23
Case 2:- Slope of line is +ve & ≤ 1 & line starting from right to left

The procedure is exactly the same as that of Case 1 except the change in X-
coordinate i.e., Δ x= -1

The X- coordinate of next point is xi+1 and Y-coordinate of next point i.e., yi+1 is
found out using the basic equation of slope i.e.,

m=Δy/Δx
- m=Δy (as Δ x= -1)
Thus, the equation can be written as,
yi+1 – yi = - m
yi+1 = yi - m

Using the above equation, it is possible to calculate Y-coordinate of next point, the
procedure is continued till the other end point of the line is reached.

24
Case 3:- Slope of line is +ve & ≥ 1 & line starting from left to right

Let (xi, yi) be any point on the line, as slope of line is greater than 1, increment in
Y-coordinate is set to unity i.e., Δ y = 1.

The Y- coordinate of next point is yi+1 and X-coordinate of next point i.e., xi+1 is
found out using the basic equation of slope i.e.,

m=Δy/Δx
m=1/Δx (as Δ y= 1)
Δx=1/m
Thus, the equation can be written as,
xi+1 – xi = 1 / m
xi+1 = xi + 1 / m

Using the above equation, it is possible to calculate X-coordinate of next point, the
procedure is continued till the other end point of the line is reached.

25
Case 4:- Slope of line is +ve & ≥ 1 & line starting from right to left

The procedure is same as Case 3 except change in Y-coordinate is set to – 1 i.e.,


Δ y= - 1
m=Δy/Δx
m = -1 / Δ x (as Δ y= -1)
Δ x = -1 / m
Thus, the equation can be written as,
xi+1 – xi = -1 / m
xi+1 = xi - 1 / m
Using the above equation, it is possible to calculate X-coordinate of next point, the
procedure is continued till the other end point of the line is reached.

Case 5:- Slope of line is –ve

In this case, absolute value of the slope is considered. If absolute value of the slope
is less than or equal to 1 then Case 1 or Case 2 is followed.

If the absolute value of m is greater than 1 then case 3 or Case 4 is followed.

26
2. BRESENHEM’s LINE GENERATION ALGORITHM
Two important points must be noted in case of this algorithm,
1. Line is always drawn from left to right, out of two end points given by user, the
bresenhem’s algorithm decides the one which is lying to the left as the starting point.
2. The equation of line y = mx + c is used to generate a line where c is the y –intercept.

Case 1:- Slope of line is +ve and less than 1 :-

yi + 1
d2
y
d1
yi

xi + 1 27
As the slope of line is less than 1, increment in x-coordinate is set to unity i.e., Δx = 1

Let (xi, yi) be any point on the line, the x-coordinate of next point will be xi+1 while y-
coordinate of the next point i.e., yi or yi+1 is decided by defining two parameters d1 and
d2 (decision parameters).
d1 = y – yi
d2 = yi + 1 –y
Where,
y = m (xi + 1)+ c
Substituting the value of y in the expression of d1 and d2 we have,
d1 = m (xi + 1)+ c – yi
d2 = yi + 1 – m (xi + 1)+ c
d1 - d2 = 2m (xi + 1) – yi – (yi + 1) + 2c

d1 - d2 = 2m (xi + 1) – 2yi + 2c – 1
d1 - d2 = 2(Δy / Δx) (xi + 1) – 2yi + 2c – 1
Δx (d1 - d2 ) = 2(Δy) (xi + 1) – 2 Δx yi + Δx (2c – 1)
Δx (d1 - d2 ) = 2Δy xi – 2 Δx yi + 2 Δy + Δx (2c – 1)
pi = 2Δy xi – 2 Δx yi + b
Where, pi = Δx (d1 - d2 )
& b = 2 Δy + Δx (2c - 1 )
28
The value of b remains constant for the complete line. The value of pixel position, pi is
evaluated to decide the pixel.
If pi < 0 , then select the pixel at position yi.
If pi ≥ 0 , then select the pixel at position yi + 1.
The procedure is continued till we reach the other end point of line.
In this procedure there is no rounding off operation, only the value of pi is to be
evaluated.
The expression of pi consists of simple arithmetic expression, which can be evaluated at
a faster rate on computer.

Case 2 :- Slope of line is > 1& +ve :-


In this case, change in y-coordinate i.e., Δy is set to unity.
The procedure is same as explained in Case 1 except Δy & Δx are interchanged in the
expression of pi.

Case 3 :- Slope of line is negative:-

In this case, absolute value of m is considered and the procedure as laid down in Case 1
& Case 2 is followed except one coordinate increases while other decreases.

29
NUMERICAL ON BRESENHAM’S LINE GENERATION

EXAMPLE 1:- Draw a straight line using bresenham’s algorithm


having end points as (35, 40) and (43, 45)

Solution:- Slope of line, m = ∆y / ∆x

1) If slope, m is less than or equal to 1 then,


Pi = 2 ∆y - ∆x
Pi+1 = Pi + 2 ∆y - 2 ∆x (yi+1 – yi)
Pi > = 0 then (xi+1, yi + 1)
Pi < 0 then (xi + 1, yi)
2) If slope, m is greater than 1 then,
Pi = 2 ∆x - ∆y
Pi+1 = Pi + 2 ∆x - 2 ∆y (xi+1 – xi)
Pi > = 0 then (xi+1, yi+1)
Pi < 0 then (xi, yi + 1)
30
Now in this example,
Slope, m = (45 – 40) / (43 – 35) = 5 / 8 = 0.6 < 1
Here slope, m is less than 1 and positive, therefore,
Pi = 2 ∆y - ∆x
Pi+1 = Pi + 2 ∆y - 2 ∆x (yi+1 – yi)
Pi > = 0 then (xi+1, yi + 1)
Pi < 0 then (xi + 1, yi)
Where,
∆x = Final coordinate - Initial coordinate = 43 – 35 = 8
∆y = Final coordinate - Initial coordinate = 45 – 40 = 5
Therefore, 2∆x = 16 and 2∆y = 10

Initial Decision Parameter,


Po = 2 ∆y - ∆x = 10 – 8 = 2 > 0 hence (xi+1, yi + 1)

31
Iterations (xi, yi) Pi (xi+1, yi+1) Pi+1 = Pi + 2 ∆y - 2 ∆x (yi+1 – yi)
0 (35, 40) 2 (36, 41) 2+10 – 16 (41- 40) = - 4
1 (36, 41) -4 (37, 41) - 4 +10 – 16 (41 – 41) = 6
2 (37, 41) 6 (38, 42) 6 + 10 – 16 (42 – 41) = 0
3 (38, 42) 0 ( 39, 43) 0 + 10 – 16 (43 – 42 ) = - 6
4 ( 39, 43) -6 ( 40 , 43) - 6 + 10 -16 (43 – 43 ) = 4
5 ( 40, 43 ) 4 ( 41, 44) 4 + 10 -16 (44 – 43) = - 2
6 ( 41, 44) -2 ( 42, 44) - 2 + 10 -16 ( 44 - 44) = 8
7 ( 42, 44) 8 ( 43, 45) Reach the end coordinates

32
By plotting all co-ordinates
46
45
44 By removing the repeat co-
43 ordinates
46
42
41 45

40 44

39 43
0 20 40 60 42
41
40
39
0 20 40 60

33
Example 2 :- Write bresenham’s algorithm for line generation for
slope is less than 1, using algorithm generate a line from ( 5, 8)
to ( 9, 11) – Summer 2017 for 9 Marks

34
Bresenhum’s Algorithm for Circle Generation :-

Equation of Circle x2+y2 = R2

Due to symmetry of circle only 1/8th part of the circle is drawn by calculating the
position of the pixel and remaining 7/8th part of the circle is generated by symmetry.

y=x

8 1
7
2
6 3
5 4

35
Mid Point Generating Algorithm (xi+1, yi)
(0,R)
yi
M (xi+1, yi-1/2)
|m|< 1 yi -1
(xi+1, yi-1)

xi
1
Let (xi, yi) be the ith pixel on the circle.
Let (xi+1, yi+1) be the i+1th pixel.

As slope is less than one i.e., |m|< 1 then increment in x- coordinate is set to unity
xi + 1 = xi + 1
yi + 1 = yi or yi - 1

A mid point ‘M’ between two pixel yi and yi – 1 is selected as shown in figure and
position of this point is used to determine whether yi or yi – 1 pixel is closer to circle.

1. If midpoint ‘M’ is inside the circle then,


xi +1 = xi + 1
yi + 1 = yi
36
2. If midpoint ‘M’ is outside the circle then,
xi + 1 = xi +1
yi + 1 = yi – 1
Now, co-ordinate of midpoint M is,
M (xm, ym) = (xi + 1, yi -1/2) ------ 1
Equation of circle is,
x2+y2 = R2
x2+y2 - R2 = 0
If x2+y2 - R2 < 0 M is Inside
If x2+y2 - R2 > 0 M is Outside
Let, Pixel Position , Pi = x2+y2 - R2
For midpoint the pixel position is
Pi = xm 2+ ym 2 - R2 -------------- 2
From equation 1,
Pi = (xi + 1)2+(yi – 1/2)2 - R2 ------------3
For i + 1th Pixel,
Pi + 1 = (xi + 1 + 1)2+(yi + 1 – 1/2)2 - R2 ------------ 4

Now, subtract equation 3 from equation 4, we get,

37
Pi +1 − Pi = [( xi + 1 + 1) 2 − ( xi + 1) 2 ] + [( yi + 1 − 1 / 2) 2 − ( yi − 1 / 2) 2 ]
Pi +1 = Pi + [( xi + 1 + 1) 2 − ( xi + 1) 2 ] + [( yi + 1 − 1 / 2) 2 − ( yi − 1 / 2) 2 ]
5
If Pi < 0 then M is inside
xi + 1 = xi + 1
yi + 1 = yi

Substitute in equation 5, we get,

Pi +1 = Pi + [( xi + 2) 2 − ( xi + 1) 2 ] + [( yi − 1 / 2) 2 − ( yi − 1 / 2) 2 ]
Pi +1 = Pi + [( xi + 2) 2 − ( xi + 1) 2 ]
Pi +1 = Pi + 2 xi + 3 6

38
If Pi > 0 then M is outside
xi + 1 = xi + 1
yi + 1 = yi - 1
Substitute in equation 5, we get,

Pi + 1 = Pi + [( xi + 1 + 1) 2 − ( xi + 1) 2 ] + [( yi − 1 − 1 / 2) 2 − ( yi − 1 / 2) 2 ]
Pi + 1 = Pi + [( xi + 2) 2 − ( xi + 1) 2 ] + [( yi − 3 / 2) 2 − ( yi − 1 / 2) 2 ]
Pi + 1 = Pi + 2 xi + 3 + [( yi 2 − 3 yi + 9 / 4) − ( yi 2 − yi + 1 / 4)]
Pi + 1 = Pi + 2 xi + 3 + [ yi 2 − 3 yi + 9 / 4 − yi 2 + yi − 1 / 4]
Pi + 1 = Pi + 2 xi + 3 + [ −2 yi + 8 / 4]
Pi + 1 = Pi + 2 xi − 2 yi + 5 7

Condition for plotting first pixel,


Substitute , x = 0 , y = R and Pi = P in equation 3, we get,

P1 = (0 + 1) 2 + ( R + 1 / 2) 2 − R 2
P1 = 1 + R 2 − R + 1 / 4 − R 2
5
P1 = −R (Float Value)
4
P1 = 1 − R (Integer Value) 8 39
NUMERICAL ON BRESENHAM’S CIRCLE GENERATION
(MIDPOINT CIRCLE GENERATING ALGORITHM)

Example 1 :- Draw a circle with radius 8 units using Bresenham’s


circle generating algorithm.

Solution:- For Initial co-ordinate,


Po = 1 – R (avoid fractional part)
Po = 1 – R = 1 – 8 = - 7
2 2 2 2
Pi +1 = Pi + [( xi + 1 + 1) − ( xi + 1) ] + [( yi + 1 − 1 / 2) − ( yi − 1 / 2) ]
1) If Pi is less than or equal to 0 then,
xi + 1 = xi + 1
yi + 1 = yi
2) If Pi is greater than 0 then,
xi + 1 = xi + 1
yi + 1 = yi - 1
40
Iterations (xi, yi) Pi (xi+1, yi+1) Pi+1 = Pi + [ (xi+1 +1)2 – (xi + 1)2] + [ (yi+1 -1/2)2 - (yi – 1/2)2]

0 (0, 8) -7 ( 1, 8) -7 + [ (1 +1)2 – (0 + 1)2] + [ (8 - 1/2)2 - (8 – 1/2)2] = - 4

1 ( 1, 8) -4 ( 2, 8) - 4 + [ (2 +1)2 – (1 + 1)2] + [ (8 - 1/2)2 - (8 – 1/2)2] = 1

2 ( 2, 8) 1 ( 3, 7) 1 + [ (3 +1)2 – (2 + 1)2] + [ (7 - 1/2)2 - (8 – 1/2)2] = - 6

3 ( 3, 7) -6 ( 4, 7) - 6 + [ (4 +1)2 – (3 + 1)2] + [ (7 - 1/2)2 - (7 – 1/2)2] = 3

4 ( 4, 7) 3 ( 5, 6) 3 + [ (5 +1)2 – (4 + 1)2] + [ (6 - 1/2)2 - (7 – 1/2)2] = 2

5 ( 5, 6) 2 ( 6, 5) 2 + [ (6 +1)2 – (5 + 1)2] + [ (5 - 1/2)2 - (6 – 1/2)2] = 5

6 ( 6, 5) 5 ( 7, 4) 5 + [ (7 +1)2 – (6 + 1)2] + [ (4 - 1/2)2 - (5 – 1/2)2] = 12

7 (7, 4) 12 (8, 3) 12 + [ (8 +1)2 – (7 + 1)2] + [ (3 - 1/2)2 - (4 – 1/2)2] = 23

8 (8, 3) 23 (8, 2) 23 + [ (8 +1)2 – (8 + 1)2] + [ (2 - 1/2)2 - (3 – 1/2)2] = 19

9 (8, 2) 19 (8, 1) 19 + [ (8 +1)2 – (8 + 1)2] + [ (1 - 1/2)2 - (2 – 1/2)2] = 17

10 (8, 1) 17 (8, 0) Reached the first quadrant on X- axis

41
By plotting all co-ordinates
9
8
7
By removing the repeat co-
6
ordinates
5
9
4
8
3
7
2
6
1
5
0
0 5 10 4
3
2
1
0
0 5 10

42
Example 2 :- Write bresenham’s algorithm for circle generation
using algorithm generate a circle with radius 10 units at centre
( 1, 1) up to first octant– Winter 2018 for 9 Marks

Solution:- For Initial co-ordinate,

Po = 1 – R (avoid fractional part)


Po = 1 – R = 1 – 10 = - 9
If Pi is less than or equal to 0 then,
xi + 1 = xi + 1
yi + 1 = yi
If Pi is greater than 0 then,
xi + 1 = xi + 1
yi + 1 = yi - 1

43
Iterations (xi, yi) Pi (xi+1, yi+1) Pi+1 = Pi + [ (xi+1 +1)2 – (xi + 1)2] + [ (yi+1 -1/2)2 - (yi – 1/2)2]

0 (1 , 11) -9 (2, 11)


1
2
3
4
5
6
7
8
9
10

44
BRESENHUM’s ALGORITHM FOR GENERATION OF ELLIPSE
Mid – point generating algorithm for ellipse

x2 y2
2
+ 2
=1
Equation of Ellipse is Rx Ry
Due to symmetry of ellipse only 1/4th part of the ellipse is drawn by plotting of pixel
and remaining 3/4th part is generated by symmetry.
|m| < 1
|m| > 1

Ry

Rx

45
To draw 1/4th part of the ellipse, we have to divide it into two parts i.e., Part I and Part II
as shown in figure.
|m| < 1
|m| > 1
(0, Ry)
I
II

x2 y2
Equation of Ellipse is
2
+ 2
=1
Rx Ry
x 2 Ry 2 + y 2 Rx 2 = Rx 2 Ry 2
Differentiate w.r.t. x and y, we get

2 xdxRy 2 + 2 ydyRx 2 = 0
2 xdxRy 2 = −2 ydyRx 2
dy xRy 2
=− 1
dx yRx 2
dy
=m 46
dx
xRy2 < yRx2 xRy2 = yRx2

xRy2 > yRx2


I
II

Put dy
= −1 in equation 1
dx
xRy 2
-1 = −
yRx 2
xRy 2 = yRx 2

47
At a point on ellipse where slope is - 1 condition is
xRy 2 = yRx 2
Ellipse is now divided into two parts,
Part 1 : -
| m | 1
xRy 2  yRx 2
xi + 1 = xi + 1
yi + 1 = yi or yi − 1
Part 2 : -
| m | 1
xRy 2  yRx 2
yi + 1 = yi + 1
xi + 1 = xi or xi + 1
48
MID POINT ALGORITHM TO DRAW PART I OF ELLIPSE WHERE |m| < 1 :-
(xi+1, yi)
yi
M (xi+1, yi-1/2)
|m|< 1 yi -1
(xi+1, yi-1)

xi xi+1
1
ith
Let (xi, yi) be the pixel on the circle.
Let (xi+1, yi+1) be the i+1th pixel.

As slope is less than one i.e., |m|< 1 then increment in x- coordinate is set to unity
xi + 1 = xi + 1
yi + 1 = yi or yi - 1

1. If midpoint ‘M’ is inside the circle then,


xi +1 = xi + 1
yi + 1 = yi

49
2. If midpoint ‘M’ is outside the circle then,
xi + 1 = xi +1
yi + 1 = yi – 1

x Ry + y Rx − Rx Ry = 0
2 2 2 2 2 2

If LHS < 0 then M is Inside


LHS > 0 then M is Outside

Let
Pi = xm Ry 2 + ym Rx 2 − Rx 2 Ry 2
2 2

Pi = ( xi + 1) 2 Ry 2 + ( yi − 1 / 2) 2 Rx 2 − Rx 2 Ry 2 2

For i + 1th pixel


Pi +1 = ( xi + 1 + 1) 2 Ry 2 + ( yi + 1 − 1 / 2) 2 Rx 2 − Rx 2 Ry 2 3

50
Equation 2 – 3, we get,

Pi +1 − Pi = [( xi + 1 + 1) 2 − ( xi + 1) 2 ]Ry 2 + [( yi + 1 − 1 / 2) 2 − ( yi − 1 / 2) 2 ]Rx 2
Pi +1 = Pi + [( xi + 1 + 1) 2 − ( xi + 1) 2 ]Ry 2 + [( yi + 1 − 1 / 2) 2 − ( yi − 1 / 2) 2 ]Rx 2 4

If Pi  0 then
xi + 1 = xi + 1
yi + 1 = yi
Put in equation 4, we get,
Pi + 1 = Pi + [( xi + 1 + 1) 2 − ( xi + 1) 2 ]Ry 2 + 0
Pi + 1 = Pi + [( xi + 2) 2 − ( xi + 1) 2 ]Ry 2
Pi + 1 = Pi + [ xi 2 + 4 xi + 4 − xi 2 − 2 xi − 1]Ry 2
Pi + 1 = Pi + [2 xi + 3]Ry 2 5

51
If Pi  0 then
xi + 1 = xi + 1
yi + 1 = yi − 1
Put in equation 4, we get,
Pi + 1 = Pi + [2 xi + 3]Ry 2 + [( yi − 1 − 1 / 2) 2 − ( yi − 1 / 2) 2 ]Rx 2
Pi + 1 = Pi + [2 xi + 3]Ry 2 + [( yi − 3 / 2) 2 − ( yi − 1 / 2) 2 ]Rx 2
Pi + 1 = Pi + [2 xi + 3]Ry 2 + [ yi 2 − 3 yi + 9 / 4 − yi 2 + yi − 1 / 4]Rx 2
Pi + 1 = Pi + [2 xi + 3]Ry 2 + [−2 yi + 2]Rx 2
Pi + 1 = Pi + [2 xi + 3]Ry 2 + [2 − 2 yi]Rx 2 6

52
Condition for plotting first pixel
Put xi = 0, yi = Ry, Pi = P1 in equation 2
Pi = ( xi + 1) 2 Ry 2 + ( yi − 1 / 2) 2 Rx 2 − Rx 2 Ry 2
Pi = (0 + 1) 2 Ry 2 + ( Ry − 1 / 2) 2 Rx 2 − Rx 2 Ry 2
Pi = Ry 2 + ( Ry − 1 / 2) 2 Rx 2 − Rx 2 Ry 2
Pi = Ry 2 + ( Ry 2 − Ry + 1 / 4) Rx 2 − Rx 2 Ry 2
Pi = Ry 2 + Ry 2 Rx 2 − RyRx 2 + 1 / 4 Rx 2 − Rx 2 Ry 2
Pi = Ry 2 − RyRx 2 + 1 / 4 Rx 2
Pi = Ry 2 − Rx 2 ( Ry − 1 / 4) for float value
Pi = Ry 2 − Rx 2 Ry for Integer Value

53
MID POINT ALGORITHM TO DRAW PART II OF ELLIPSE WHERE |m| > 1 :-

(xi-1, yi+1)
M (xi-1/2, yi+1)

|m|>1 yi -1
yi (xi, yi+1)

xi-1 xi
1
Let (xi, yi) be the ith pixel on the circle.
Let (xi+1, yi+1) be the i+1th pixel.

As slope is less than one i.e., |m|> 1 then increment in y- coordinate is set to unity
yi + 1 = yi + 1
xi + 1 = xi or xi - 1

1. If midpoint ‘M’ is inside the circle then,


yi +1 = yi + 1
xi + 1 = xi

54
2. If midpoint ‘M’ is outside the circle then,
yi + 1 = yi +1
xi + 1 = xi – 1

x Ry + y Rx − Rx Ry = 0
2 2 2 2 2 2

If LHS < 0 then M is Inside


LHS > 0 then M is Outside

Let
Pi = xm Ry 2 + ym Rx 2 − Rx 2 Ry 2
2 2

Pi = ( xi − 1 / 2) 2 Ry 2 + ( yi + 1) 2 Rx 2 − Rx 2 Ry 2 2

For i + 1th pixel


Pi +1 = ( xi + 1 − 1 / 2) 2 Ry 2 + ( yi + 1 + 1) 2 Rx 2 − Rx 2 Ry 2 3

55
Equation 2 – 3, we get,

Pi +1 − Pi = [( xi + 1 − 1 / 2) 2 − ( xi − 1 / 2) 2 ]Ry 2 + [( yi + 1 + 1) 2 − ( yi + 1) 2 ]Rx 2 4

If Pi  0 then
yi + 1 = yi + 1
xi + 1 = xi
Put in equation 4, we get,
Pi + 1 = Pi + [( xi − 1 / 2) 2 − ( xi − 1 / 2) 2 ]Ry 2 + [( yi + 1 + 1) 2 − ( yi + 1) 2 ]Rx 2
Pi + 1 = Pi + [( yi + 2) 2 − ( yi + 1) 2 ]Rx 2
Pi + 1 = Pi + [ yi 2 + 4 yi + 4 − yi 2 − 2 yi − 1]Rx 2
Pi + 1 = Pi + [2 yi + 3]Rx 2 5

56
If Pi  0 then
yi + 1 = yi + 1
xi + 1 = xi − 1
Put in equation 4, we get,
Pi + 1 = Pi + [( xi − 1 − 1 / 2) 2 − ( xi − 1 / 2) 2 ]Ry 2 + [2 yi + 3]Rx 2
Pi + 1 = Pi + [−2 xi + 2]Ry 2 + [2 yi + 3]Rx 2 6

57
Condition for plotting first pixel
Put xi = Rx, yi = 0, Pi = P1 in equation 2
Pi = ( Rx − 1 / 2) 2 Ry 2 + (0 + 1) 2 Rx 2 − Rx 2 Ry 2
Pi = ( Rx 2 − Rx + 1 / 4) Ry 2 + Rx 2 − Rx 2 Ry 2
Pi = Rx 2 Ry 2 − RxRy 2 + 1 / 4 Ry 2 + Rx 2 − Rx 2 Ry 2
Pi = Rx 2 − RxRy 2 + 1 / 4 Ry 2
Pi = Rx 2 − Ry 2 ( Rx − 1 / 4) for float value
Pi = Rx 2 − Ry 2 Rx for Integer Value

58
NUMERICAL ON BRESENHAM’S ELLIPSE GENERATION
(MIDPOINT ELLIPSE GENERATING ALGORITHM)

Example 1 :- Draw a ellipse with major axis as 8 units and minor


axis as 6 units using Bresenham’s ellipse generating algorithm.

Solution:- Here, Rx = 8 units and Ry = 6 units


Condition for plotting part I of ellipse where |m| < 1,
Po = Ry 2 − Rx 2 Ry (avoid fractional part)

Po = (6)2 – (8)2 * 6 = - 348


Pi + 1 = Pi + [( xi + 1 + 1) 2 − ( xi + 1) 2 ]Ry 2 + [( yi + 1 − 1 / 2) 2 − ( yi − 1 / 2) 2 ]Rx 2

1) If Pi is less than or equal to 0 then,


xi + 1 = xi + 1
yi + 1 = yi
2) If Pi is greater than 0 then,
xi + 1 = xi + 1
yi + 1 = yi - 1 59
Iterations (xi, yi) Pi (xi+1, yi+1) Pi + 1 = Pi + [( xi + 1 + 1) 2 − ( xi + 1) 2 ]Ry 2 + [( yi + 1 − 1 / 2) 2 − ( yi − 1 / 2) 2 ]Rx 2

0 (0, 6) - 348 ( 1, 6) - 348 + [(1+1)2 – (0+1)2] 36 +[(5.5)2 – (5.5)2]64 = - 240

1 ( 1, 6) - 240 (2, 6) - 240 + [(2+1)2 – (1+1)2] 36 +[(5.5)2 – (5.5)2]64 = - 60

2 (2, 6) -60 (3, 6) - 60 + [(3+1)2 – (2+1)2] 36 +[(5.5)2 – (5.5)2]64 = 192

3 (3, 6) 192 (4, 5) 192 + [(4+1)2 – (3+1)2] 36 +[(4.5)2 – (5.5)2]64 = - 124

4 (4, 5) -124 (5, 5) -124 + [(5+1)2 – (4+1)2] 36 +[(4.5)2 – (4.5)2]64 = 272

5 (5, 5) 272 (6, 4) 272 + [(6+1)2 – (5+1)2] 36 +[(3.5)2 – (4.5)2]64 = 228

6 (6, 4) 228 (7, 3) Ellipse reached up to part I afterwards the |m| > 1

60
Conditions for plotting part II of ellipse where |m| > 1

Here, Rx = 7 units and Ry = 3 units

Po = Rx 2 − Ry 2 Rx (avoid fractional part)


Po = (7)2 – (3)2 * 7 = - 14

Pi +1 = Pi + [( xi + 1 − 1 / 2) 2 − ( xi − 1 / 2) 2 ]Ry 2 + [( yi + 1 + 1) 2 − ( yi + 1) 2 ]Rx 2

(0, 6) Part I

(7,3)

Part II

61
Pi +1 = Pi + [( xi + 1 − 1 / 2) 2 − ( xi − 1 / 2) 2 ]Ry 2 + [( yi + 1 + 1) 2 − ( yi + 1) 2 ]Rx 2
Iterations (xi, yi) Pi (xi+1, yi+1)

0 (7, 3) - 14 (8, 3) - 14 + [(7.5)2 – (6.5)2] 9 + [(4)2 – (4)2] 49 = 112

1 (8, 3) 112 (8, 2) 112 + [(7.5)2 – (7.5)2] 9 + [(3)2 – (4)2] 49 = -231

2 (8, 2) -231 (8, 1) -231 + [(7.5)2 – (7.5)2] 9 + [(2)2 – (3)2] 49 = - 476

3 (8, 1) - 476 (8, 0) Ellipse completed part II

62
By plotting all co-ordinates
7
6
5 By removing the repeat co-
4
ordinates
7
3
6
2
5
1
4
0
0 5 10 3
2
1
0
0 5 10

63
THANK YOU.

64

You might also like