0% found this document useful (0 votes)
6 views

Algorithm Cheat

Algorithm

Uploaded by

preeyathapa827
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Algorithm Cheat

Algorithm

Uploaded by

preeyathapa827
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

DDA (line drawing)stands for Digital 2.

Check Current Pixel: If the current pixel is


Differential Analyzer. It is an incremental Cohen Sutherland Algorithm is a line clipping not the boundary color or already filled,
method of scan conversion of line. In this algorithm that cuts lines to portions which are proceed to the next step.
method calculation is performed at each within a rectangular area. It eliminates the 3.Color Current Pixel: Change the color of the
lines from a given set of lines and rectangle current pixel to the fill color.
step but by using results of previous steps.
area of interest (view port) which belongs 4.Recursively Check Neighboring Pixels:
1. Calculate the change in x-coordinate (∆x)
outside the area of interest and clip those Check and apply the following steps for each
and y-coordinate (∆y) between the endpoints.
lines which are partially inside the area of pixel:
2. Determine the number of steps required for
interest. >Check the pixel to the left
drawing the line (which is maximum of ∆x and
Define region codes for both endpoints of the >Check the pixel to the right
∆y).
line segment. > Check the pixel above
3. Calculate the incremental change in x
2. Check if both endpoints lie inside the > Check the pixel below
(∆x_inc) and y (∆y_inc) for each step.
window (region code is 0000). 5.Repeat Until Filling is Complete: Continue
4. Start from the initial point and at each
3. If yes, accept the line segment. this process for each checked pixel until the
step, increment the coordinates by (∆x_inc,
4. If no, check if both endpoints lie outside entire area is filled with the desired color
∆y_inc) until the final point is reached.
Bresenham's(line drawing) algorithm works by
the window (bitwise AND of region codes is The flood fill algorithm has many
incrementally plotting points along the line
not 0000). characters similar to boundary fill. But this
5. If yes, reject the line segment. method is more suitable for filling multiple
path between two endpoints, selecting the
6. If no, compute intersection points of the colors boundary. When boundary is of
closest pixel to the ideal line path. It ensures
line with the clipping window.
that the line drawn is as close as possible to many colors and interior is to be filled with
7. Replace the outside endpoint with the
the ideal line while maintaining consistency in one color we use this algorithm.
intersection point.
slope. 1.Select Starting Point: Choose a starting pixel
8. Repeat steps 1-7 until the line segment is
1. Input two endpoints (x0, y0) and (x1, y1). within the region to be filled with a specified
either completely inside or outside the
2. Calculate the differences between the two color .
window
endpoints: dx = x1 - x0 and dy = y1 - y0. 2. Change Starting Pixel Color: Set the color of
The Sutherland-Hodgman algorithm is a
3. Calculate the decision parameter d as 2 * the starting pixel to the desired fill color .
computational algorithm used for polygon
dy - dx. 3.Check Neighboring Pixels: Examine the
clipping, which is the process of determining
4. For each x from x0 to x1: neighboring pixels of the starting pixel. For
the visible portion of a polygon in relation to a
• Plot the pixel at (x, y). each neighbor, check if it's within the image
clipping window (another polygon). The
• If d >= 0, increment y by 1 and update d as d bounds and has the same color as the starting
algorithm was proposed by Ivan Sutherland
+ 2 * dy - 2 * dx. pixel's original color .
and Gary Hodgman in 1974
• Otherwise, update d as d + 2 * dy. 4. Color Neighboring Pixels: If a neighboring
1. Initialize:
The mid-point circle drawing algorithm pixel meets the criteria (same color as the
• Input the polygon vertices in
is an algorithm used to determine the starting pixel's original color and within image
counterclockwise order.
points needed for rasterizing a circle. • Input the clipping window vertices in
bounds), color it with the new fill color .
Step 1: Start. 5.Repeat Step 4: Recursively or iteratively
counterclockwise order.
continue examining and coloring the
Step 2: Declare x, y, r, xc , yc , P as variables, 2. Clip against each edge of the clipping
neighboring pixels of the newly filled pixels
where (xc , yc) are coordinates of the window:
until all pixels within the enclosed area with
center. • For each edge of the clipping window, clip
the original color have been filled with the
Step 3: Put x = 0 and y = r the polygon.
new color
Step 4: Repeat the steps while x ≤ y; 3. Clip against a single edge:
• For each edge of the polygon, clip it against (Z-Buffer)it is also called a Depth Buffer
Step 5: Plot (x, y). Algorithm. Depth buffer algorithm is
a single edge of the clipping window.
Step 6: if (P < 0):
4. Output the resulting clipped polygon. simplest image space algorithm. For
Set P = P + 2x + 3
else if (P >= 0):
Window view port mapping is draw by the each pixel on the display screen, we
graphics function using rectangle and line
Set P = P + 2(x-y) + 5 function. There rectangle and line has four
keep a record of the depth of an
y=y- 1 argument there are declare as the Float data object within the pixel that lies
Step 7: Do x = x + 1 variable. closest to the observer. In addition to
Step 8: End 1.Define the window in world depth, we also record the intensity
The Mid-point Ellipse drawing algorithm is
based on the parametric form of the ellipse
coordinates (xwmin, ywmin) to (xwmax, that should be displayed to show the
ywmax) object.
equation. It utilizes the concept of decision
parameters to determine the appropriate pixels 2.Define the viewport in screen 1.Initialize the depth buffer with the
to plot when drawing the ellipse. coordinates (xvmin, yvmin) to (xvmax, maximum depth value for each pixel .
1. Initialize the ellipse parameters: major axis yvmax) 2. Initialize the color buffer with the
(a), minor axis (b), center coordinates (xc, yc). 3.Calculate the scaling factors for x and
2. Calculate decision parameter for region 1:
background color for each pixel .
y coordinates: Sx = (xvmax - xvmin) / 3.Process each polygon one at a time .
P1 = b^2 - a^2 * b + 0.25 * a^2.
(xwmax - xwmin) Sy = (yvmax - yvmin) / 4. For each projected pixel position of
3. Set initial values for coordinates: x = 0, y =
b. (ywmax - ywmin) the polygon, calculate the depth z .
4. While (a^2 * (y - 0.5)) > (b^2 * (x + 1)): • If 4.For a point (xw, yw) in the window, 5. Compare the calculated depth z with
P1 < 0, update P1 and increment x by 1. • If P1 calculate its corresponding point (xv, yv) the depth value in the depth buffer at
≥ 0, update P1, decrement y by 1, and in the viewport: that pixel position .
increment x by 1. xv = xvmin + (xw - xwmin) * Sx
5. Calculate decision parameter for region 2:
6.If z is less than the depth buffer value,
yv = yvmin + (yw - ywmin) * Sy update the depth buffer with the new
P2 = b^2 * (x + 0.5)^2 + a^2 * (y - 1)^2 - a^2 * The Boundary Fill Algorithm is a fundamental
b^2. depth value z .
technique in computer graphics used to fill
6. While y > 0: • If P2 > 0, update P2 and enclosed areas with a specified color. 7.Also update the color buffer with the
decrement y by 1. • If P2 ≤ 0, update P2, 1.Select Starting Point: Choose a starting point surface color at that pixel position
decrement y by 1, and increment x by 1. within the region to be filled with a specified
color.

You might also like