SLIDE 1
521493S Computer Graphics Exercise 4 Question 4.1 Consider two - - PowerPoint PPT Presentation
521493S Computer Graphics Exercise 4 Question 4.1 Consider two - - PowerPoint PPT Presentation
521493S Computer Graphics Exercise 4 Question 4.1 Consider two line segments represented in parametric form: Find a procedure for determining whether the segments intersect, and, if they do, for finding the point of intersection. Assume three
SLIDE 2
SLIDE 3
Solution 4.1 (1/2)
- Consider the problem in two dimensions first
- We are looking for and so that
- Two equations and two unknowns and , as
long as the line segments are not parallel, can be solved.
- If both these values are between 0 and 1, the
segments intersect.
SLIDE 4
Solution 4.1 (2/2)
- For three dimensions we can first solve the
equations in x and y dimensions.
- Then we assign calculated and values to
the line equations and solve z values for both lines.
- If z values are the same (within numerical
accuracy), the lines intersect.
SLIDE 5
Question 4.2
Prove that clipping a convex object against another convex object result in at most one convex object.
SLIDE 6
Solution 4.2 (1/2)
SLIDE 7
Solution 4.2 (2/2)
- Any two points in the intersection area are
inside both convex objects.
- Therefore it’s possible to create a line segment
between any two points within that area without going outside the area.
- Above is the definition of convex area.
SLIDE 8
Question 4.3
A standard anti-aliasing technique used in ray tracing is to cast rays not only through the center of each pixel, but also through the pixel’s four corners. What is the increase in work compared to casting a single ray through the center?
SLIDE 9
Solution 4.3 (1/2)
- Number of non-antialiased rays is w × h (red)
- Extra rays needed are the white circles and are
shared with neighbouring rays
SLIDE 10
Solution 4.3 (2/2)
- The exact number is of rays is 2 × (w × h) + w +
h + 1
SLIDE 11
Question 4.4
- Images produced on displays that support only a
few colors or gray levels tend to show contour effects because the viewer can detect the differences between adjacent shades. One technique for avoiding this visual effect is to add a little noise (jitter) to the pixel values.
– Why does this technique work? – How much noise should you add? – Does it make sense to conclude that the degraded image created by the addition of noise is of quality higher than the original image?
SLIDE 12
Solution 4.4 (1/2)
64 shades, Closest color 16 shades, Closest color 4 shades, Closest color Black & White, Closest color 64 shades, 3% Noise 16 shades, 12% noise 4 shades, 25% noise Black & White, 50% noise 64 shades, Floyd-Steinberg 16 shades, Floyd-Steinberg 4 shades, Floyd-Steinberg Black & White, Floyd-Steinberg
SLIDE 13
Solution 4.4 (2/2)
- If there are very few levels, we cannot display a gradual
change in brightness. Instead the viewer will see steps of intensity.
- A simple rule of thumb is that we need enough gray levels
so that a change of one step is not visible.
- We can mitigate the problem by adding one bit of random
noise to the least significant bit of a pixel. Thus if we have 3 bits (8 levels), third bit will be noise.
- The effect of the noise will be to break up regions of almost
constant intensity so the user will not be able to see a step because it will be masked by the noise. In a statistical sense jittered image is a noisy (degraded) version of the original but in a visual sense it appears better.
SLIDE 14
Instead of jittering: Dithering
Original Jittered Floyd-Steinberg -dithering
SLIDE 15
Question 4.5
Draw a one pixel wide line using Bresenham’s algorithm from (10, 3) to (6, 8).
SLIDE 16
Solution 4.5 (1/10)
- We are drawing a line from (10, 3) to (6, 8).
For Bresenham’s line drawing algorithm
- Because |∆y| > |∆x| we have to be stepping
in y direction instead of x direction.
- Multiple options how varying combinations of
directions can be handled
– This approach uses E for long (|∆y|) direction and N for shorter (|∆x|) direction.
SLIDE 17
Solution 4.5 (2/10)
- So we draw the line from (10, 3) to (6, 8) and
iterate the point up or up left at each step.
SLIDE 18
Solution 4.5 (3/10)
- Lets calculate the required variables
– ∆x = 6 – 10 = – 4 – ∆y = 8 – 3 = 5
- Because |∆y| > |∆x|:
– E = |∆y| = 5 – N = |∆x| = 4 – Movement direction ∆E = (0, 1) – Movement direction ∆NE = (– 1, 1) – Decision variable d = 2 ∙ N – E = 2 ∙ 4 – 5 = 3 – incrE = 2 ∙ N = 2 ∙ 4 = 8 – incrNE = 2 ∙ (N – E) = 2 ∙ (4 – 5) = – 2
SLIDE 19
Solution 4.5 (4/10)
- Lets draw the first point
– d = 3, p = (10, 6)
SLIDE 20
Solution 4.5 (5/10)
- d = 3 > 0 => Going NE
– d = d – 2 = 1, p = p + ∆NE = (9, 4)
SLIDE 21
Solution 4.5 (6/10)
- d = 1 > 0 => Going NE
– d = d – 2 = – 1, p = p + ∆NE = (8, 5)
SLIDE 22
Solution 4.5 (7/10)
- d = – 1 <= 0 => Going E
– d = d + 8 = 7, p = p + ∆E = (8, 6)
SLIDE 23
Solution 4.5 (8/10)
- d = 7 > 0 => Going NE
– d = d – 2 = 5, p = p + ∆NE = (7, 7)
SLIDE 24
Solution 4.5 (9/10)
- d = 5 > 0 => Going NE
– d = d – 2 = 3, p = p + ∆NE = (6, 8)
SLIDE 25
Solution 4.5 (10/10)
- At finish point. Stop drawing.
SLIDE 26
Question 4.6
Check if point (3, 4) is inside concave polygon defined by vertices (1, 1), (6, 3), (4, 6), (1, 5), (2, 3), (1, 1).
SLIDE 27
Answer 4.6 (1/5)
- One way to check if a point is inside a polygon
(even a concave one) is by counting how many times a horizontal line starting from the point crosses polygon borders.
SLIDE 28
Answer 4.6 (2/5)
- Vertices (1, 1), (6, 3), (4, 6), (1, 5), (2, 3), (1, 1)
form a polygon from line segments (1, 1; 6, 3), (6, 3; 4, 6), (4, 6; 1, 5), (1, 5; 2,3), (2, 3; 1, 1).
- As we are investigating point (3, 4) using a
horizontal line, we need to check only lines that cross line y=4.
– Lines that cross this line are (6, 3; 4, 6) and (1, 5; 2, 3).
SLIDE 29
Answer 4.6 (3/5)
- Figuring where line (6, 3; 4, 6) crosses y = 4:
- Solving b:
- When y = 4:
- Crosses on the right side of point (3, 4).
SLIDE 30
Answer 4.6 (4/5)
- Similarly where line (1, 5; 2, 3) crosses y = 4:
- Solving b:
- When y = 4:
- Crosses on the left side of point (3, 4)
SLIDE 31
Answer 4.6 (5/5)
- Because there are odd number of lines on
either side of the point, the point is inside the
- polygon. If there were even number of lines, it