Sie sind auf Seite 1von 18

Computer Graphics 2008

- Introduction:

- Typically the output unit is the screen … its operation depends on the cathode ray tube.

- The basic operation of the cathode ray tube:

- A beam of electrons emitted by an electron gun , passes through focusing system and
deflecting system towards specified positions on the phosphor-coated screen.

- Note:

- The phosphor emits a small spot of light at each position contacted by the beam it may fades
quickly … one way to maintain the picture is to quickly direct the beam towards the same spot …
this is called ( refresh CRT ).

- The component of the electron gun:

- The primary component of the electron gun is ( heated metal , cathode , control grid ) … first
the heat is supplied to the cathode by directing a current through a coil of wire called the (
filament ) … this causes the electrons to be boiled off the cathode surface … this free, negative
charged electrons are then accelerated towards the phosphor coated screen by a high positive
voltage … this voltage can be generated with a ( positive charged metal in the CRT envelop near
the phosphor coated screen ) or ( accelerating anode ).

- Note:

- Intensity of the electron beam can be controlled by setting the voltage levels on the control
grid … which is a metal cylinder that fits over the cathode … a high negative voltage will shut of
the beam by repelling the electrons and stopping them from passing through the small hole at
the end of the grid.

- Focusing system:

- Focusing system in a CRT is needed to force the electron beam to converge into a small spot as
it strikes the phosphor. Other wise the beam will spread as soon as it contacts the screen.

- Focusing can be accomplished by either electric or magnetic fields.

- Electrostatic focusing is commonly used in ( T.V and computer graphic screens ) … in


electrostatic focusing the electrons passes through a positive charged metal cylinder that forms
an electrostatic lens witch focuses the beam at the center of the screen.

- Similarly focusing can be accomplished by magnetic field setup by a coil mounted around the
outside of the CRT envelop … it is used for special purpose devises.

1
Computer Graphics 2008
- Deflection system:

- As with focusing, deflection of the beam can be accomplished with electric and magnetic field.

- Cathode ray tube are now commonly constructed with magnetic deflection coils mounted on
the outside of the CRT envelop.

- Two pair of coils are used … one pair is mounted on the ( top and bottom ) of the neck and the
other is mounted on the ( side ) of the neck.

- Magnetic field produced by each pair results in a transverse force that is perpendicular to the
magnetic field and to the direction of travel of the beam … the prober deflection are attained by
adjusting the current through the coils.

- When electrostatic deflection is used two pairs of parallel plates are constructed inside the CRT
envelop … one pair is constructed horizontally to control the vertical deflection and the other
pair is constructed vertically for the horizontal deflection.

- Phosphor coated screen:

- Spots of light are produced on the screen by the transfer of the CRT beam energy to the
phosphor.

- When the electrons of the beam collide with the phosphor, they are stopped and there energy
is absorbed by the phosphor, this causes the phosphor electrons to transfer to a higher energy
level.

- After a while this excited electron drops back to ground state giving up their extra energy in
the form of light energy.

- The frequency ( color ) of the light is proportional to the energy difference between the excited
quantum state and the ground state.

- Different types of phosphors are available the major difference is their persistence: ( how long
they continue to emit light after the beam is removed ) … it is defined as the time takes the
emitted light from the screen to decay to tenth of it original intensity.

- Low persistence phosphor requires high refresh rate to maintain the picture on the screen, it is
very useful for animation … high persistence phosphor is used for complex static pictures.

2
Computer Graphics 2008
- The resolution:

- The maximum number of points can be displayed without overlap on the CRT is called
resolution. A more accurate definition of the resolution is the number of points per centimeter
that can be displayed horizontally and vertically.

- Two adjacent spots will appear distinct as long as their separation is greater than the diameter
at which every point has an intensity about 60% of that at the center of the spot.

- Spot size also depends on the beam intensity as more electrons are accelerated towards the
phosphor the more the diameter of the illuminated spot increases.

- Resolution depends on the ( type of the phosphor , the intensity to be displayed and the
focusing and deflecting system ).

- Aspect Ration:

This number gives the ration of vertical points to horizontal points necessary to produce equal-
length lines in both direction of the screen.

- An aspect ration of ( ¾ ) means that a vertical line plotted with tree points has the same length
as a horizontal line plotted with four points.

- Raster-Scan Display:

- The most common type of graphic monitors employing a CRT are raster scan display system,
based on television technology.

- In raster scan system the beam is swept across the screen one line a time from top to bottom
… while the beam moves across the screen its intensity is turned ( on ) and ( off ) creating a
pattern of illuminated spots.

- The picture definition are stored in memory location that is call refresh ( buffer ) or ( frame
buffer ) … this memory location stores the intensity values for all screen points … the capability
of the raster system to store the intensity values for all the points of the screen makes it suitable
for realistic display.

- Each point is called ( pixel ) … the intensity values for pixel positions depends on the capability
of the system … in simple black and white system every pixel with In the screen is either ( on ) or
( off ) .. So one bit will be enough to control the pixel status … Additional bits will be needed ion
color systems .. Up to 24-bit can be used in high quality systems, these bits may require a
storage space of several megabytes.

3
Computer Graphics 2008
- Refreshing in the raster scan system is between ( 60 – 80 ) frame per second or ( HZ ) … at the
end of each scan line the beams returns back to the left side to begin the new scan line, this is
called ( horizontal retrace ) … while at the end of every frame it returns back to the top left
corner of the screen to begin the new frame this is called ( vertical retrace ).

- In some raster system ( like T.V ), the frame is displayed in 2 passes using ( interlaced )
procedure … In the first pass the beam swept across every other scan line then after vertical
retrace it moves across the remaining lines.

- Interlaced procedure allows us to display the frame at half the time of the ordinary methods …
also it requires a slower refresh rate.

- Random-Scan Display:

- In random display system the CRT directs the beam toward certain parts of the screen where
the picture is to be drawn.

- Random scan system draws a picture one line a time for this reason it is called (vector display).

- The component line of a picture can be drawn and refreshed by a random scan system at any
order.

- Refresh rate depends on the number of line to be displayed … the picture definition is stored in
a memory location called ( refresh display file ) in the form of line drawing commands.

- To display a picture the system cycles through commands, drawing each component line In
turn, after finishing it cycles back to the first command on the list.

- Random scan systems are designed for line drawing applications and can not display realistic
picture … since the picture definition is stored as a line drawing commands and not as a set on

4
Computer Graphics 2008
intensity values for all the screen points it have a higher resolution than raster system and a
smooth line drawing.

- Color CRT Monitors:

- A CRT monitor displays color by using a combination of phosphor the have a different colored
light … by combining the emitted light produced from the different phosphors we can have any
desired color.

- There are two basic techniques for producing color ( beam penetration method ) and ( masked
shadow method ).

- The beam penetration method is used with random scan monitors … two layers of phosphor
( red , green ) are coated on the inside if the CRT screen , and the displayed color depends on
how far did the beam penetrates the layers.

- A beam of slow electrons excites only the outer red layer... A beam of very fast electrons will
penetrates the red layer and excites the green layer … A intermediate beam will penetrate
through the red layer and excites the inner green layer to show to additional colors ( yellow ,
orange ).

- Beam penetration method is not an expensive method to produce color but it produced only
four colors and the quality of the picture is not so good.

- Shadow masked method is used in raster scan systems because it provides a wider range of
colors than the beam penetration method.

- A shadow masked CRT have three color dots at every pixel position each dot have its
corresponding electron gun they emits ( red , green , blue ) lights … Also there is a shadow

5
Computer Graphics 2008
mashed grid just behind the screen , it is used to focuses and deflect the tree electron beams as
a group towards the desired pixel ( point ).

- When the three beams passes through the hole in the shadow mask and contacts there
corresponding dots ( delta-delta ) configuration they activate a dot triangle which appears as a
small color spot on the screen.

- Another configuration for the three electron guns is an ( in-line ) arrangement in which the
three electron guns and the corresponding dots are aligned along one scan line … it is used for
high resolution systems.

- We obtain the color variations in a shadow masked system by varying the intensity level of the
three electron guns … by turning of the red and green guns we will have only a blue light, other
combination can easily be obtained as the color depends on the amount of the excitation of the
( red , green , blue ) phosphor … white color can be produced by activate the three guns at equal
intensity.

- Color CRTs in graphic systems are designed as ( RGB monitors ) … this monitors use shadow
masked methods but they take the intensity levels from the computer system directly to the
screen with out passing through the shadow grid … high quality raster-graphic system have 24-
bit per pixel in the frame buffer , allowing about 256 voltage setting which is nearly 17 million
color choices.

6
Computer Graphics 2008
- Direct-View Storage Tubes ( DVST ):

- An alternating method for maintaining the screen picture is to store the picture information
inside the ( CRT ) instead of refreshing the screen … A ( DVST ) stores the picture information in
the form of charge distribution just behind the phosphorus coated screen.

- Two electron guns are used in a ( DVST ) … one , the primary gun is used to store the picture
pattern and the second one ( the flood gun ) , is used to maintain the picture display.

- DVST monitors has both advantages and disadvantages compared to refresh ( CRT ) … the
advantage is that since no refresh is needed very complex picture could be displayed at a very
high resolution … the disadvantage is that it is ordinarily do not display color and a certain
selected part of the picture can not be erased.

- Flat Panel Display:

- The term flat panel display refers to objects that have reduced weight volume and power
requirements compared to ( CRT ) … the flat panel display is used ion small T.V monitors ,
calculators and laptops.

- We can divide the flat panel display in to categories emissive and non-emissive display.

- Emissive display are devices that converts electrical energy to light energy such as plasma
panel , electroluminescent display , and light emitting diode.

- Non-emissive devices are devices that use optical effect to convert sun light or any other light
from an internal source in to graph pattern … such as liquid crystal display.

- Plasma Panel: also called gas discharge display , are constructed by filling the region between
two glass plates with mixture of gas usually including neon. A series of vertical conducting
ribbons is places on the glass plate , and a set of horizontal ribbons are places on the other glass
plate … firing voltage applied to a pair of vertical and horizontal conductors causes the gas at the
intersection to glow a plasma of electrons and ions.

- Picture definition is stored in a refresh buffer and firing voltage are applied to refresh the pixel
position 60 times per second.

- Thin –Film Electroluminescent display: are similar to in construction to plasma panel , the
difference is that the region between the glass plates filled with phosphor instead of gas … the
phosphor become a conductor at the region of intersection of the two electrodes. Then
electrical energy is then absorbed and converted to light energy … it requires more power than
the plasma display.

- Light Emitting Diode: A matrix of diodes is constructed to form the pixel position.

7
Computer Graphics 2008

( Plasma Panel ) ( Electroluminescent)

- Liquid crystal display ( LCD ):

- They are used with very small devices such as calculators or laptops , these non-emissive
devices use polarized light generated fro the surrounding or from an internal source to produce
a picture.

- Picture definition are stored in a refresh buffer and the screen is refreshed ( 60 ) times per
second as emissive devices.

- Color can be displayed by using different materials or dyes and by placing a triad of color at
each screen position.

- Raster Scan System:

- Interactive raster graphics system employ several processing units. In addition to the ( CPU )
there is a video controller , that is used to control the operation of the display device.

- In the organization of simple raster system the frame buffer could be any where in the system
memory and the video controller access the frame buffer to refresh the screen.

- Another commonly used organization of the raster system , a fixed area at the system memory
is reserved to the frame buffer that the video controller have a direct access to it.

Fig.1 Fig.2

8
Computer Graphics 2008
- Random Scan System:

- In the organization of a simple random-scan (vector) system an application program is input


and stored in the system memory … Graphics commands in the application program are
translated into a display file stored in the system memory … this display file is then accessed by
the display processor to refresh the screen.

- Graphics patterns are drawn on a random-scan system by directing the electron beam along
the component lines of the picture. Lines are defined by the values for their coordinate
endpoints, and these input coordinate values are converted to x and y deflection voltages.

- Graphic Software:

- There are two general classifications for graphics software : general purpose programming
package and special purpose device package.

- A general graphics programming package provides an extensive set of graphic functions that
can be used in a high level programming language such as ( C ) … graphic library ( GL ) system are
an example.

- The basic functions in general package includes components used for generating a picture such
as ( strait lines , polygons , circles ) , setting color , intensity values.

- The general purpose package applications are designed to be used by non-programmers so


that the used can create a display without worrying about how it is done. The interface of
graphic routine allows the used to communicate with the program.

9
Computer Graphics 2008
- Coordinates representation:

- General purpose package are designed to be used with Cartesian coordinates ... if the picture
coordinate values are specified at any other reference frame then it should be converted to
Cartesian coordinates … only special purpose package allow the use if other reference frames.

- In general , several different Cartesian reference frame can be used to construct or display a
picture.

- Individual objects like ( trees , furniture )can be constructed in a separate reference frames
called the ( modeling coordinates ) … then after finishing all the objects we place them in
appropriate place in another reference frame called the world coordinates … then they have to
converted to a reference frame that will normalize them from the range of ( 0 to 1 ) called the
( normalized coordinates ) … finally they are transmitted to the output device and converted to
the output device reference frame called ( device coordinated ).

( X mc , Y mc ) ( X wc , Y wc ) ( X nc , Y nc ) ( X dc , Y dc )

- Modeling and world coordinates can be floating point values while the normalized coordinated
should satisfy the equation ( 0 < X , Y < 1 ) … also the device coordinated are bounded by the
region from ( 0 , 0 ) and ( X max. , Y max. ).

10
Computer Graphics 2008
- Graphic Functions:

- A general purpose programming package provides a Varity of graphic functions that are used
for crating pictures … these routines can be organized according to whether they are dealing
with : input , output , attributes , transformation , view , …. .

- Output primitives: the basic function blocks for picture is referent to output primitive … they
includes the character string and geometric entity like : points , lines , curved lines , circles …
Shapes are defined with a array of colored points … routines for output primitives includes the
basic tools for constructing a picture.

- Attributes: they describe how a particular primitive is to be displayed … they include the
intensity and color specifications , line style , text style.

- Geometric Transformation: it is used to change to size , position , and orientation of an object


within a scene.

- View Transformation: it is used to specify the view going to be presented and the output
display area going to be used.

- Points and Lines:

- Point plotting is accomplished by converting a single coordinate position created by an


application program into appropriate operations for the output device in use. With a CRT
monitor, for example, the electron beam is turned ( on ) to illuminate the screen phosphor at
the selected location.

- A random-scan (vector) system stores point-plotting instructions in the display list, and
coordinate values in these instructions are converted to deflection voltages that position the
electron beam at the screen locations to be plotted.

- For a black and white raster system , a point is plotted by setting the bit value corresponding to
a specified screen position within the frame buffer to 1. Then, as the electron beam sweeps
across each horizontal scan line, it turns the beam ( on ) whenever a value of ( 1 )is encountered
in the frame buffer.

- With an RGB system, the frame buffer is loaded with the color codes for the intensities that are
to be displayed.

- Line drawing is accomplished by calculating intermediate positions along the line path between
two specified endpoint positions. An output device is then directed to fill in these positions
between the endpoints.

11
Computer Graphics 2008
- For analog devices, a straight line can be drawn smoothly from one endpoint to the other.
Varying horizontal and vertical deflection voltages should be proportional to the required
changes in the ( x ) and ( y ) directions to produce the smooth line.

- Digital devices display a straight line by plotting discrete points between the two endpoints.
Discrete coordinate positions along the line path are calculated from the equation of the line.

- We will assume that the pixel positions are referred to the scan-line number and column
number.

- Line-Drawing Algorithms:

- The Cartesian slope-intercept equation for a straight line is:

Y = mX + b

- With ( m ) representing the slope of the line and ( b ) as the ( y ) intercept. Given that the two
endpoints of a line segment are specified at positions ( X1 , Y1 ) and (X2 ,Y2) … we can
determine values for the slope ( m) and ( y ) intercept ( b ) with the following calculations:

𝑌2 − 𝑌1
𝑚=
𝑋2 − 𝑋1

𝑏 = 𝑌1 − 𝑚 𝑋1

- For any given ( x ) interval ( ∆x ) along a line, we can compute the corresponding ( y ) interval
( ∆y ) from:

∆𝑦 = 𝑚 ∆𝑥

- similarly we can obtain ( x ) interval ( ∆x ) corresponding to a specified ( ∆y ) from:

∆𝑦
∆𝑥 =
𝑚

- This equations forms the basics for determining deflection voltages in analog devices

- For lines with slope magnitudes I m I < 1, ( ∆x ) can be set proportional to a small horizontal
deflection voltage and the corresponding vertical deflection is then set proportional to ( ∆y ).

- For lines whose slopes have magnitudes I m I > 1, ( ∆y ) can be set proportional to a small
vertical deflection voltage and the corresponding horizontal deflection voltage set proportional
to ( ∆x ).

- For lines with m = 1,( ∆x ) = ( ∆y ) and the horizontal and vertical deflections voltages are equal.

12
Computer Graphics 2008
- On raster systems, lines are plotted with pixels, and step sizes in the horizontal and vertical
directions are depends on pixel separations … so we must "sample" a line at discrete positions
and determine the nearest pixel to the line at each sampled position.

- DDA Algorithm:

- The digital differential analyzer (DDA) is a scan-conversion line algorithm based on calculating
either ∆y or ∆x. We sample the line at unit intervals in one coordinate and determine
corresponding integer values nearest the line path for the other coordinate.

- Consider first a line with positive slope. If the slope is less than or equal to 1, we sample at unit
( x ) intervals (∆x = 1) and compute each successive ( y ) value:

𝑦𝑘+1 = 𝑦𝑘 + 𝑚

- ( K ) takes integer values starting from 1, for the first point, and increases by 1 until the final
endpoint is reached. Since ( m ) can be any real number between 0 and 1, the calculated ( y )
values must be rounded to the nearest integer.

- For lines with a positive slope greater than 1, we reverse the roles of x and y. That is, we
sample at unit ( y ) intervals (∆y = 1) and compute each successive ( x ) value:

1
𝑥𝑘+1 = 𝑥𝑘 +
𝑚

- The Equations are based on the assumption that lines are to be processed from the left
endpoint to the right endpoint. If this process is reversed, so that the starting endpoint is at the
right, then either we have ∆x = -1 and:

𝑦𝑘+1 = 𝑦𝑘 − 𝑚

- Or (when the slope is greater than 1) we have ∆y = -1 with:

1
𝑥𝑘+1 = 𝑥𝑘 −
𝑚

- Summary:

- Equations can also be used to calculate pixel positions along a line with negative slope. If the
absolute value of the slope is less than 1 and the start endpoint is at the left, we set ( ∆x = 1 )
and calculate ( y ) values.

-When the start endpoint is at the right (for the same slope), we set ( ∆x = -1 ) and obtain (y)
positions.

- Similarly, when the absolute value of a negative slope is greater than 1, we use ∆y = -1 or we
use ∆y = 1.

13
Computer Graphics 2008
- Loading the frame buffer:

- When a straight line segment and other objects are scan converted fro display with a raster
system, the frame buffer positions must be calculated.

- We have assumed that this is accomplished with the ( set pixel ) procedure, which stores
intensity values for the pixel at corresponding addresses within the frame buffer array.

- We use incremental methods to calculate the frame buffer addresses.

- As a specific example, suppose the frame buffer array is addressed in row major order and that
pixel position vary from ( 0 , 0 ) at the lower left screen corner to ( X max. , Y max. ) at the top
right corner. For a bi-level system ( 1 bit per pixel ), the frame-buffer bit addresses for pixel
position ( x, y ) is calculated as:

𝑎𝑑𝑑𝑟(𝑥 , 𝑦) = 𝑎𝑑𝑑𝑟(0 , 0) + 𝑦(𝑥𝑚𝑎𝑥 . +1 ) + 𝑥

- Moving across a scan line, we can calculate the frame buffer address for the pixel at ( X + 1 , Y )
as the following offset from the address for position ( x , y ):

𝑎𝑑𝑑𝑟( 𝑥 + 1 , 𝑦 ) = 𝑎𝑑𝑑𝑟(𝑥 , 𝑦) + 1

- Stepping diagonally up to the next scan line from ( x, y ), we get to the frame-buffer address of
( X+1 , Y+1 ) with the calculation:

𝑎𝑑𝑑𝑟( 𝑥 + 1 , 𝑦 ) = 𝑎𝑑𝑑𝑟(𝑥 , 𝑦) + 𝑥𝑚𝑎𝑥. + 2

- Where the constant ( X max. + 2 ) is calculated once for all line segments.

- Methods for implementing the ( Set Pixel ) procedure depends on the capability of a particular
system and the design requirements of the software package. With systems that can display a
range of intensity values for each pixel, frame buffer addresses calculations would include pixel
width ( Number of bits ).

14
Computer Graphics 2008
- Circle generation algorithm:

- Since the circle is a frequently used component in pictures and graphs, a procedure for
generating either full circles or circular arcs is included in most graphics packages.

Properties of Circles:

- A circle is defined as the set of points that are all at a given distance r from a center position
( X c , Y c ). This distance relationship is expressed by the Cartesian coordinates as:

( 𝑥 − 𝑥𝑐 )2 + ( 𝑦 − 𝑦𝑐 )2 = 𝑟 2

- We could use this equation to calculate the position of points on a circle circumference by
stepping along the x axis in unit steps from ( X c – r ) to ( X c + r ) and calculating the
corresponding ( Y ) values at each position as:

𝑦 = 𝑦𝑐 ± √𝑟 2 − (𝑥 − 𝑥𝑐 )2

- But this is not the best method for generating a circle. One problem with this approach is that
it involves considerable computation at each step. Moreover, the spacing between plotted pixel
positions is not uniform.

- We could adjust the spacing by interchanging ( X and Y ) whenever the absolute value of the
slope of the circle is greater than 1. But this simply increases the computation and processing
required by the algorithm.

- Another way to eliminate the unequal spacing is to calculate points along the circular boundary
using polar coordinates ( r and Ѳ ). Expressing the circle equation in parametric polar form yields
the pair of equations:

𝑥 = 𝑥𝑐 + 𝑟 cos 𝜃

𝑦 = 𝑦𝑐 + 𝑟 sin 𝜃

- When a display is generated with these equations using a fixed angular step size, a circle is
plotted with equally spaced points along the circumference. The step size chosen for Ѳ depends
on the application and the display device. For a more continuous boundary on a raster display,
𝐼
we can set the step size at ( ). This plots pixel positions that are approximately one unit apart.
𝑟

- Computation can be reduced by considering the symmetry of circles. The shape of the circle is
similar in each quadrant. We can generate the circle section in the second quadrant of the (x y)
plane by noting that the two circle sections are symmetric with respect to the ( Y axis ). And
circle sections in the third and fourth quadrants can be obtained from sections in the first and
second quadrants by considering the symmetry about the ( X axis ).

15
Computer Graphics 2008
- We can do such operation also be notice the symmetry between octants. Circle sections in
adjacent octants within one quadrant are symmetric with respect to the 45° line dividing the
two octants.

- Where a point at position (x, y) on a one-eighth circle sector is mapped into the seven circle
points in the other octants of the ( x y ) plane.

- Taking advantage of the circle symmetry in this way, we can generate all pixel positions around
a circle by calculating only the points within the sector from x = 0 to x = y.

- A method for direct distance comparison is to test the halfway position between two pixels to
determine if this midpoint is inside or outside the circle boundary. This method is more easily
applied to other conics and for an integer circle radius.

- Midpoint Circle Algorithm:

- To apply the midpoint method, we define a circle function:

𝑓𝑐𝑖𝑟𝑐𝑙𝑒 = 𝑥 2 + 𝑦 2 − 𝑟 2

- The relative position of any point ( x, y ) can be determined by checking the sign of the circle
function:

<0, 𝑖𝑓 (𝑥 , 𝑦 )𝑖𝑠 𝑖𝑛𝑠𝑖𝑑𝑒 𝑡ℎ𝑒 𝑐𝑖𝑟𝑐𝑙𝑒 𝑏𝑜𝑢𝑛𝑑𝑎𝑟𝑦


𝑓𝑐𝑖𝑟𝑐𝑙𝑒 {=0, 𝑖𝑓 (𝑥 , 𝑦 )𝑖𝑠 𝑜𝑛 𝑡ℎ𝑒 𝑐𝑖𝑟𝑐𝑙𝑒 𝑏𝑜𝑢𝑛𝑑𝑎𝑟𝑦
>0, 𝑖𝑓 (𝑥 , 𝑦 )𝑖𝑠 𝑜𝑢𝑡𝑠𝑖𝑑𝑒 𝑡ℎ𝑒 𝑐𝑖𝑟𝑐𝑙𝑒 𝑏𝑜𝑢𝑛𝑑𝑎𝑟𝑦

- The circle-function tests are performed for the mid positions between pixels near the circle
path at each sampling step. Thus, the circle function is the decision parameter in the midpoint
algorithm, and we can set up incremental calculations for this function as we did in the line
algorithm.

- If ( P k ) < 0, this midpoint is inside the circle and the pixel on scan line ( Y k ) is closer to the
circle boundary. Otherwise, the mid position is outside or on the circle boundary, and we select
the pixel on scan line ( Y k – 1 ).

16
Computer Graphics 2008
- Midpoint Circle Algorithm:

1. Input radius( r ) and circle center (x c, y C), and obtain the first point on the circumference of a
circle centered on the origin as:

(𝑥0 , 𝑦0 ) = (0 , 𝑟)

2. Calculate the initial value of the decision parameter as

5
𝑝0 = − 𝑟
4

3. At each ( X k ) position, starting at ( K = 0 ), perform the following test: if ( P k < 0 ), the next
point along the circle centered on (0, 0) is (X k+1 , Y k) and

𝑝𝑘+1 = 𝑝𝑘 + 2𝑥𝑘+1 + 1

Otherwise, the next point along the circle is (X k + 1, Y k - 1) and

𝑝𝑘+1 = 𝑝𝑘 + 2𝑥𝑘+1 + 1 − 2𝑦𝑘+1

Where 2𝑥𝑘+1 = 2𝑥𝑘 + 2 and 2𝑦𝑘+1 = 2𝑦𝑘 − 2

4. Determine symmetry points in the other seven octants.

5. Move each calculated pixel position (x, y) onto the circular path centered on (x c, y c) and plot
the coordinate values:

𝑥 = 𝑥 + 𝑥𝑐 , 𝑦 = 𝑦 + 𝑦𝑐

6. Repeat steps 3 through 5 until ( X ≥ Y ).

17
Computer Graphics 2008
- Example:

- Given a circle radius r = 10, we demonstrate the midpoint circle algorithm by determining
positions along the circle octant in the first quadrant from x = 0 to x = y. The initial value of the
decision parameter is

𝑝0 = 1 − 𝑟 = −9

For the circle centered on the coordinate origin, the initial point is (x0, y0) = (0, 10), and initial
increment terms for calculating the decision parameters are

2𝑥0 = 0 , 2𝑦0 = 20

Successive decision parameter values and positions along the circle path are calculated using the
midpoint method as

K 𝒑𝒌 ( 𝒙𝒌+𝟏 , 𝒚𝒌+𝟏 ) 𝟐𝒙𝒌+𝟏 𝟐𝒚𝒌+𝟏


0 -9 ( 1 , 10 ) 2 20
1 -6 ( 2 , 10 ) 4 20
2 -1 ( 3 , 10 ) 6 20
3 6 (4,9) 8 18
4 -3 (5,9) 10 18
5 8 (6,8) 12 16
6 5 (7,7) 14 14

18

Das könnte Ihnen auch gefallen