Data Communication and Computer 22414 Unit Wise Notes
Syllabus DCC(314318)
8.outtexty(intx,inty.”text”); Outtexty function is used to insert text at the given position(x,y).
We say these computers have vector graphics capability (the line is a vector).
The process is turning on pixels for a line segment is called vector generation and algorithm for them is known as vector generation algorithm.
Problems of vector generation:
·
Line is straight but width is no constant.
·
Brightness of line dependent on orientation of the line.
·
Calculate only an approximate linelength.
·
Reduce the calculations using simple
integer arithmetic.
Line Drawing Algorithms
1. DDA Algorithm (Digital Differential Analyzer)
Step1: Start Algorithm
Step2: Declare x1,y1,x2,y2,dx,dy,x,y as integer variables.
Step3: Enter value of
x1,y1,x2,y2. Step4: Calculate dx = x2-x1 Step5: Calculate dy = y2-y1
Step6: If ABS (dx) > ABS (dy) Then step = abs (dx) Else
Step7: xinc=dx/step yin=dy/step assign x = x1 assign y = y1
Step8: Set pixel
(x, y)
Step9: x = x +
xinc
y = y + yinc
Set pixels
(Round (x), Round (y))
Step10: Repeat step 9 until
x =
x2
It’s an accurate and efficient raster line generating Algorithm. Bresenham's line-drawing algorithm uses an iterative scheme. A key feature of the algorithm is that it requires only integer data and simple arithmetic. This makes the algorithm very efficient andfast.
Procedure for Bresenham’s algorithm:
1.Read line end points (x1,y1) and (x2,y2) such that they are not equal.
2. dx=|x2-x1| and dy=|y2-y1| 3.x=x1 and y=y1
4.e=2*dy-dx 5.i=1
6.plot (x,y) 7.while (e>0)
{
x=y+1 e=e-2*dx
}
x=x+1 e=e+2*dy
8 for .i=i+1
9. if(i<dx) then goto step 6.
10. Stop.
Enter the upper left corner of the rectangle:
100
100
Enter the lower right corner of the rectangle:
200
200
******2DTransformations*******
1.Translation
2.Rotation
3.Scaling
4.Reflection
5.Shearing
6.Exit
Enter your choice: 1
*******Translation******* Enter the value of shift vector:
150
150
******2DTransformations*******
1.Translation
2.Rotation
3.Scaling
4.Reflection
5.Shearing
6.Exit
Enter your choice: 2
*******Rotation*******
Enter the value of fixed point and angle of rotation:
300
300
70
******2DTransformations******* 1.Translation
2.Rotation
3.Scaling
4.Reflection
5.Shearing
6.Exit
Enter your choice: 3
********Scaling*******
Enter the value of scaling factor:
2
2
******2DTransformations*******
1.Translation
2.Rotation
3.Scaling
4.Reflection
5.Shearing
6.Exit
Enter your choice: 4
*******Reflection*********
1.About x-axis
2.About y-axis
3.About both axis
Enter your choice:1
Enter the fixed point
150
150
Enter your choice: 2
Enter the fixed point
150
150
Enter your choice: 3
Enter the fixed point
150
150
******2DTransformations******* 1.Translation
2.Rotation
3.Scaling
4.Reflection
5.Shearing
6.Exit
Enter your choice: 5
*******Shearing*********
1.x-direction shear
2.y-direction shear
Enter your choice: 1
Enter the value of shear : 2
Enter your choice: 2
Enter the value of shear : 2
Algorithm:
Step 1: Start the program.
Step 2: input the points for the cude and size of the Cube.
Step 3: Display the menu as 1.Translation 2.Scaling 3.Rotation 4.Exit
Step 4: Get the choice from the user.
Step 5: If the choice is 1 a point or an object is translated from position P to position P‘ with the operation P’=T.P where tx,ty and tz specifying translation distances.
x’=x+ tx ,y’=y+ ty,z’=z+ tz
Step 6: If the choice is 2 the scaling transformation of a position P can be written as P’=S.P where scaling parameters sx,sy and sz are assigned any positive values.
x’=x.sx ,y’=y.sy ,z’=z.sz
Step 7: If the choice is 3 get the rotation angle. Rotate the figure with respect to the axis of rotation.
Step 8: About z axis rotation x’=xcosӨ-ysinӨ ,y’=xsinӨ+ycosӨ
z’=z Rotation can be expressed as P’=Rz(Ө).P
Step 9: About x axis rotation y’=ycosӨ-zsinӨ z’=ysinӨ+zcosӨ x’=x
Rotation can be expressed as P’=Rx(Ө).P
Step 10: About y axis rotation z’=zcosӨ-xsinӨ x’=zsinӨ+xcosӨ y’=y
Rotation can be expressed as P’=Ry(Ө).P
Step 11: If choice is 4 exit the program.
Step 12: Stop the program.
Algorithm :
1) Read two end points of line P1 (x1,y1) and P2 (x2,y2).
2)
Read corners
of window (Wx1, Wy1) and (Wx2, Wy2).
3) Assign region codes for P1 and P2. A region code is a 4
digit bit code
which indicates one of nine regions
having the end point of line.
Initialize code with bits 0000
Set Bit
1 if(x<Wx1) Set Bit
2 if (x>Wx2) Set Bit
3 if (y<Wy2) Set Bit
4 if (y>Wy1)
4)
Check visibility of line P1P2
a) If region codes for both end points P1 and P2 are 0 =
>
Line is completely visible. Draw Line and Go to Step 3.
b) If region codes for both end points P1 and P2 are not 0
and
logical ANDing of them is
also not zero = > Line is completely invisible. Reject line and Go to Step 3.
c) If a) and b) both are not satisfied, line is partially visible.
5) Divide partially visible line segments to equal parts and repeat steps 3 through 5 for both sub divided line segments until you get completely
visible and completely invisible line
segments.
6)
Stop.
// output:
//enter the co-ordinate of px :20
//enter the co-ordinate of py: 200
//enter the co-ordinate of px: 40
//enter the co-ordinate of py: 300
//enter the co-ordinate of px: 80
//enter the co-ordinate of py: 30
//enter the co-ordinate of px: 50
//enter the co-ordinate of py: 400