0% found this document useful (0 votes)
15 views

CGM unit 2nd

Computer graphics

Uploaded by

vermagovind434
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
15 views

CGM unit 2nd

Computer graphics

Uploaded by

vermagovind434
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 23
COMPUTER GRAPHICS MODULI Output Primitives: Line Drawing Algorithms — Loading the Frame Buffer — Line Function ~ Cirle — Generating Algorithms - Attributes of Output Primitives: Line Attributes ~ Curve Attributes — Color and Gray scale levels— Area fill Attributes — Character Attributes ~ Bundled Attributes — Inquiry Functions. Output Primitives Points and Lines Point plotting is done by converting a single coordinate position furnished by an application program into appropriate operations for the ouput device in use. (Line drawing is done by calculating intermediate positions along the line path between two specified ‘endpoint positions [The output device is then directed to fill in those positions between the end points with some color. (For some device such as a pen plotter or random sean display, a straight line can be drawn smoothly from one cend point to other. (> Digital devices display a straight line segment hy plotting discrete points between the two endpoints [Discrete coordinate positions along the line path are calculated from the equation of the line. (> Fora raster video display, the line intensity is loaded in frame buffer at the corresponding pixel positions. | Reading from the frame buffer, the videa controller then plots the screen pixels, ‘Screen locations are referenced with integer values, so plotted positions may only approximate actual line positions between two specified endpoint (> Forexample line position of (12.36, 23.87) would he converted to pixel position (12, 24). This rounding of coordinate values to integers causes lines to be displayed with a stair step appearance ("the jaggies”), as represented in fig 2.1. eee ece**® eee eee eee Fig. 2.1: - Stair step effect produced when line is generated as a series of pixel positions. [>The stair step shape is noticeable in low resolution system, and we can improve their appearance somewhat by displaying them on high resolution system. More effective techniques for smoothing raster lines are based on adjusting pixel intensities along the line paths. |. Forraster graphics device-level algorithms discuss here, object positions are specified directly in integer device coandinates. [- Pixel position will referenced according to scan following figure. number and column number which is illustrated by Dr. D.UDAYA / Assistant Professor AAGASC / Department of Computer Science / KKL COMPUTER GRAPHICS is specified in an application program, the corresponding binary value is placed in the frame buffer for each-component pixel in the output primitives to be displayed in that color, A minimum number of colors can be provided in the scheme with 3 bits of storage per pixel, as shown in Table. Each of the three bit positions is used to control the intensity level (either on or off) of the corresponding electron gun in an RGB monitor. The leftmost bit controls the red gun, the middle bit controls the green gun, and the rightmost bil controls the blue gun, Adding more bits per pixel to the frame buffer increases the number of color choices. With 6 bits per pixel, 2 hits can he used for each gun. This allows four different intensity seltings for each of the three color guns, and a total of 64 color values are available for each screen pixel. With o resolution of 1024 by 1024, a full-color (24bit per pixel) RGB system needs 3 megabytes of storage for the frame buffer. Color tables are an altemate means for providing extended color capabilities to auser without requiring large frame buffers. Lower-cost personal computer systems, in particular, often use color tables to reduce frame-buffer storage requirements. COLOR TABLES Figure 2.1 illustrates a possible scheme for storing color values in a color lookup table (or video lookup table), where frame-buffer values are now used as indices into the color table. In this example, each pixel can reference any one of the 256 table positions, and cach entry in the table uses 24 bits to specify an RGB color. For the color code 2081, 1 combination green-blue color is displayed for pixel location (x, y). Systems employing this particular lookup table would allow a user to select any 256 colors for simultaneous display from a palette of nearly 17 million colors. Compared to a full color system, this scheme reduces the number of simultaneous colors that ean be displayed, but it also reduces the frame buffer storage requirements to 1 megabyte. Some graphics systems provide 9 bits per pixel in the frame buffer, permitting a user to select 512 colors that could be used in each display. iC THE EIGHT RGB COLOR CODES FOR A THREE-BIT PER PIXEL FRAME BUFFER Stored Cotor Values in Fr Color Code RO GI Displayed Color 0 o 0 o Black 1 0 0 1 Blue 2 o 1 0 Gren 3 0 1 1 Cyan 4 1 0 0 Red $ 1 ° 1 Magenta 6 1 1 0 Yellow 7 1 1 1 White (Table 2.1, The eight color codes for a three-bit per pixel frame buffer) Dr. D. UDAYA / Assistant Professor AAGASC / Department of Computer Science / KKL COMPUTER GRAPHICS (Fig: 2:1, Color Lookup Table) There are several advantages in storing color codes in a lookup table. Use of a color table can provide a “reasonable” number of simultaneous colors without requiring large frame buffers. For most applications, 256 or 512 different colors are sufficient for a single picture. Also, table entries can be changed at any time, allowing a user to be able to experiment easily with different color combinations in a design, scene, or graph without changing the attribute settings for the graphics data structure. Similarly, visualization applications can store values for some physical quantity, such as energy, in There are several advantages in storing color codes in a lookup table. Use of a color table can provide a “reasonable” number of uultancous colors without requiring large frame buffers. For most applications, 256 or 512 different colors are sufficient for a single picture. Also, table entries can be changed at any time, allowing a user to be able to experiment easily with different color combinations in a design, scene, or graph without changing the attribute settings for the graphics data structure. Similarly, visualization applications can store vilues for some physical quantity, such as energy. in the frame buffer and use a lookup table to try out various color encodings without changing the pixel values, And in visualization and image-processing applications, color tables are a convenient means or setting color thresholds so that all pixel values above or below a specified threshold can be set to the same color. For these reasons, some systems provide both capabilities for color-code storage, so that a user can elect either to use color tables or to store color codes directly in the frame buffer. GRAYSCALE, With monitors that have no color capability, color functions can be used in an application program to set the shades of gray. or grayscale, for displayed primitives. Numeric values over the range from 0 to I can be used to specify grayscale levels, which are then converted to appropriate binary codes for storage in the raster. This allows the intensity settings to be casily adapted to systems with differing grayscale capabilities, Table lists the specifications for intensity codes for a four-level grayscale system, In this example, any imensity input value near 0.33 would be stored as the binary value O1 in the frame buffer, and pixels with this value would be displayed as dark gray. If additional bits per pixel are available in the frame buffer, the value of 0.33 would be mapped to the nearest level. With 3 bits per pixel, we can accommodate 8 gray Dr. D. UDAYA / Assistant Professor AAGASC / Department of Computer Science / KKL COMPUTER GRAPHICS levels; while 8 bits per pixel would give us 256 shades of gray. An alternative scheme for storing the intensity information is to convert each intensity code directly to the voltage value that produces this grayscale level on the output device in use. INTENSITY CODES FOR A FOUR-LEVEL GRAYSCALE SYSTEM Intensity Stored Intensity Displayed Codes Values Gray Scale In the frame Buffer (Binary Code) 00 0 (00) Black 0.33 1 (ol) Dark gray 0.67 2 ao Light gray 10 3 an White Area-Fill Attributes: Options for filling a region include a choice between a solid colour and a patterned fill. These options can be applied to polygon regions or regions with curved boundaries. Areas can be displayed with various fill styles: hollow, solid, pattern and hatch. Hollow areas are displayed using only the boundary outline, with interior colour the same as the background colour. A Solid {ill is displayed in a single colour including the borders. Fill style can also be with a specific pattern or design. The Hatch fill is used to fill area with hatching pattern. co QD Hollow Solid Pattern Polygon fill styles Diagonal hatch Diagonal __Cross-hatch Polygon fill using hatch_patier Other fill options include specifications for the edge type. edge width and edge colour. These attributes are same as the line attributes. That is, we can display polygon edges as dotted, dashed, thick or of different colours, ete. Or. D. UDAYA,/ Assistant Professor AAGASC / Department of Computer Science / KKL COMPUTER GRAPHICS Soft Fill We may want to fill area again due to 2 reasons: + tis blurred (unclear) when painted first time, or © Wis repainting of a color area that was originally filled with semitransparent brush, where current color is then mixture of the brush color and the background color “behind” the area. So that the fill color is combined with the background colors are referred to as Soft-fill. Character Attributes: The appearance of displayed characters is controlled by attributes such as font, size, colour and orientation. Attributes can be set both for entire character strings and for individual characters, known as Marker symbols. 1, Text Attributes: There are many text options available, such as font, colour, size, spacing, and orientation. % Text Style: The characters in a selected font can also be displayed in various underlining styles (solid, dotted, dashed, double), in bold, in italics, shadow style, etc. Font options can be made available as predefined sets of grid patterns or as character sets designed with lines and curve: % Text Colour: Colour settings for displayed text are stored in the system attribute list and transferred to the frame buffer by character loading functions. When a character string is displayed, the current colour is used to set pixel values in the frame buffer corresponding to the character shapes and position. % Text Size: We can adjust text size by changing the overall dimensions, i.e., width and height, of characters or by changing only the width, Character size is specified in Points, where | point is 0.013837 inch or approximately 1/72 inch. Point measurements specify the size of the Character Body. Different fonts with the same point specifications can have different character sizes depending upon the design of the font. Topline Kern wm mina seline . ~~ Descenders Bottomline character, Dr. D. UDAYA / Assistant Professor AAGASC/ Department of Computer Science / KKL COMPUTER GRAPHICS Character Body The distance between Topline and Bottomline is same for all characters in a particular size and font, but the width may be different. A smaller body width is assigned to narrow characters such as i,j, le t ¢ compared to broad characters such as W or M. The Character Height is the distance between the Baseline and Capline of cl Kerned characters, such as f and j, extend beyond the character-width limits. And letters with descenders, such as g. j. p. q. extend below the baseline. ractet The size can be changed in such away so that the width and spacing of characters is adjusted to maintain the same text proportions. For example, doubling the height also doubles the character width and the spacing between characters. Also, only the width of the character s can be changes without affecting its height. Similarly, spacing between characters can be increased without changing height or width of individual characters. The effect of different character-height setting, charact spacing ona text is shown below. r-width setting, and character HEIGHT! WIDTHI SPACING! HEIGHT2 WIDTH2 SPACING2 HEIGHT3 WIPTHs3 SPACING3 Effect of changing Height, Width and Spacing # Text Orientation: The text can be displayed at various angles, known as orientation, A procedure for orienting text rotates characters so that the sides of character bodies, from baseline to topline at aligned at some angle. Character strings can be arranged vertically or horizontally, Orientation ea ws, Se %@ ® A text orientated by 45 degrees in anticlockwise and clockwise directi * Text Path: In some applications the character strings are arranged vertically or horizontally. This is known as Text Path. Text path can be right, lefi, up or down. Dr. D. UDAYA/ Assistant Professor AAGASC / Department of Computer Science / KKL COMPUTER GRAPHICS g 8 t r t s gnirts String A text displayed with the four text-path options © o r t 5 9 * Text Alignment: Another auribute for character strings is alignment. This attribute specifies how text is to be positioned with respect to the start coordinates. Vertical alignment can be top, cap. half, base and bottom. Similarly, horizontal alignment can be left, centre and right. top TEXT ALIGNMENT ita 7 bottom | | Alignment values for a string ‘Text Attributes ] Intext we are having so many style and design like italic fonts, bold fonts ctc. _ Forsetting the font style in PHIGS package we have one function which is: setTextFont (if Where tis used to specily text font | [twill set specified font as a current character. For setting color of character in PHIGS we have function: setTextColorindes (te Where text color parameter te specifies an allowable color code. For setting the size of the text we use function, setCharacterheight (ch) [ For scaling the character we use function. Dr. D. UDAYA / Assistant Professor AAGASC/Department of Computer Science / KL COMPUTER GRAPHICS setCharacterExpansionFacter (cw) Where character width parameter ew is set to a positive real number that seale the character body width, Spacing between character is controlled by function setCharacterSpacing (es) Where character spacing parameter cs can be assigned any real value. The orientation for a displayed character string is set according to the direction of the character up vector: setCharacterUpVector (upvect) Parameter upvect in this function is assigned two values that specify the x and y vector components, Text is then displayed so that the orientation of characters from baseline to cap line is in the direction of the up vector. ©) For sctting the path of the character we use function: setTextPath (tp) CQ Where the text path parameter tp can be assigned the value: right, lefi, up, or down. CQ Ttwill set the direction in which we are writing. For setting the alignment of the text we use function. setText Alignment (h, v) Where parameter h and v control horizontal and vertical alignment respectively. For specifying precision for text display is given with function. setTextPrecision (tr) Where text precision parameter tpr is assigned one of the values: string, char, or stroke. © The highest-quality text is produced when the parameter is set to the value stroke. Marker Attributes A marker symbol display single character in different color and in different sizes. For marker attributes implementation by procedure that load the chosen character into the raster at defined position with the specified color and size. ©) We select marker type using function. setMarkerType (mt) CQ Where marker type parameter mt is set to an integer code. 1 Typical codes for marker type are the integers 1 through 5, specifying, respectively, a dot (.), a vertical cross (+), an asterisk (*), a circle (0), and a diagonal cross (x). Displayed marker types are centered on the marker coordinates. O We set the marker size with function, SetMarkerSizeScaleFactor (ms) CO — Where parameter marker size ms assigned a positi Q For setting marker color we use function. setPolymarkerColorIndex (me) Where parameter me specify the color of the marker symbol ve number according to need for scaling. Bundled Attributes A particular set of attribute values tor a primitive on each output device is then chosen by specifying the appropriate table index. Atributes specified in this manner called bundled attributes Dr. D. UDAYA / Assistant Professor AAGASC/Depart ment of Computer Science / KKL COMPUTER GRAPHICS Bundied ling Attributes Entries in the bundle table for ine attnbutes en a spectied workstation are set with the function setPotylineRepresentation (ws, Il It bw, le) Parameter wi is the mortstation identifier and line Index parameter Hi defines the bundie table postion. Parameter I, hw, tc are then Bundled and esgned valves to set the line tye, Ine midth, and line color specifications for designated table Index, example setPotylinenepresentation (1, 3, 2, 0.3, 1) setpotylineRepresentation (4, 3, 1, 2.7) A poly line that is atugned a table index value of 3 would be eisplayed using (Cashed bres at nai thickness in a blue color on work station 1: while on woristation 4 his same index generates sol, standarduatted white Lines Bundte ares fil Attributes ‘Table entries for bundled area-fil attributes are set with setInterlorRepresentation (we, fs, ply fe) Which defines the attributes list corresponding to fil Index fl on workstation we. Peremeter fa, pl and tc are asugned valves for the fil style pattern index and fi color. Bundled Text Attributes setTextRepresentation (ws, tl, tf, tp, te, ts, tc) Bundles values for text font, precision expansion factor size an color in a table posttion for work station ws that is specified by value assigned to text index parameter u Bundled marker Attributes setPolymarkerRepresentation (ws, mi, mt, ms, mc) That defines marker type marker scale factor marker color for index mi on workstation ws. Inquiry Function Current settings for attributes and other parameters as workstations types and status in the system lists can be retneved with inguiry functions. InquirePotylinetndex ( tasttl) ane InquirernterioreColourtndex (lastfc) Copy the current valves for ine index and fil color into parameter last and lastfc. Dr, D, UDAVA / Assistant Professor ‘AAGASC/Department of Computer Science / KKL COMPUTER GRAPHICS — { ™*E, orz2s4a5 © Fig. 2.2: - Pixel positions referenced by sean-line number and column number. * To load the specified color imo the frame buffer at a particular position, we will assume we have available low-level procedure of the form setpixel(x, y) © Similarly for retrieve the current frame buffer intensity we assume to have procedure getpix(x. y). Line Drawing Algorithms The Line drawing algorithm is a graphical algorithm which is used to represent the line segment on discrete graphical media. ie... printer and pixel-based media. A tine contains two points. The point is an important clement of a line. Properties of a Line Drawing Algorithm ‘There are the following properties of a good Line Drawing Algorithm, * Analgorithm should be precise: Each step of the algorithm must be adequately defined. Finiteness: An algorithm must contain finiteness. It means the algorithm stops after the exceution of all steps. + Easy to understand: An algorithm must help Ieamers to understand the solution in a more natural way. © Correctness: An algorithm must be in the correct manner. ‘+ Effectiveness: The steps of an algorithm must be valid and efficient, ‘+ Uniqueness: All steps of an algorithm should be clearly and uniquely defined, and the result should be based on the given input, ‘+ Input: A good algorithm must accept at least one or more input. ‘+ Output: An algorithm must generate at least one output, Equation of the straight line We can define a straight line with the help of the following equation. yemx+a Where, (x, y) = atis of the line. Slope of the line. Interception point Dr. D. UDAYA / Assistant Professor AAGASC / Department of Computer Science / KL COMPUTER GRAPHICS Step 3: We get m= 1, Third case is satisfied. Now move to next step. X a Meet yer Oar Ye) 1 7 2 8 (2.8) 3 9 G9» 4 10 (4, 10) 5 u 6.1) 6 12 (6.12) 7 13 (7,13) 8 (8,14) 9 15 (9,15) 10 16 (10, 16) uw 7 (11 17) Step S: Stop. vA 20 13 16 14 12 10 uaoe too | 2 4 6 8 10 12 14 16 fo te Step 4: We will repeat step 3 until we get the endpoints of the line. ‘The coordinates of drawn line are (9, 15) 10, 16) 11,17) Dr. D. UDAYA / Assistant Professor AAGASC / Department of Computer Science / KKL ‘COMPUTER GRAPHICS ‘© Itis fast to apply but not faster than the Digital Differ ‘¢ The pointing accuracy is higher than the DDA algorithm. ial Analyzer (DDA) algorithm. Disadvantages of Bresenham's Line Drawing Algorithm + The Bresenham’s Line drawing algorithm only helps to draw the basic line, © The resulted draw line is not smooth, Circle generating algorithm. Drawing a circle on the screen is a little complex than drawing a line. There are two popular algorithms for generating a circle ~ Bresenham's Algorithm and Midpoint Circle Algorithm. These algorithms are based on the idea of determining the subsequent points required to draw the circle. Let us discuss the algorithms in detail — ‘The equation of circle is X2+Y2=r2,X2+¥2=12, where r is radius. (-ba) (ba) (ab) (at) (2) (b-ay (bra) Bresenham's Algorithm We cannot display a continuous arc on the raster display. Instead, we have to choose the nearest pixel position to complete the arc, From the following illustration, you can see that we have put the pixel at X,YX.Y location and now need to decide where to put the next pixel — at N X#1,YX+1,¥ or at S X+1,Y-1X+1,Y-1. Nien este ° This can be decided by the decision parameter d. © fd <= 0, then NX+1,YX+1,Y is to be chosen as next pixel. © Id >0, then SX+1,Y-1X+1,¥-1 is to be chosen as the next pixel. Dr. D. UDAYA / Assistant Professor AAGASC / Department of Computer Science / KKL COMPUTER GRAPHICS Advantages of Digital Differential Analyzer isa simple algorithm to implement, Itis a faster algorithm than the direct line equation. We cannot use the multiplication method in Digital Differential Analyzer, Digital Differential Analyzer algorithm tells us about the overflow of the point when the point changes its location, Disadvantages of Digital Differential Analyzer * The floating-point arithmetic implementation of the Digital Differential Analyzer is time-consuming. # The method of round-off is also time-consuming. # Sometimes the point position is not accurate. Bresenham’s Line Drawing Algorithm This algorithm was introduced by “Jack Elton Bresenham” in 1962, This algorithm helps us to perform scan conversion of is a powerful, useful and accurate method. We use incremental integer calculations to draw a line. The integer calculations include addition, subtraction, and multiplication. In Bresenham’s Line Drawing algorithm, we have to calculate the slope (m) between the starting point and the ending point, ool + t Xk Xk As shown in the above figure let, we have initial coordinates of a line = (x4, ya). The next coordinates of a line = (x41, Yas). The intersection point between yy and yur = ys Let we assume that the distance between y and y= di. The distance between y and ys.1= ds Now, we have to decide which point is nearest to the intersection point. Him <1 then x = xy+1 { Unit Interval) a+ ( Unit Interval) ‘As we know the equation of a line- yemx+h Now we put the value of x into the Line equation, then y= mixtl) +b a The value of di=y—- va Now we put the value of di in equation (1). Dr. D. UDAYA/ Assistant Professor AAGASC / Department of Computer Science / KKL Y COMPUTER GRAPHICS Then, Me atl {We will choose the nearest x..1 pixel} ‘The next coordinate will be (xi+1, yu) Ifp<0 Then, Bae a {We will choose the nearest xx pixel) ‘The next coordinate will be (xt, y+) Algorithm of Bresenham's Line Drawing Algorithm Step 1: Stan. Step 2: Now, we consider Starting point as (xs, ys) and ending point (xz, y2). Step 3: Now. we have to calculate Ax and Ay. Step coordinates of the line are (x4, yx)pand the next coordinates are (X44 calculate wo eases for decision parameter pa Case I: If ). Now, we are going to psd ‘Then Case2: If ‘Then 7 Step 6: We will repeat step 5 until we found the ending point of the Tine and the total number of iterations = Ax Step 7: Stop. Exampl toplota line has a starting point (9,18) and ending point (14,22). Apply the Bresenham’s Line Drawing algorithm Solution: We have two coordinates, Starting Point Ending Point The value of pr=3 Step 3: Now, we will check both the cases. Dr. D. UDAYA / Assistant Professor AAGASC / Department of Computer Science / KL COMPUTER GRAPHICS If pa>=0 Then Case 2 is satisfied. Thus 42hy-2hx=3+2x4)-(2x5)=1 +1210 B+1=19 Step 4: Now moye to next step. We will calculate the coordinates until we reach the end point of the line. ax-l -t=4 The Coordinates of drawn lines are- Pi=(9, 18) Py= (10, 19) Py= (11, 20) 12, 20) Ps= (13,21) P= (14, 22) Advantages of Bresenbam's Line Drawing Algorithm # Ibis simple to implement because it only contains integers. © Ieis quick and incremental Dr. D. UDAYA / Assistant Professor AAGASC / Department of Computer Science / KKL COMPUTER GRAPHICS Case 1: Ifm<1 ‘Then x coordinate tends to the Unit interval. masmtd yas Case 2: fm >1 Then y coordinate tends to the Unit interval. yoe ytd ™ s+ 1m Case 3: If m=1 ‘Then x and y coordinate tend to the Unit interval. natael yarnel We can calculate all imermediate points with the help of above three discussed cases. Algorithm of Digital Differential Analyzer (DDA) Line Drawing Step 1: Stan. Step 2: We consider Starting point as (x1, yx), and endingpoint (x3, ¥2). Step 3: Now, we have to calculate Ax and Ay. Aree Ay=yeys m= Ay/Ax Step 4: Now, we calculate three cases. mst ‘Then x change in Unit Interval ¥ moves with deviation Yao) = (xat Ds YH) ‘Then x moves with deviation y change in Unit Interval 1) = (at1/m, yut 1m) Then x moves in Unit Interval y moves in Unit Interval (x41, yt) Step 5: We will repeat step 4 until we find the ending point of the line Step 6: Stop. Example: A line hasa starting point (1,7) and ending point (11,17). Apply the Digital Differential Analyzer algorithm to plot a Tine. Solution: We have two coordinates, Starting Point Ending Point Step J: First, we calculate Ax, Ay and m. Axo m= 1-1 = 10 7 y on Step 2: Now, we calculate the number of steps. Ax=ay=10 ‘Then, the number of steps = 10 Dr. D. UDAYA// Assistant Professor AAGASC / Department of Computer Science / KKL COMPUTER GRAPHICS yem(utD+b-y., Ne we again put the value of y in the previous equation then we got, yua-y Spt tom (yl Now, we calculate the difference between di—dz Wdi dy ‘Thea yuu = yal {we will choose the upper pixel as shown in figure) Now. we calculate the values of di~ ds (i= d:)=m (atl) +h-yn—ye— 1 +m (at) +b We simplified the above equation and replaced the m with A y//Ax. ai- im (x1) -2yu + 2bel We multiplied x at both side then we got, Ax (di— dy) = Ax (2m (suar)-2y. + 2b-1) We consider Ax (di—dz) as a decision parameter (Pa), so Pr= Ax (di-d:) After calculation we got, n= 2A yt DAy—2Axye + Ax (26-1) ‘Then, the next coordinate of Pa Pai = 2A 9K + 2A — 2A SVE + AX (2b-1) Now, the difference between pasi— pathen, ’ TAX (Yr n+ 2AY (xie1-a)—2AX (Yea) {Decision parameter coordinate) Now, we put the value of x,y in above equation then we got, P= pet 2Ay-ZAxX(Ma—M) (New decision parameter when m <1) arly, if m >1, the new decision parameter for next coordinate will be Pui= pit 2Ay-2Ax (xi) (New decision parameter when m >I) I p>=0 (For coordinate y) ‘Then, Yeas yatl {We will choose the nearest y..1 pixel) ‘The next coordinate will be (x41, yit 1) {We will choose the nearest y4 pixel) {For coordinate x} Dr. D. UDAYA / Assistant Professor AAGASC / Department of Computer Science / KKL COMPUTER GRAPHICS Pag) ay | Let us assume we have two points of the Fine (pr, q1) and (ps, q3). Now, we will put values of the two points in straight line equation, and we get oa) +--Q) We have from equation (1) and (2) @3—qu= mp2—mpr @:— g= m (P2-Pr) The value of m= (q:~qu/ (p2—pr) m= Aq/ ap Algorithms of Line Drawing ‘There are following algorithms used for drawing a line: + DDA (Digital Differential Analyzer) Line Drawing Algorithm © Bresenham’s Line Drawing Algorithm © Mid-Point Line Drawing Algorith DDA (Digital Differential Analyzer) Line Drawing Algorithm The Digital Differential Analyzer helps us to interpolate the variables on an interval from one point to another point. ‘We can use the digital Differential Analyzer algorithm to perform rasterization on polygons, lines, and triangles. Digital Differential Analyzer algorithm is also known as an incremental method of scan conversion. In this algorithm, we can perform the calculation in a step by step manner, We use the previous step result in the next step. ‘As we know the general equation of the straight Hine is: yemte Here, m is the slope of (x1, ys) and (x, ye m= (y2-y1 (2-31) Now, we consider one point (x4, Then the slope m = (yuet— ya)! (Xu. ) and (xi.4, yaot) as the next point. x) Now, we have to find the slope between the starting point and ending point. There can be following three cases to discuss: Dr. D.UDAYA / Assistant Professor AAGASC / Department of Computer Science / KL COMPUTER GRAPHICS Algorithm. Step 1 - Get the coordinates of the center of the circle and radius, and store them in x, y, and R respectively. Set P=0 and Q=R. Step 2 — Set decision parameter D = 3 - 2R. Step 3 —Repeat through step-8 while P< Q. Step 4 — Call Draw Circle X,Y,P,QX,Y,P,Q. Step 5 — Increment the value of P. Step 6 —IfD <0 then D=D+4P +6. Step 7 — Else Set R=R - 1, D=D +4P-QP-Q+ 10. Step 8 — Call Draw Circle X,¥.P.QX.Y.P.Q. Draw Circle Method(X, Y, P, Q). Call Putpixel (X +P. ¥ + Q). Call Putpixel (X - P. ¥ + Q). Call Putpixel (X +P, ¥ - Q). Call Putpixel (X - P, ¥ - Q). Call Purpixel (X+Q, ¥ +P). Call Putpixel (X - Q. Y +P). Call Putpixel (X +Q. Y - P). Call Putpixel (X - Q, YP). Mid Point Algorithm Step 1 — Input radius r and circle center (xc.ye)(xe.ye) and obtain the first point on the circumference of the circle centered on the origin as Go, yo) = (0, 1) Step 2 — Calculate the initial value of decision parameter as POPO=5/4—r Sce the following description for simplification of this equation. fi. yaxr+y-r=0 2+ey+1) 12+e+i(y+ ler (yt IP - + x = fixi- V2, yi +1) + 20a - 122+ /2)e +e" Dr. D. UDAYA / Assistant Professor AAGASC / Department of Computer Science / KKL COMPUTER GRAPHICS Attributes of output primit Attributes, The features or characteristics of an output primitive are known as Aftribufe. In other words, any parameter that affects the way a primitive is to be displayed is known as Attribute. Some attributes, such as colour and size. are basic characteristics of primitive. Some attributes control the basic display properties of primitives. For example, lines can be dotted or dashed, thin or thick. Areas can be filled with one colour or with multiple colours pattern. Text can appear from left to right, slanted or vertical. Line Attributes: Basic attributes of a straight line are its type, its width, and its colour. In some graphics packages, line can also be displayed using selected pen or brush options. L_ Line Type: The line type attribute includes solid lines, dashed lines, and dotted lines. We modify the line drawing algorithm to generate such lines by setting the length and space. A dashed line could be displayed by generating spaces that is equal to length of solid part, A dotted line can be displayed by generating very short dashes with spacing equal to or greater than the dash size. Similar methods are used to produce other line-type variations. Raster line-algorithms displays line type attribute by plotting pixels. For various dashed, dotted patterns, the line-drawing algorithms outputs part of pixels followed by spaces. Plotting dashes with a fixed number of pixels results in unequal-length dashes for different line angles. For example, the length of dash diagonally is more than horizontal dash for same number of pixels. For precision drawings, dash length should remain approximately same for any line angle. For this, we can adjust the pixel number according to line slope. 2 Line Width: A line with more width can be displayed as parallel lines on a video monitor. In raster lines, a standard width line is generated with single pixels at each point, Width lines are displayed by plotting additional pixels along next parallel line paths. For lines with slope less than 1, we ean display thick lines by plotting a vertical length of pixels at each x pos along the line. Similarly, for lines with slope greater than 1, we can plot thick lines with horizontal widths for each point. The problem with implementing width options using horizontal and vertical pixel widths is that the width of line is depended on the slope. A 45-degree line will be displayed thinner as compared to vertical or horizontal line plotted with same number of pixel widths, Dr. D. UDAYA// Assistant Professor AAGASC/ Department of Computer Science / KKL COMPUTER GRAPHICS Figure ad Double-wide rasterline with slope [mr] < 1 generated with vertical pixel soans Another problem is that it produces lines whose ends are either horizontal or vertical. We can adjust the shape of the line ends by adding Line Caps. One kind of line cap is the Butt Cap. It is obtained by adjusting the end positions of lines so that the thick line is displayed with square ends that are perpendicular to the line. Another line capis the Round Cap obtained by adding a filled semicircle to each butt cap. The semicircle has diameter equal to thickness of line. The third type of line cap is the Projecting Square Cap. Here, the butt cap is extended to half of line width. G ‘Thick Lines drawn with (a) Butt Cap (b) Round Cap and (c) Projecting Square Cap Generating thick connected line segments require other considerations. The methods that we have considered for displaying thick lines will not produce smoothly connected line segments It leaves gaps at the boundaries between lines of different slope. There are three possible methods for smoothly joining two line segments. A Miter Join is obtained by extending the outer boundaries of each of the two lines until they meet. A Round Join is produced by covering the connection between the two segments with a circular boundary whose diameter is equal to the line width, A Bevel Join is generated by displaying the line with butt caps and filling in the triangular gap where the segments meet. Dr. D. UDAYA// Assistant Professor AAGASC / Department of Computer Science / KKL. COMPUTER GRAPHICS Line without Joins == > Miter Join Round Join 3. Pen and Brush Options: In some graphic packages, lines can be displayed with pen or brush selection. Options in this category include shape, size and pattern. These shapes are stored in a Pixel Mask that identifies the pixel positions that are to be set along the line path. Lines generated with pen or brush shaped can be displayed in various widths by changing the size of the mask. Lines can also be displayed with selected patterns. b>)» Kieu ew (Curved nes drawn wath apa! program sing varios shapes and patterns. From left to phi. the beesh shapes are square ound, logonal ne, ot patern and lade ata 4 Line Colour: A system displays a line in the current colour by setting the colour value in the frame buffer at pixel locations. The number of colour choices depends on the number of bits available per pixel in the frame buffer. A line drawn in the background colour is invisible. COLOR AND GRAYSCALE LEVELS Various color and intensity-level options can be made available to a user, depending on the capabilities and design objectives of a particular system, General purpose raster-scan systems, for example, usually provide a wide range of colors, while random-scan monitors typically offer only a few color choices, if any. Color options are numerically coded with values ranging from 0 through the positive integers. For CRT monitors, these color codes are then converted to intensity level settings for the electron beams, With color plotters, the codes could control ink-jet deposits or pen selections In accolor raster system. the number of color choices available depends on the amount of storage provided per pixel in the frame buffer. Also, color-information can be stored in the frame buffer in two ways: We can store color codes directly in the frame buffer, or we can put the color codes in a separate table and use pixel values as an index into this table. With the direct storage scheme, whenever a particular color code Dr. D. UDAYA / Assistant Professor AAGASC/ Department of Computer Science / KKL COMPUTER GRAPHICS GADD Te yo) P=Cua) Let dh = f(xi- 1/2. yi + 1) =-2(xi- 1/Qe - e* Thus, Ife < O then di > Oso choose poi S = (x)= 1, yi + 1). digs = fla 1 V2. yet 14 1) = (xn 1/2)- IP 4 (ee De Pe dy -2(xi- 1) + Ay t+ +1 die 2yicrexnel The initial value of di is do = fir-1/2.0+ I= (1-124 PP 5/4-r[1-rcan be used ifr is an integer} When point § = (xi- 1, yi + 1) is chosen then d= ,+ 281+ 2yia +h When point T = (xi, yi + 1) is chosen then da adit ya t Step 3— At each XKXK position starting at K=O, perform the following test — If Pk <0 then next point on circle (0,0) is (Xk+1,Yx) and Pao =Pxt 2X +1 Else Par = Pet 2Xco #1 = 2Y x Where. 2Xk.1 = 2Xk.2. and 2Ykut = 2YK2- Step 4—Determine the symmetry points in other seven octants Step 5 — Move each calculate pixel position X,YX.Y onto the circular path centered on (XC.YC)(XC.YC) and plot the coordinate values. X=X+Xe, Y=¥+Ye Step 6 — Repeat step-3 through 5 until X >= Y. Dr. D. UDAYA / Assistant Professor ANGASC / Department of Computer Science / KL

You might also like