You are on page 1of 19

WOLLO UNIVERSITY

KOMBOLCHA INSTITUTE OF TECHNOLOGY


Collage of Informatics
Department of Software Engineering

Group Name……………………………ID
1) Udo Mabratu 0828/11
2) Bahiru Balina 0578/11
3) Amanuel Wagari 0561/11
4) Melaku Wondesen 0721/11
5) Abraham Habtemu 0965/11
What is point?
• A point is a location and a dimensionless shape represented by a dot.
• Named by capital letter. Point C, Point M, Point Q.
• A point does not have any length, width, shape or size.

• It only has a position.


• When two distinct points are connected they form a line.
What is point in computer graphics?
• The point is a most basic graphical element & is completely defined
by a pair of user coordinates (x, y).
• A Point in three-dimensional geometry is defined as a location in 3D
space that is uniquely defined by an ordered triplet (x, y, z) where x, y,
& z are the distances of the point from the X-axis, Y-axis, and Z-axis
respectively
Types of Points
There are different types of points in geometry, such as:
 Collinear and Non-collinear points
 Coplanar and Non-coplanar points

Collinear points lie on the same line but non-collinear points do not lie on the same line.
Coplanar points line on the same plane but non-coplanar points do not lie on the same plane.
What is line in computer graphics?
• A line connects two points.
• It is a basic element in graphics.
• To draw a line, you need two points between which you can draw a
line.
• Lines can appear in many different forms some examples may be
straight, curved, continuous, dotted, thick and thin.
Line Attributes In Computer Graphics:
• The line is one of the major inbuild functions in computer graphics,
This helps to make more interactive & interesting images.
• As the line is the function there some attributes or arguments are
present. These help to draw a line in a better position.
• There are mainly four coordinates.
• Two are the starting coordinates & the two are for ending coordinates.
Syntax:
line(int X1, int Y1, int X2, int Y2);
Types Of Lines In Computer Graphics:
• Users can derive mainly three types of lines by playing with the attribute
values of the lines.
Horizontal line
line(100, 300, 400, 300);

• Vertical line
line(600, 200, 600, 400);

• Tangent line
line(250, 400, 450, 500);
How to draw line
• graphics.h library is used to include and facilitate graphical operations
in program.
• graphics.h functions can be used to draw different shapes, display text
in different fonts, change colors and many more.
• Using functions of graphics.h you can make graphics programs,
animations, projects and games. You can draw circles, lines,
rectangles, bars and many other geometrical figures.
• Step 1: Here, we will first include the necessary header file for
working on the computer graphics.
• Step 2: Then we color the line using setcolor() function.
• Step 3: Now, we will use the line attributes. As this is the horizontal
line, we have to keep same the values of Y coordinates. The distance
will depend upon the difference between X1 & X2.
• As this is the vertical line, we have to keep same the values of X
coordinates. The distance will depend upon the difference between Y1
& Y2.
• As this is the tangent line, all the values must not be the same as each
other. The distance will depend upon the difference between X1 & Y1,
X2 & Y2.
• Step 4: We have to close the graph using closegraph() function.
Examples:
For line 1, Input : x1 = 150, y1 = 150, x2 = 450, y2 = 150
For line 2, Input : x1 = 150, y1 = 200, x2 = 450, y2 = 200
For line 3, Input : x1 = 150, y1 = 250, x2 = 450, y2 = 250
Why Line in computer graphics?
• One of the main uses of lines is in the separation of borders in a work.
• It is commonly used in illustrations as a way to help viewers
distinguish a subject’s edges or boundaries and to create individual
shapes
• Another use of line in graphics is the ability to help suggest a tone or
feeling in a work.
• Lines direct your attention to some particular part of the image.
• Lines of different weights, colors, and solidity can make the design
look decorative. ...
• Divide the space into parts.
Bresenham's Line Algorithm
• This algorithm is used for scan converting a line.
• It was developed by Bresenham.
• It is an efficient method because it involves only integer addition,
subtractions, and multiplication operations.
• These operations can be performed very rapidly so lines can be
generated quickly.
• In this method, next pixel selected is that one who has the least
distance from true line.
The method works as follows:
Step1: Start Algorithm
Step2: Declare variable x1,x2,y1,y2,d,i1,i2,dx,dy
Step3: Enter value of x1,y1,x2,y2
Where x1,y1are coordinates of starting point
And x2,y2 are coordinates of Ending point
Step4: Calculate dx = x2-x1
Calculate dy = y2-y1
Calculate i1=2*dy
Calculate i2=2*(dy-dx)
Calculate d=i1-dx
Step5: Consider (x, y) as starting point and xend as maximum possible value of x.
If dx < 0
Then x = x2
y = y2
xend=x1
If dx > 0
Then x = x1
y = y1
xend=x2
Step6: Generate point at (x,y)coordinates.

Step7: Check if whole line is generated.


If x > = xend
Stop.
Step8: Calculate co-ordinates of the next pixel
If d < 0
Then d = d + i1
If d ≥ 0
Then d = d + i2
Increment y = y + 1

Step9: Increment x = x + 1
Step10: Draw a point of latest (x, y) coordinates
Step11: Go to step 7
Step12: End of Algorithm
• Example: Starting and Ending position of the line are (1, 1) and (8, 5).
Find intermediate points.
Solution: x1=1, y1=1
x2=8, y2=5
dx= x2-x1=8-1=7
dy=y2-y1=5-1=4
I1=2* ∆y=2*4=8
I2=2*(∆y-∆x)=2*(4-7)=-6
d = I1-∆x=8-7=1
x y d=d+I1 or I2

1 1 d = I1-∆x=8-7=1

2 2 d+I2=1+(-6)=-5

3 2 d+I1=-5+8=3

4 3 d+I2=3+(-6)=-3

5 3 d+I1=-3+8=5

6 4 d+I2=5+(-6)=-1

7 4 d+I1=-1+8=7

8 5 d+I2=7+(-6)=1
Why Bresenham's
 It involves only integer arithmetic, so it is simple.
 It avoids the generation of duplicate points.
 It can be implemented using hardware because it does not use
multiplication and division.
 It is faster as compared to DDA (Digital Differential Analyzer)
because it does not involve floating point calculations like DDA
Algorithm.

You might also like