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

Computer Graphs 7

Uploaded by

mohanbarhate700
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)
8 views

Computer Graphs 7

Uploaded by

mohanbarhate700
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/ 9

9/29/24, 10:51 AM Computer Graphics Overview Components

ChatGPT

Algorithm Steps:
1. Input the starting point (x1 , y1 ) and the ending point (x2 , y2 ).
​ ​ ​ ​

2. Calculate the differences:

Δx = x2 − x1 ​ ​ and Δy = y2 − y1
​ ​

3. Initialize the decision variable (or error term):

Decision parameter (p) = 2Δy − Δx


4. Initialize the starting point (x1 , y1 ). ​

5. For each x-coordinate from x1 to x2 : ​ ​

Plot the current point (x, y).

If p ≥ 0, increment y by 1 (i.e., move diagonally up) and update the decision variable:

p = p + 2(Δy − Δx)
If p < 0, only increment x and update the decision variable:

p = p + 2Δy
6. Repeat until the endpoint (x2 , y2 ) is reached.
​ ​

Example: Rasterizing the Line from (5, 5) to (13, 9)


We are given the line segment with starting point A(5, 5) and ending point B(13, 9). Let's use Bresenham’s algorithm to rasterize this line.

Step 1: Calculate Δx and Δy :

Δx = x2 − x1 = 13 − 5 = 8
​ ​

Δy = y2 − y1 = 9 − 5 = 4
​ ​

Step 2: Initialize the decision parameter p:

p = 2Δy − Δx = 2(4) − 8 = 8 − 8 = 0

Step 3: Initialize the starting point (x1 , y1 ) ​ ​ = (5, 5).

Step 4: Iterate through the x-values from x1 to x2 : ​ ​

The initial point is (5, 5). For each step, we will update the decision parameter p and determine whether to increment y or just x.

Let's go step-by-step:

Step x y p (Decision Parameter) Plotted Pixel

0 5 5 0 (5, 5)

1 6 5 p=0+2×4=8 (6, 5)

2 7 6 p=8−2×8=0 (7, 6)

3 8 6 p=0+2×4=8 (8, 6)

4 9 7 p=8−2×8=0 (9, 7)

5 10 7 p=0+2×4=8 (10, 7)

6 11 8 p=8−2×8=0 (11, 8)

7 12 8 p=0+2×4=8 (12, 8)

8 13 9 p=8−2×8=0 (13, 9)

Final Rasterized Line:


The pixels plotted to form the line from (5, 5) to (13, 9) are:

(5, 5), (6, 5), (7, 6), (8, 6), (9, 7), (10, 7), (11, 8), (12, 8), (13, 9).

Explanation of the Process:


Starting from (5, 5), the algorithm steps through the x-values from 5 to 13.

The decision parameter p starts at 0. Each time p is recalculated, it determines whether to increment y (when p ≥ 0) or just move horizontally (increment x).
When p ≥ 0, we move both horizontally and vertically (diagonal step).
When p < 0, we move horizontally only (straight step).

Conclusion:
Bresenham’s line drawing algorithm efficiently rasterizes a line by using only integer arithmetic, avoiding the rounding errors associated with floating-point operations. It tracks the error as the line is drawn and ensures that the plotted
pixels closely follow the theoretical line. In this example, the line from (5, 5) to (13, 9) is rasterized with 9 pixels, ensuring smooth progression from the start to the endpoint.

Message ChatGPT

ChatGPT can make mistakes. Check important info.

https://chatgpt.com/c/66f8da70-8768-8005-bc69-981adbdaf93b 1/9
9/29/24, 10:51 AM Computer Graphics Overview Components

https://chatgpt.com/c/66f8da70-8768-8005-bc69-981adbdaf93b 2/9
9/29/24, 10:51 AM Computer Graphics Overview Components

https://chatgpt.com/c/66f8da70-8768-8005-bc69-981adbdaf93b 3/9
9/29/24, 10:51 AM Computer Graphics Overview Components

https://chatgpt.com/c/66f8da70-8768-8005-bc69-981adbdaf93b 4/9
9/29/24, 10:51 AM Computer Graphics Overview Components

https://chatgpt.com/c/66f8da70-8768-8005-bc69-981adbdaf93b 5/9
9/29/24, 10:51 AM Computer Graphics Overview Components

https://chatgpt.com/c/66f8da70-8768-8005-bc69-981adbdaf93b 6/9
9/29/24, 10:51 AM Computer Graphics Overview Components

https://chatgpt.com/c/66f8da70-8768-8005-bc69-981adbdaf93b 7/9
9/29/24, 10:51 AM Computer Graphics Overview Components

https://chatgpt.com/c/66f8da70-8768-8005-bc69-981adbdaf93b 8/9
9/29/24, 10:51 AM Computer Graphics Overview Components

https://chatgpt.com/c/66f8da70-8768-8005-bc69-981adbdaf93b 9/9

You might also like