03 - Line Rasterization
03 - Line Rasterization
Line Rasterization
Computer Graphics
Winter Term 2019/20
• Triangle primitive:
• Line primitive:
• Lines:
• very widely used in CAD (computer aided design) → wireframe models
autodesk.com
autodesk.com
• A polygon is defined by an ordered set of
points (for now in 2D)
𝑝𝑝1
𝑝𝑝2
𝑝𝑝5
𝑝𝑝3
𝑝𝑝4
autodesk.com
• Every polygon can be split into triangles
𝑝𝑝1
= Triangulation
𝑝𝑝2
𝑝𝑝5
𝑝𝑝3
Computer Graphics 2019/20 - Line Rasterization
𝑝𝑝4 4
Rasterization
• This lecture: Rasterization of lines (+ circles)
• Next Lecture: Rasterization of filled objects (Triangles, Polygons)
(𝑥𝑥1, 𝑦𝑦1)
(𝑥𝑥0 , 𝑦𝑦0 )
• → differentiate cases
(𝑥𝑥1, 𝑦𝑦1)
(𝑥𝑥0, 𝑦𝑦0)
for int x = x0 to x1
float y = y0 + m(x – x0)
setPixel (x, round(y))
• Midpoint decider
→ look at midpoint between E and NE pixel E
• if line below midpoint GO EAST
(𝑥𝑥 + 1, 𝑦𝑦 + 0.5)
current
• otherwise, GO NORTH-EAST NE
(𝑥𝑥, 𝑦𝑦)
• Analog, if 𝑑𝑑 > 0
→ E: 𝑥𝑥0 , 𝑦𝑦0 → (𝑥𝑥0 + 1, 𝑦𝑦0 )
1
• Next test will be at 𝑥𝑥0 + 2, 𝑦𝑦0 +
2
1 1
• 𝐹𝐹 𝑥𝑥0 + 2, 𝑦𝑦0 + = ⋯ = 𝐹𝐹 𝑥𝑥0 + 1, 𝑦𝑦 + + (𝑦𝑦0 − 𝑦𝑦1 )
2 2
𝐿𝐿
Δ𝑦𝑦
𝛼𝛼
Δx
1
→ on grey scale screen: modify intensity by 2 cos 𝛼𝛼
• Eight-fold symmetry
• 1st octant: 0 ≤ 𝑦𝑦 < 𝑥𝑥
• 2nd octant: 0 <= 𝑥𝑥 < 𝑦𝑦
• 3rd octant: 0 <= −𝑥𝑥 < 𝑦𝑦
• 4th octant: 0 <= 𝑦𝑦 < −𝑥𝑥
• 5th octant: 0 <= −𝑦𝑦 < −𝑥𝑥
• 6th octant: 0 <= −𝑥𝑥 < −𝑦𝑦
• 7th octant: 0 <= 𝑥𝑥 < −𝑦𝑦
• 8th octant: 0 <= −𝑦𝑦 < 𝑥𝑥