0% found this document useful (0 votes)
29 views21 pages

Sahilcg

Scaling Algorithm: 1. Initialize a graphical canvas or window for visualization. 2. Define the properties of the geometric objects, such as coordinates, width, height. 3. Set scaling factors (sx, sy) that determine how much the objects will be scaled. 4. Calculate new coordinates for each object by multiplying the original coordinates by the scaling factors: xnew = xoriginal * sx ynew = yoriginal * sy 5. Draw both the original and scaled objects on the canvas using Matplotlib. 6. Display the canvas with both versions for comparison. Advantages: - Demonstrates enlarging or shrinking of objects through multiplication. - Provides experience
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views21 pages

Sahilcg

Scaling Algorithm: 1. Initialize a graphical canvas or window for visualization. 2. Define the properties of the geometric objects, such as coordinates, width, height. 3. Set scaling factors (sx, sy) that determine how much the objects will be scaled. 4. Calculate new coordinates for each object by multiplying the original coordinates by the scaling factors: xnew = xoriginal * sx ynew = yoriginal * sy 5. Draw both the original and scaled objects on the canvas using Matplotlib. 6. Display the canvas with both versions for comparison. Advantages: - Demonstrates enlarging or shrinking of objects through multiplication. - Provides experience
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

INDEX

S.no. Experiment Signature

1 Implement the Digital Differential Analyzer


algorithm by plotting the graph.

2 Write a program to implement Bresenham’s Line


Drawing
3 Implement the mid point circle algorithm by plotting
the graph.
4 Implement the midpoint Ellipse algorithm.
5 Program to implement the Circular Arc Algorithm.

6 Program to implement the Elliptical Arc Algorithm.

7 Program to implement the flood fill Algorithm.


8 Program to implement the Boundary fill Algorithm.

9 Write a program cohen-sutherland line clipping


algorithm

10 Implement the Liang barsky line clipping algorithm


by plotting the graph.

11 Program to implement the thick line


12 Program to implement the Translation of object
13 Program to implement the Rotation of object
14 Program to implement the Scaling of object
15 Program to implement the Reflection of object
16 Program to implement the Shearing of object
17 Program to implement the Polygon Drawing
algorithm
Experiment 7: Flood Fill Algorithm

Objective:
Implement the Flood Fill algorithm to fill a bounded area in a raster graphics image.

Theory:
In computer graphics, the Flood Fill algorithm is used to fill a connected area of pixels with a selected
color. It's a versatile tool for tasks such as coloring regions or creating fill patterns in 2D images.

Flood Fill Algorithm:


1. Begin:
2. Initialization: Declare variables to store the seed point (starting point) coordinates (x_seed, y_seed)
and the target fill color.
3. Input: Obtain the seed point (x_seed, y_seed) and the target fill color.
4. Create a Stack: Initialize an empty stack data structure for storing pixel coordinates.
5. Push Seed Point: Push the seed point (x_seed, y_seed) onto the stack.
6. Start Loop:
- While the stack is not empty, do the following:
1. Pop Pixel: Pop a pixel (x, y) from the stack.
2. Fill Pixel: Set the color of the pixel (x, y) to the target fill color.
3. Check Neighbors: Check the neighboring pixels in 4-connected or 8-connected fashion,
depending on the desired behavior. For each neighboring pixel (x_neighbor, y_neighbor):
- If the pixel is within the image boundaries and has the same color as the seed point, push it onto
the stack.
7. End Loop: Continue the loop until the stack is empty, indicating that the entire connected region has
been filled.
8. End:
9. Output: Display the image with the filled area.

Advantages:
• The Flood Fill algorithm is efficient for filling large connected regions with a selected color.
• It is widely used in various image editing and graphics applications.
• It's a simple and intuitive algorithm to implement.

Disadvantages:
• In some cases, the Flood Fill algorithm may not perform well with complex shapes or areas with
intricate boundaries.
• The algorithm can be sensitive to the choice of connectivity (4-connected or 8-connected), which
affects its behavior.
• It might not be suitable for filling areas with patterns or textures that have varying colors.
Code:

Output:
Experiment 8: Boundary Fill Algorithm

Objective:
Implement the Boundary Fill algorithm to fill a closed area in a raster graphics image.

Theory:
In computer graphics, the Boundary Fill algorithm is used to fill a closed area with a selected color. It
starts from a seed point and recursively fills adjacent pixels until it reaches the boundary.

Boundary Fill Algorithm:


1. Begin:
2. Initialization: Declare variables for the image, seed point (x_seed, y_seed), target color, and fill
color.
3. Input: Obtain the image, seed point (x_seed, y_seed), target color, and fill color.
4. Create a Stack: Initialize an empty stack data structure for storing pixel coordinates.
5. Push Seed Point: Push the seed point (x_seed, y_seed) onto the stack.
6. Start Loop:
• While the stack is not empty, do the following:
1. Pop Pixel: Pop a pixel (x, y) from the stack.
2. Fill Pixel: Set the color of the pixel (x, y) to the fill color.
3. Check Neighbors: Check the neighboring pixels in 4-connected or 8-connected
fashion. For each neighboring pixel (x_neighbor, y_neighbor):
• If the pixel is within the image boundaries and has the same color as the
target color, push it onto the stack.
7. End Loop: Continue the loop until the stack is empty, indicating that the closed area has been
filled.
8. End:
9. Output: Display the image with the filled closed area.

Advantages:
• The Boundary Fill algorithm is straightforward and easy to implement.
• It works well for filling complex shapes with many interior boundaries.

Disadvantages:
• It may be slow for large regions or regions with intricate boundaries.
• The recursive nature of the algorithm can lead to stack overflow errors for very large regions.
Code:

Output:
Experiment 11: Thick Line Algorithm

Objective:
Implement a program and graphical representation of thick line algorithm.

Theory:
A thick line, in computer graphics and image processing, represents a broader and more visually
prominent version of a standard thin line. Unlike a thin line, which is typically just one pixel wide, a
thick line has a variable and often greater width.

Boundary Fill Algorithm:


1. Calculate the perpendicular vector to line segment of the line you want to draw.
2. Normalize the perpendicular vector to have unit length.
3. Multiply the normalized vector by half of the desired line width to get the offset vector.
4. Draw two parallel lines with the calculated offset in opposite directions from the original line.

Advantages:
• Thick lines are more visible and easier to perceive compared to thin lines, especially when dealing
with complex or crowded visualizations.
• They can enhance the visual appeal of a drawing or visualization.
• They can enhance the visual appeal of a drawing or visualization, providing a more substantial and
bold appearance.

Disadvantages:
• Drawing thick lines requires more processing power and memory compared to thin lines, especially
when dealing with large number of lines.
Codes:

Output:
Experiment 12: Translating Transformation

Objective:
Implement a program to repeatedly translate two geometric objects (a rectangle and a circle) and
visualize the effect of multiple translations.

Theory:
Translation in computer graphics involves moving objects from one position to another. This
experiment will demonstrate the effect of repeated translations on geometric objects.

Boundary Fill Algorithm:


1. Initialize a graphical canvas or window for visualization.
2. Define the properties of the geometric objects, such as coordinates, width, height (for the
rectangle), and radius (for the circle).
3. Set a list of translation amounts for each object. Each translation is a pair of (x, y) values that
determines how far the objects will be moved.
4. Calculate new coordinates for each object after each translation by adding the translation values
to their original coordinates.
5. Draw both the original and translated objects on the canvas using Matplotlib after each
translation.
6. Display the canvas with both the original and translated objects for visualization.

Advantages:
• Demonstrates the cumulative effect of repeated translations on geometric objects.
• Provides hands-on experience with visualizing multiple translations in computer graphic

Disadvantages:
• The experiment focuses on translation, which is a fundamental concept in computer graphics.
• The objects being translated are simple, and the principles can be applied to more complex shapes.

Code:
Output:
Experiment 13: Rotation Transformation

Objective:
Write a program to implement Rotation of an object

Theory:
It is a method of altering the object's angle. Rotation may be done either clockwise or
counterclockwise. In order to rotate, we must give the rotation point and angle. A pivot point is another
name for a rotation point.

Rotation Algorithm:
1. Initialize a graphical canvas or window for visualization.
2. Define the properties of the geometric objects, such as coordinates, width, height (for the
rectangle), and radius (for the circle).
3. Set a list of rotation amounts for each object. Each rotation is a pair of (x, y) values that
determines how far the objects will be moved.
4. Calculate new coordinates for each object after each translation by adding the translation values
to their original coordinates
5. Draw both the original and translated objects on the canvas using Matplotlib after each
translation.
6. Display the canvas with both the original and translated objects for visualization.

Advantages:
• Demonstrates the cumulative effect of repeated translations on geometric objects.
• Provides hands-on experience with visualizing multiple translations in computer graphic

Disadvantages:
• The experiment focuses on rotation, which is a fundamental concept in computer graphics.
• The objects being rotated are simple, and the principles can be applied to more complex shapes.
Code:

Output:
Experiment 14: Scaling Transformation

Objective:
Write a program to implement Scaling of an object.

Theory:
A scaling transformation modifies an object's size. It either reduce or increase the object's dimension
throughout the scaling procedure. The polygon's vertex coordinates (x, y) can be scaled by multiplying
each by the scaling factors Sx and Sy to create the converted coordinates (x', y').
Consequently,
x' = x * Sx
y' = y * Sy.
The object is scaled in the X and Y directions, respectively, by the scaling factors Sx and Sy

Advantages:
• Scaling enables the adjustment of object sizes to fit within a specific region or to achieve the
desired visual effect.

Disadvantages:
• Scaling alone cannot change the shape or orientation of an object. It can only move it within the
coordinate system.

Code:
Output:
Experiment 16: Reflection Transformation

Objective:
Write a program to implement Reflection of an object

Theory:
Three kinds of Reflections are possible in 3D space:
• Reflection along the X-Y plane.
• Reflection along Y-Z plane.
• Reflection along X-Z plane.
The reflection transformation matrix for x - y axes is as follows:
Consider, a point P[x, y, z] which is in 3D space is made to reflect along X-Y direction
after reflection P[x, y, z] becomes P'[x’ ,y’ ,z’].

The reflection transformation matrix for y-z axes is as follows:


Consider, a point P[x, y, z] which is in 3D space is made to reflect along Y-Z direction,
after reflection P[x, y, z] becomes P'[x’ ,y’ ,z’].

The Reflection transformation matrix for z-x axes is as follows:


Consider, a point P[x, y, z] which is in 3D space is made to reflect along Z-X direction,
after reflection P[x, y, z] becomes P'[x’, y’, z’]

Advantages:
• Easy to implement and straightforward.
• Easy to implement.
Disadvantages:
• The experiment focuses on translation, which is a fundamental concept in computer graphics.
• The objects being translated are simple, and the principles can be applied to more complex shapes.
• Can be computationally expensive for very complex scenes.

Code:

Output:
Experiment 16: Shearing Transformation

Objective:
Write a program to implement Shearing of an object.

Theory:
Shearing deals with changing the shape and size of the 2D object along x-axis and y-axis. It is
similar to sliding the layers in one direction to change the shape of the 2D object.It is an ideal
technique to change the shape of an existing object in a two dimensional plane. In a two
dimensional plane, the object size can be changed along X direction as well as Y direction.
x-Shear :
In x shear, the y co-ordinates remain the same but the x co-ordinates changes. If P(x, y) is the
point then the new points will be P’(x’, y’) given as –
Matrix Form:

y-Shear :
In y shear, the x co-ordinates remain the same but the y co-ordinates changes. If P(x, y) is the
point then the new points will be P’(x’, y’) given as –
Matrix Form:

x-y Shear :
In x-y shear, both the x and y co-ordinates changes. If P(x, y) is the point then the new points
will be P’(x’, y’) given as –
Matrix Form:

Advantages:
• Easy to implement and straightforward.
• Easy to implement.

Disadvantages:
• The experiment focuses on translation, which is a fundamental concept in computer graphics.
• The objects being translated are simple, and the principles can be applied to more complex shapes.
• Can be computationally expensive for very complex scenes.
Code:

Output:
Experiment 17: Polygon Drawing Algorithm

Objective:
Write a program to implement Polygon Drawing Algorithm.

Theory:
polygon is a flat two-dimensional shape with straight sides that are fully closed. The sides must be
straight, not curved. However, polygons can have any number of sides.

Advantages:
• Easy to implement and straightforward.
• Easy to implement.

Disadvantages:
• The experiment focuses on translation, which is a fundamental concept in computer graphics.
• The objects being translated are simple, and the principles can be applied to more complex shapes.
• Can be computationally expensive for very complex scenes.

Code:
Output:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy