Download presentation
Presentation is loading. Please wait.
Published byRegina Cummings Modified over 9 years ago
1
1 CPE 333 : Computer Graphics มหาวิทยาลัยเทคโนโลยีพระจอม เกล้าธนบุรี Dr. Natasha Dejdumrong
2
2 Course Description Line Drawing Circle Drawing [ Ellipse Drawing ] 2D and 3D Transformations Line and Polygon Clipping techniques 3D Viewing Geometric Modeling: Representation of Curves and Surfaces, Solid Modeling Hidden Surface Removal Algorithms Illumination and Shading models Ray tracing
3
3 Text Book and Supplements Textbook – Hearn Baker, Computer Graphics with OpenGL, 3rd Ed., Pearson International Edition, 2004. Lecture Note Powerpoints
4
4 Schedule Classroom: CB40805 Lecture Time:Monday 13:30 – 15:20 [AB] Tuesday 14:30 – 16:20 [CD] Lab Time:Monday 14:30 – 16:20 [AB] Tuesday 16:30 – 17:20 [CD]
5
5 Active Learning Lecture: 2 Hours Laboratory: 2 Hours Teaching Assistant: Pitchaya Jamjun
6
6 Marking Midterm Examination 20% Final Examination 30% Assignments 40% Class + Lab Attendance 10% Total100%
7
7 Grading Policy 80 or aboveA 75-79B+ 70-74B 65-69C+ 60-64C 55-59D+ 50-54D under 50F
8
8 Chapter 2 Scan Conversion
9
9 Overview Point Line Circle Ellipse
10
10 Raster Graphics A raster graphics image, digital image, or bitmap, is a data file or structure representing a generally rectangular grid of pixels, or points of color, on a computer monitor, paper, or other display device.
11
11 Vector Graphics Vector graphics (also called Geometric Modeling or Object-Oriented Graphics) is the use of geometrical primitives such as points, lines, curves, and polygons, which are all based upon mathematical equations to represent images in computer graphics. It is used by contrast to the term raster graphics, which is the representation of images as a collection of pixels (dots). Raster graphics are distinguished from vector graphics in that vector graphics represent an image through the use of geometric objects such as curves and polygons.
12
12 Raster vs Vector Graphics Raster graphics cannot be scaled to a higher resolution without loss of apparent quality. This is in contrast to vector graphics, which easily scale to the quality of the device on which they are rendered.vector graphics Raster graphics are more practical than vector graphics for photographs and photo-realistic images, while vector graphics are often more practical for typesetting or graphic design.
13
13 RGB The color of each pixel is individually defined; images in the RGB color space, for instance, often consist of colored pixels defined by three bytes—one byte each for red, green and blue. Less colorful images require less information per pixel; an image with only black and white pixels requires only a single bit for each pixel. A colored raster image (or pixmap) will usually have pixels with between one and eight bits for each of the red, green, and blue components.
14
14 Resolution The quality of a raster image is determined by the total number of pixels ( resolution ), and the amount of information in each pixel (often called color depth ). color depth For example, an image that stores 24 bits of color information per pixel can represent smoother degrees of shading than one that only stores 16 bits per pixel, but not as smooth as one that stores 48 bits. Likewise, an image sampled at 640 x 480 pixels (therefore containing 307,200 pixels) will look rough and blocky compared to one sampled at 1280 x 1024 (1,310,720 pixels). Because it takes a large amount of data to store a high- quality image.
15
15 Point Real World A point has no dimension. Practical Representation A point has size. Analytic Geometry A point P = (x, y) [For 2 Dimension] A point P = (x, y, z) [For 3 Dimension]
16
16 Raster Graphics Pixels Example Point(4.3, 5.3) = Pixel(4, 5) Point(3.8, 4.8) = Pixel(4, 5)
17
Straight Line (x 2,y 2 ) (x 1,y 1 ) y = m x +b y x b
18
18 Equation : y = m x + b b : y-interceptm : dy/dx F(x, y) : Ax + By +C = 0 F(x, y) : dy x - dx y + b dx = 0 Therefore, A = dy, B = -dx, C = b dx Straight Line
19
Bresenham’s Line Algorithm
20
Midpoint Line Algorithm
21
Suppose that point (x i, y i ) has been plotted. We move x i to x i + 1. The problem is how to select between two pixels, U (x i + 1, y i + 1) and D (x i + 1, y i ). For this purpose, we consider the middle pixel M (x i + 1, y i + 1/2). d = F(M) = a (x i + 1) + b( y i + 1/2) + c IFd > 0,choose U d < 0,choose D d = 0,choose either U or D, so choose U.
22
When D is chosen, M is incremented one step in the x direction. So d new =F (x i +2, y i + 1/2) =a (x i + 2) + b (y i + 1/2) + c while d old =F (x i + 1, y i + 1/2) = a (x i + 1) + b (y i + 1/2) + c So the increment in d (denoted d D ) is d D =d new - d old = a = dy
23
When U (x i + 1, y i + 1) is chosen, M is incremented one step in both directions: d new =F (x i +2, y i + 3/2) =a (x i + 2) + b( y i + 3/2) + c =d old + a + b So the increment in d (denoted d U ) is d U = a + b = dy - dx
24
First, we have the point (x 1, y 1 ). So M (x 1 + 1, y 1 + 1/2) and F(M) =a (x 1 + 1) + b (y 1 + 1/2) + c =F (x 1, y 1 ) + a + b/2 Since F (x 1, y 1 ) = 0, we have d = d 1 = dy - dx/2
25
In order to avoid a division by 2, we use 2d 1 instead. Afterward, 2d is used. So, with d used in place of 2d, we have First set d 1 = 2dy - dx IF d i >= 0 THEN x i+1 = x i + 1, y i+1 = y i + 1 and d i+1 = d i + 2 (dy-dx) IF d i < 0 THEN x i+1 = x i + 1, y i+1 = y i and d i+1 = d i + 2dy
26
26 Midpoint Line Algorithm [Scan-convert the line between (x 1, y 1 ) and (x 2, y 2 )] dx = x 2 - x 1 ; dy = y 2 - y 1 ; d = 2 * dy - dx;/* initial value of d */ dD = 2 * dy;/* increment used to move D */ dU = 2 * (dy-dx);/* increment used to move U */ x = x 1 ; y = y 1 ; Plot(x,y);/* the first pixel */ While (x < x 2 ) if d < 0 then d = d + dD;/ * choose D */ x = x + 1; else d = d + dU;/* choose U */ x = x + 1; y = y + 1; endif Plot(x,y);/* the selected pixel closest to the line */ EndWhile Midpoint Line Algorithm
27
Since for the points, x < y, consequently the algorithm can apply. Here dy = 11 - 8 = 3, dx = 9-5 = 4 First d 1 = 2dy - dx = 6 - 4 = 2 > 0Select U So the new point is (6, 9) and d 2 = d 1 + 2 (dy - dx) = 2 + 2(-1) = 0Select U The chosen pixel is (7, 10) and d 3 = d 2 + 2 (dy - dx) = 0 +2(-1) = -2 < 0 Select D The chosen pixel is (8, 10) then d 4 = d 3 + 2dy = - 1 + 6 = 5 > 0Select U The chosen pixel is (9, 11). Example. Scan-convert the line between (5, 8) and (9, 11). Example
28
28 Bresenham’s Line Algorithm can work only with the line segment with slope m from 0 to 1. (45 o ) y x Remarks
29
29 Bresenham’s Line Algorithm can work only with the line segment with slope m from 0 to 1. (45 o ) Remarks
30
30 Bresenham’s Line Algorithm can work only with the line segment with slope m from 0 to 1. (45 o ) Remarks
31
31 x 2 + y 2 = r 2 F ( x,y ) = x 2 + y 2 - r 2 F ( x,y ) = (x - x c ) 2 + (y - y c ) 2 - r 2 x = r cos(theta) y = r sin(theta) Circle
32
32 F ( x,y ) = (x - x c ) 2 + (y - y c ) 2 - r 2 IF F ( x,y ) = 0 : Point ( x,y ) is on the circle. IF F ( x,y ) < 0 : Point ( x,y ) is inside the circle. IF F ( x,y ) > 0 : Point ( x,y ) is outside the circle. F ( x,y ) < 0 F ( x,y ) > 0 Circle
33
33 Midpoint Circle Algorithm
34
34 P 1 = ( x, y ) P 5 = (- y, -x ) P 2 = ( y, x ) P 6 = (- y, -x ) P 3 = (- y, x ) P 7 = ( y, -x ) P 4 = (- x, y ) P 8 = ( x, - y ) Eight-Way Symmetry
35
35 d = F(M) = F(x i, y i ) = x i 2 + y i 2 - r 2 IFd < 0,choose U d > 0,choose D d = 0,choose either U or D, so choose U. Midpoint Algorithm
36
Let d old = F(x i +1, y i - 1/2) = (x i + 1) 2 + (y i - 1/2) 2 - r 2 If d old < 0, then U (x i+1, y i ) is chosen and the next midpoint will be one increment over x. Thus d new = F(x i +2, y i - 1/2) = d old + 2x i + 3 The increment in d is d U = d new - d old = 2x i + 3
37
IF d old >= 0, M is outside the circle and D is chosen. The new midpoint will be one increment over x and one increment down in y: d new = F (x i + 2, y i - 3/2) = d old + 2x i - 2y i + 5 The increment in d is therefore d D = d new - d old = 2(x i - y i ) + 5
38
Initial point : (0, r). The next midpoint lies at (1, r- 1/2) and so F (1, r- 1/2) = 1 + (r- 1/2) 2 - r 2 = 5/4 - r To avoid the fractional initialization of d, we take h = d - 1/4. So the initials value of h is 1-r and the comparison d < 0 becomes h < -1/4. However, since h starts out with an integer value and is incremented with integer values ( d U and d D ), we can change the comparison to h < 0.
39
39 h = 1-r; /* initialization */ x = 0; y = r; Plot(x,y); While y > x if h < 0 then/* Select U */ dU = 2*x + 3; h = h + dU; x = x + 1; else/* Select D */ dD = 2*(x-y) + 5; h = h + dD; x = x + 1; y = y - 1; endif Plot(x,y); EndWhile Midpoint Circle Algorithm
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.