521493s computer graphics
play

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


  1. 521493S Computer Graphics Exercise 4

  2. 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 dimensional coordinates.

  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.

  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.

  5. Question 4.2 Prove that clipping a convex object against another convex object result in at most one convex object.

  6. Solution 4.2 (1/2)

  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.

  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?

  9. Solution 4.3 (1/1) • Although each pixel uses five rays, the total number of rays has only doubled, i.e. consider a second grid that is offset one half pixel in both the x and y directions:

  10. 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?

  11. Solution 4.4 (1/1) • 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), the 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 the jittered image is a noisy (degraded) version of the original but in a visual sense it appears better.

  12. Instead of jittering: Dithering Original Thresholded Floyd-Steinberg -dithering

  13. Question 4.5 Draw a one pixel wide line using Bresenham’s algorithm from (10, 3) to (6, 8).

  14. 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 stepping in y 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.

  15. 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.

  16. 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

  17. Solution 4.5 (4/10) • Lets draw the first point – d = 3, p = (10, 6)

  18. Solution 4.5 (5/10) • d = 3 > 0 => Going NE – d = d – 2 = 1, p = p + ∆NE = (9, 4)

  19. Solution 4.5 (6/10) • d = 1 > 0 => Going NE – d = d – 2 = – 1, p = p + ∆NE = (8, 5)

  20. Solution 4.5 (7/10) • d = – 1 <= 0 => Going E – d = d + 8 = 7, p = p + ∆E = (8, 6)

  21. Solution 4.5 (8/10) • d = 7 > 0 => Going NE – d = d – 2 = 5, p = p + ∆NE = (7, 7)

  22. Solution 4.5 (9/10) • d = 5 > 0 => Going NE – d = d – 2 = 3, p = p + ∆NE = (6, 8)

  23. Solution 4.5 (10/10) • At finish point. Stop drawing.

  24. 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).

  25. 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 it crosses polygon borders.

  26. 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).

  27. 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).

  28. 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)

  29. 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 would be outside.

Recommend


More recommend