Drawing Algorithms
CS4815 1
B. Bartlett, M. Santos (CRIS)
Computer Graphics
B. Bartlett, M.
Santos
D2-037
Main Building.
ben.bartlett@ul.ie
matheus.santos@ul.ie
Spring 2025
Computer Graphics
Drawing Algorithms
CS4815 2
B. Bartlett, M. Santos (CRIS)
Examples - DDA
L1 = p(0,0) ; q(2,10)
L2 = p(10,7) ; q(2,4)
----------------------------
|
𝑚
| ≤ 1
|
𝑚
|> 1
Drawing Algorithms
CS4815 3
B. Bartlett, M. Santos (CRIS)
Which pixels?
L1: (0,0) (2,10)
Sampling in
0
0
1
2
1 2 3 4
3
4
5
6
7
8
9
10
𝑚 =
10
2
=5
0 0 0
1 1 5
2 2 10
𝑦 𝑘+1= 𝑦 𝑘 +m
Drawing Algorithms
CS4815 4
B. Bartlett, M. Santos (CRIS)
Which pixels?
L1: (0,0) (2,10)
Sampling in
0
0
1
2
1 2 3 4
3
4
5
6
7
8
9
10
𝑚 =
10
2
=5
0 0 0
1 0.2 1
2 0.4 2
3 0.6 3
4 0.8 4
5 1 5
6 1.2 6
7 1.4 7
8 1.6 8
9 1.8 9
10 2 10
𝑥𝑘+1= 𝑥𝑘 +
1
𝑚
|𝑚|>1
Drawing Algorithms
CS4815 5
B. Bartlett, M. Santos (CRIS)
Which pixels?
L2: (10,7) (2,4)
Sampling in
0
2
1
2
3 4 5 6
3
4
5
6
7
8
9
10
𝑚 =
3
8
0 2 4
1 3 4.375
2 4 4.75
3 5 5.125
4 6 5.5
5 7 5.875
6 8 6.25
7 9 6.625
8 10 7
𝑦 𝑘+1= 𝑦𝑘 +𝑚|𝑚|≤1
7 8 9 10
Drawing Algorithms
CS4815 6
B. Bartlett, M. Santos (CRIS)
Examples - Bresenham’s
L1 = p(0,0) ; q(2,10)
L2 = p(10,7) ; q(2,4)
Drawing Algorithms
CS4815 7
B. Bartlett, M. Santos (CRIS)
Which pixels?
L2: (10,7) (2,4)
Sampling in
0
2
1
2
3 4 5 6
3
4
5
6
7
8
9
10
𝑚 =
3
8
0 2 4 -2
1 3 4 4
2 4 5 -6
3 5 5 0
4 6 6 -10
5 7 6 -4
6 8 6 2
7 9 7 -8
8 10 7
7 8 9 10
Sampling in
Positive Slope
Drawing Algorithms
CS4815 8
B. Bartlett, M. Santos (CRIS)
Examples - Bresenham’s
L3 = p(-4,7) ; q(-2,-4)
L4 = p(5,2) ; q(11,4)
L5 = p(6,12) ; q(14,5)
Drawing Algorithms
CS4815 9
B. Bartlett, M. Santos (CRIS)
Which pixels?
L5: (6,12) (14,5)
Sampling in
2
6
3
4
7 8 9 10
5
6
7
8
9
10
11
12
𝑚=−
7
8
*
0 6 -12 6
1 7 -11 4
2 8 -10 2
3 9 -9 0
4 10 -8 -2
5 11 -8 12
6 12 -7 10
7 13 -6 8
8 14 -5
11 12 13 14
Sampling in
Negative Slope
Swap sign for calculations
L5: (6,-12) (14,-5)
(*) real value is equal to -*
Drawing Algorithms
CS4815 10
B. Bartlett, M. Santos (CRIS)
Which pixels?
L3: (-4,7) (-2,-4)
-3
-1
-2
-1
0 1 2 3
0
1
2
3
4
5
6
7
𝑚=−
11
2
* **
0 -4 2 -7
1 -3 2 -3
2 -2 2 1
3 -1 3 -17
4 0 3 -13
5 1 3 -9
6 2 3 -5
7 3 3 -1
8 4 3 3
9 5 4 -15
10 6 4 -11
11 7 4
4 5 6 7
Sampling in
Swap for calculations
L3: (7,-4) (-4,-2)
Since (-4 < 7), rearrange:
L3: (-4,-2)(7,-4)
Negative Slope
Swap sign for calculations
L3: (-4,2) (7,4)
(*) true value is equal to -**
(**) true value is equal to *
-2
-3
-4
-4

Sample of Drawing Line Algorithms - SOL.pptx

  • 1.
    Drawing Algorithms CS4815 1 B.Bartlett, M. Santos (CRIS) Computer Graphics B. Bartlett, M. Santos D2-037 Main Building. ben.bartlett@ul.ie matheus.santos@ul.ie Spring 2025 Computer Graphics
  • 2.
    Drawing Algorithms CS4815 2 B.Bartlett, M. Santos (CRIS) Examples - DDA L1 = p(0,0) ; q(2,10) L2 = p(10,7) ; q(2,4) ---------------------------- | 𝑚 | ≤ 1 | 𝑚 |> 1
  • 3.
    Drawing Algorithms CS4815 3 B.Bartlett, M. Santos (CRIS) Which pixels? L1: (0,0) (2,10) Sampling in 0 0 1 2 1 2 3 4 3 4 5 6 7 8 9 10 𝑚 = 10 2 =5 0 0 0 1 1 5 2 2 10 𝑦 𝑘+1= 𝑦 𝑘 +m
  • 4.
    Drawing Algorithms CS4815 4 B.Bartlett, M. Santos (CRIS) Which pixels? L1: (0,0) (2,10) Sampling in 0 0 1 2 1 2 3 4 3 4 5 6 7 8 9 10 𝑚 = 10 2 =5 0 0 0 1 0.2 1 2 0.4 2 3 0.6 3 4 0.8 4 5 1 5 6 1.2 6 7 1.4 7 8 1.6 8 9 1.8 9 10 2 10 𝑥𝑘+1= 𝑥𝑘 + 1 𝑚 |𝑚|>1
  • 5.
    Drawing Algorithms CS4815 5 B.Bartlett, M. Santos (CRIS) Which pixels? L2: (10,7) (2,4) Sampling in 0 2 1 2 3 4 5 6 3 4 5 6 7 8 9 10 𝑚 = 3 8 0 2 4 1 3 4.375 2 4 4.75 3 5 5.125 4 6 5.5 5 7 5.875 6 8 6.25 7 9 6.625 8 10 7 𝑦 𝑘+1= 𝑦𝑘 +𝑚|𝑚|≤1 7 8 9 10
  • 6.
    Drawing Algorithms CS4815 6 B.Bartlett, M. Santos (CRIS) Examples - Bresenham’s L1 = p(0,0) ; q(2,10) L2 = p(10,7) ; q(2,4)
  • 7.
    Drawing Algorithms CS4815 7 B.Bartlett, M. Santos (CRIS) Which pixels? L2: (10,7) (2,4) Sampling in 0 2 1 2 3 4 5 6 3 4 5 6 7 8 9 10 𝑚 = 3 8 0 2 4 -2 1 3 4 4 2 4 5 -6 3 5 5 0 4 6 6 -10 5 7 6 -4 6 8 6 2 7 9 7 -8 8 10 7 7 8 9 10 Sampling in Positive Slope
  • 8.
    Drawing Algorithms CS4815 8 B.Bartlett, M. Santos (CRIS) Examples - Bresenham’s L3 = p(-4,7) ; q(-2,-4) L4 = p(5,2) ; q(11,4) L5 = p(6,12) ; q(14,5)
  • 9.
    Drawing Algorithms CS4815 9 B.Bartlett, M. Santos (CRIS) Which pixels? L5: (6,12) (14,5) Sampling in 2 6 3 4 7 8 9 10 5 6 7 8 9 10 11 12 𝑚=− 7 8 * 0 6 -12 6 1 7 -11 4 2 8 -10 2 3 9 -9 0 4 10 -8 -2 5 11 -8 12 6 12 -7 10 7 13 -6 8 8 14 -5 11 12 13 14 Sampling in Negative Slope Swap sign for calculations L5: (6,-12) (14,-5) (*) real value is equal to -*
  • 10.
    Drawing Algorithms CS4815 10 B.Bartlett, M. Santos (CRIS) Which pixels? L3: (-4,7) (-2,-4) -3 -1 -2 -1 0 1 2 3 0 1 2 3 4 5 6 7 𝑚=− 11 2 * ** 0 -4 2 -7 1 -3 2 -3 2 -2 2 1 3 -1 3 -17 4 0 3 -13 5 1 3 -9 6 2 3 -5 7 3 3 -1 8 4 3 3 9 5 4 -15 10 6 4 -11 11 7 4 4 5 6 7 Sampling in Swap for calculations L3: (7,-4) (-4,-2) Since (-4 < 7), rearrange: L3: (-4,-2)(7,-4) Negative Slope Swap sign for calculations L3: (-4,2) (7,4) (*) true value is equal to -** (**) true value is equal to * -2 -3 -4 -4