OUTPUT PRIMITIVES - Technical symposium.com



SYLLABUS

CS2405 COMPUTER GRAPHICS LAB L T P C

0 0 3 2

1. Implementation of Bresenhams Algorithm – Line, Circle, Ellipse.

2. Implementation of Line, Circle and ellipse Attributes.

3. Two Dimensional transformations - Translation, Rotation, Scaling, Reflection,Shear.

4. Composite 2D Transformations.

5. Cohen Sutherland 2D line clipping and Windowing

6. Sutherland – Hodgeman Polygon clipping Algorithm.

7. Three dimensional transformations - Translation, Rotation, Scaling.

8. Composite 3D transformations.

9. Drawing three dimensional objects and Scenes.

10. Generating Fractal images.

TOTAL = 45 PERIODS

EX NO 1 OUTPUT PRIMITIVES

Aim:

To write a C Program to display the output primitives.

Algorithm:

1. Start the program .

2. Initialize the variables.

3. Call the initgraph() function

4. Set color for the output primitives.

5. Using Outtextxy() display the chosen particular primitives.

6. Using switch case mention the various primitives and their attributes.

7. The various primitives are arc, line ,circle, rectangle and ellipse.

8. close the graph and run the program.

9. stop the program.

EX NO 2a DDA ALGORITHM

AIM

To write a C program to draw a line using DDA algorithm.

The digital differential analyzer is a scan conversion algorithm based on

calculation either ∆y or ∆x using the following equations

∆y = m∆x

∆x = ∆y / m

Sample the line at unit intervals in one coordinate and determine corresponding integer values nearest the line path for the other coordinate.

Sample at X intervals (∆x = 1) and compute each successive Y value as

Yk+1 = Yk + m

For lines with positive slope greater than 1, reverse the roles of X and Y. Sample at unit Y intervals (∆y = 1)and calculate each successive X value as

Xk+1 = Xk + 1/m

Algorithm

Step 1: Input the line endpoints and store the left endpoint in (x1, y1) and right

endpoint in (x2, y2)

Step 2: Calculate the values of ∆x and ∆y using ∆x = xb – xa, ∆y = yb – ya

Step 3: if the values of ∆x > ∆y assign values of steps as ∆x otherwise the values

of steps as ∆y

Step 4: Calculate the values of X increment and Y increment and assign

the value x= xa and y = ya

Step 5: for k=1 to steps do

X = X + X increment

Y= Y + Y increment

Putpixel(ceil(x), ceil(y),15)

EX NO 2b BRESENHAM’S LINE DRAWING ALGORITHM

AIM

To write a C program to draw a line using Bresenham’s algorithm.

In Bresenham’s approach the pixel position along a line path are determined by sampling unit X intervals. Starting from the left end point(X0, Y0)of a given line we step to each successive columns and plot the pixel whose scan line Y-value is closest to the line path. Assuming the Kth step in process, determined that the pixel at(Xk, Yk)decide which pixel to plot in column Xk+1.The choices are (Xk+1, Yk) and (Xk+1,Yk+1)

Algorithm

Step 1: Input the line endpoints and store the left endpoint in (X0, Y0)

Step 2: Load (X0, Y0) in to the frame buffer

Step 3: Calculate constants ∆x, ∆y, 2∆y, and 2∆y -2∆x, and obtain the decision parameters as

P0 = 2 ∆y – ∆x

Step 4 : At each Xk along the line, starting at k = 0, perform the following test.

If Pk < 0, the next point to plot is (Xk+1, Yk) and

Pk+1 = Pk+2∆y

Otherwise, the next point to plot is (Xk+1, Yk+1) and

Pk+1 = Pk+2 ∆y - 2 ∆x

Step 5: Repeat step 4 ∆x times

EX NO 3 MIDPOINT CIRCLE DRAWING ALGORITHM

AIM

To write a C program to draw a circle using Bresenham’s algorithm.

Algorithm

Step 1:Input radius r and circle center(Xc, Yc)and obtain the first point on the circumference of a circle centered on the origin as (X0, Y0) = (0, r)

Step 2: Calculate the initial values of the decision parameter as

P0 = 5/4 – r

Step 3: At each position starting at k perform the following test:

If Pk < 0, the next point to plot is (Xk+1, Yk) and

Pk+1 = Pk+2 Xk+1 + 1

Otherwise the next point is (Xk+1, Yk-1) and

Pk+1 = Pk+2 Xk+1 + 1- 2Yk+1

where 2Xk+1=2Xk+2 and 2Yk+1=2Yk-2

Step 4: Determine symmetry points in the other seven octants

Step 5: Move each pixel position(X, Y) onto the circular path centered on(Xc, Yc) and plot the coordinate values as

X = X + Xc Y = Y + Yc

Step 6: Repeat steps 3 through until X>=Y

EX NO 4 MIDPOINT ELLIPSE DRAWING ALGORITHM

AIM

To write a C program to draw an ellipse using midpoint ellipse algorithm.

Algorithm

Step 1: Input radius rx, ry and ellipse center (Xc, Yc) and obtain the first point on the circumference of a circle centered on the origin as (X0, Y0) = (0, ry)

Step 2: Calculate the initial values of the decision parameter in region 1 as

P10 = r2y – r2x ry + 1/4 r2x

Step 3: At each Xk position in region 1, starting at k = 0, perform the following test:

If P1k < 0, the next point to plot is (Xk+1, Yk) and

P1k+1 = P1k+2 r2yXk+1 + r2y

Otherwise the next point is (Xk+1, Yk-1) and

P1k+1 = P1k+2 r2yXk+1 - 2r2xYk+1 + r2y

With

2 r2yXk+1=2 r2yXk+ 2r2y

2r2xYk+1=2r2xYk- 2r2x

Step 4: Calculate the initial values of the decision parameter in region 2 as

P20 = r2y(X0+1/2)2+ r2x(Y0 – 1)2- r2x r2y

Step 5: At each position starting at Yk position in region 2, starting at k = 0,

perform the following test:

If P2k > 0, the next point to plot is (Xk, Yk-1) and

P2k+1 = P2k - 2 r2yYk+1 + r2x

Otherwise the next point is (Xk+1, Yk-1) and

P2k+1 = P2k - 2 r2yXk+1 - 2r2xYk+1 + r2x

Step 6: Determine symmetry points in the other three octants

Step 7: Move each pixel position(X, Y) onto the circular path centered on

(Xc, Yc) and plot the coordinate values as

X = X + Xc Y = Y + Yc

Step 8: Repeat steps for region 1 until 2 r2yX>=2 r2xY

EX NO 5 IMPLEMENTATION OF LINE,CIRCLE & ELLIPSE ATTRIBUTES

Aim:

To write a C Program to display the various attributes of line, circle and ellipse.

Algorithm:

1. Start the program .

2. Initialize the variables.

3. Call the initgraph() function

4. Set color for the output primitives.

5. Using Outtextxy() display the chosen particular primitives.

6. Include the various attributes of line, circle and ellipse.

7. close the graph and run the program.

8. stop the program.

EX NO 6a 2 -D TRANFORMATIONS- TRANSLATION & ROTATION

AIM

To perform the various 2-dimensional transformations such as translation, rotation.

Algorithm

Step 1: Input the figure.

Step 2: Display the menu as 1.Translation 2.Rotation 3.Exit

Step 3: Get the choice from the user.

Step 4: If the choice is 1 get the translation vector. Add the translation vector to the original coordinate position to move to a new position.

Step 5: If the choice is 2 get the rotation angle. Rotate the figure with respect to the specified angle.

Step 9: If choice is 3 exit the program.

EX NO 6b 2 -DIMENSIONAL TRANFORMATIONS

AIM

To perform the various 2-dimensional transformations such as scaling, reflection and shearing.

Algorithm

Step 1: Input the figure.

Step 2: Display the menu as 1.Scaling 2.Reflection 3.Shearing 4.Exit

Step 3: Get the choice from the user.

Step 4: If the choice is 1 get the scaling factor. Multiply the coordinate values of each vertex by scaling factors to produce the transformed coordinates.

Step 5: If the choice is 2 get the axis of reflection. Mirror image is generated relative to an axis of reflection by rotating the object 180◦ about the reflection axis.

Step 6: If the choice is 3 shearing is done which causes the transformation that distorts the shape of an object.

Step 7: If choice is 4 exit the program.

EX NO 7 COHEN-SUTHERLAND ALGORITHM

AIM:

To clip a line using Cohen-Sutherland clipping algorithm.

Algorithm:

The method speeds up the processing of line segments by performing initial tests that reduce the number of intersections that must be calculated.

1. Every line endpoint is assigned a four digit binary code, called region code, that identifies the location of the point relative to the boundaries of the clipping rectangle.

2. Each bit position in the region code is used to indicate one of the four relative coordinate positions of the point with respect to the clip window.

Bit 1: left

Bit 2: right

Bit 3: below

Bit 4: above

3. Bit values in the region code are determined by comparing endpoint coordinates values (x, y) with respect to the clip boundaries. eg.Bit 1 is set to 1 if x ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download