+ All Categories
Home > Documents > Cgms Lecture Notes1

Cgms Lecture Notes1

Date post: 09-Apr-2018
Category:
Upload: chellam1kalai
View: 228 times
Download: 0 times
Share this document with a friend

of 26

Transcript
  • 8/8/2019 Cgms Lecture Notes1

    1/26

    1. Application of Computer Graphics

    y Computer-Aided Design for engineering and architectural systems etc.Objects maybe displayed in a wireframe outline form. Multi-window environment is also favored forproducing various zooming scales and views. Animations are useful for testing performance.

    y Presentation GraphicsTo produce illustrations which summarize various kinds of data. Except 2D, 3D graphics are good

    tools for reporting more complex data.

    y Computer ArtPainting packages are available. With cordless, pressure-sensitive stylus, artists can produce electronic

    paintings which simulate different brush strokes, brush widths, and colors. Photorealistic techniques,

    morphing and animations are very useful in commercial art. For films, 24 frames per second arerequired. For video monitor, 30 frames per second are required.

    y EntertainmentMotion pictures, Music videos, and TV shows, Computer games

    y Education and TrainingTraining with computer-generated models of specialized systems such as the training of ship captains

    and aircraft pilots.

    y VisualizationFor analyzing scientific, engineering, medical and business data or behavior. Converting data to visual

    form can help to understand mass volume of data very efficiently.

    y Image ProcessingImage processing is to apply techniques to modify or interpret existing pictures. It is widely used inmedical applications.

    y Graphical UserInterfaceMultiple window, icons, menus allow a computer setup to be utilized more efficiently.

    2. Overview of Graphics Systems

    2.1 Cathode-Ray Tubes (CRT) - still the most common video display device presently

    Electrostatic deflection of the electron beam in a CRT

    An electron gun emits a beam of electrons, which passes through focusing and deflection systems and

    hits on the phosphor-coated screen. The number of points displayed on a CRT is referred to as the

    1

  • 8/8/2019 Cgms Lecture Notes1

    2/26

  • 8/8/2019 Cgms Lecture Notes1

    3/26

    CS3162 Introduction to Computer GraphicsHelena Wong, 2000

    Random-Scan (Vector Display)

    The CRT's electron beam is directed only to the parts of the screen where a picture is to be drawn. The

    picture definition is stored as a set of line-drawing commands in a refresh display file or a refresh

    buffer in memory.

    Random-scan generally have higher resolution than raster systems and can produce smooth line

    drawings, however it cannot display realistic shaded scenes.

    2.2 Flat-Panel Displays - will be the most common video display device very soon.

    Reduced thickness, volumn, weight, and power requirements compared to CRT.

    Liquid-Crystal Displays (LCDs)

    - Liquid crystal refers to compounds which are in crystalline arrangement, but can flow like liquid.

    - The light source passes through a liquid-crystal material that can be aligned to either block or

    transmit the light.

    - 2 glass plates, each containing a light polarizer at right angles to the other, sandwich a liquid

    crystal material.

    - Rows of horizontal transparent conductors are built into one glass page. Columns of vertical

    conductors are put into the other plate. The intersection of 2 conductors defines a pixel position. -- Passive-matrix LCD

    - In the "on" state, polarized light passing through the material is twisted so that it will pass through

    the opposite polarizer.

    - Different materials can display different colors.

    - By placing thin-film transistors at pixel locations, voltage at each pixel can be controlled. --

    Active-matrix LCD.

    3

  • 8/8/2019 Cgms Lecture Notes1

    4/26

    CS3162 Introduction to Computer GraphicsHelena Wong, 2000

    2.3. Graphics Systems

    Block diagram of a CRT graphics system

    In this context we discuss the graphics systems of raster-scan devices. A graphics processor accepts

    graphics commands from the CPU and executes the graphics commands which may involve drawinginto the frame buffer. The frame buffer acts as a temporary store of the image and also as a decoupler

    to allow the graphics processor and the display controller to operate at different speeds. The display

    controller reads the frame buffer line by line and generates the control signals for the screen.

    Graphics commands:- Draw point

    - Draw polygon

    - Draw text

    - Clear frame buffer- Change drawing color

    2 kinds of graphics processors:

    2D graphics processors execute commands in 2D coordinates. When objects overlap, the one being

    drawn will obscure objects drawn previously in the region. BitBlt operations (Bit Block Transfer) are

    usually provided for moving/copying one rectangular region of frame buffer contents to another

    region.

    3D graphics processors execute commands in 3D coordinates. When objects overlap, it is requiredto

    determine the visibility of the objects according to the z values.

    Display Controller for a raster display device reads the frame buffer and generates the control signalsfor the screen, ie. the signals for horizontal scanning and vertical scanning. Most display controllers

    include a colormap (or video look-up table). The major function of a colormap is to provide a

    mapping between the input pixel value to the output color.

    2.4. Input Devices

    Common devices: keyboard, mouse, trackball and joystick

    Specialized devices:

    Data gloves are electronic gloves for detecting fingers' movement. In some applications, a sensor is

    also attached to the glove to detect the hand movement as a whole in 3D space.

    4

  • 8/8/2019 Cgms Lecture Notes1

    5/26

    CS3162 Introduction to Computer GraphicsHelena Wong, 2000

    A tablet contains a stylus and a drawing surface and it is mainly used for the input of drawings. A

    tablet is usually more accurate than a mouse, and is commonly used for large drawings.

    Scanners are used to convert drawings or pictures in hardcopy format into digital signal for computer

    processing.

    Touch panels allow displayed objects or screen positions to be selected with the touch of a finger. In

    these devices a touch-sensing mechanism is fitted over the video monitor screen. Touch input can be

    recorded using optical, electrical, or acoustical methods.

    2.5 Hard-Copy Devices

    Directing pictures to a printer or plotter to produce hard-copy output on 35-mm slides, overhead

    transparencies, or plain paper. The quality of the pictures depend on dot size and number of dots per

    inch (DPI).

    Types of printers: line printers, laserjet, ink-jet, dot-matrix

    Laserjet printers use a laser beam to create a charge distribution on a rotating drum coated with a

    photoelectric material. Toner is applied to the drum and then transferred to the paper. To produce

    color outputs, the 3 color pigments (cyan, magenta, and yellow) are deposited on separate passes.

    Inkjetprinters produce output by squirting ink in horizontal rows across a roll of paper wrapped on a

    drum. To produce color outputs, the 3 color pigments are shot simultaneously on a single pass along

    each print line on the paper.

    Inkjet or pen plotters are used to generate drafting layouts and other drawings of normally larger

    sizes. A pen plotter has one or more pens of different colors and widths mounted on a carriage which

    spans a sheet of paper.

    2.6 Coordinate Representations in Graphics

    General graphics packages are designed to be used with Cartesian coordinate representations (x,y,z).

    Usually several different Cartesian reference frames are used to construct and display a scene:

    Modeling coordinates are used to construct individual object shapes.

    World coordinates are computed for specifying the placement of individual objects in appropriate

    positions.

    Normalized coordinates are converted from world coordinates, such that x,y values are ranged from

    0 to 1.

    Device coordinates are the final locations on the output devices.

    5

  • 8/8/2019 Cgms Lecture Notes1

    6/26

    CS3162 Introduction to Computer Graphics Helena Wong, 2000

    3. Output Primitives

    Shapes and colors of objects can be described internally with pixel arrays or sets of basic geometric

    structures such as straight line segments and polygon color areas. The functions provided by graphics

    programming packages to deal with these basic geometric structures are called output primitives.

    For example:

    Drawing a point: SetPixel(100,200,RGB(255,255,0));

    Drawing a line: MoveTo(100,100); LineTo(100,200);

    Drawing some text: SetText(100,200,"Hello");

    Drawing an ellipse: Ellipse(100,100,200,200);

    Painting a picture: BitBlt(100,100,50,50,srcImage,0,0,SRCCOPY);

    3.1 Drawing a Thin Line in Raster Devices

    This is to compute intermediate discrete coordinates along the line path between 2 specified endpoint

    positions. The corresponding entry of these discrete coordinates in the frame buffer is then markedwith the line color wanted.

    The basic concept is:

    - A line can be specified in the form: y

    = mx + c

    - Let m be between 0 to 1, then the slope of the line is between 0 and 45 degrees.

    - For the x-coordinate of the left end point of the line, compute the corresponding y value according

    to the line equation. Thus we get the left end point as (x1,y1), where y1 may not be an integer.

    - Calculate the distance of(x1,y1) from the center of the pixel immediately above it and call it D1

    -

    Calculate the distance of(x1,y1) from the center of the pixel immediately below it and call it D2- If D1 is smaller than D2, it means that the line is closer to the upper pixel than the lower pixel,

    then, we set the upper pixel to on; otherwise we set the lower pixel to on.

    - Then increatement x by 1 and repeat the same process until x reaches the right end point of the

    line.

    - This method assumes the width of the line to be zero

    6

  • 8/8/2019 Cgms Lecture Notes1

    7/26

  • 8/8/2019 Cgms Lecture Notes1

    8/26

    CS3162 Introduction to Computer GraphicsHelena Wong, 2000

    3.2 Drawing a Circle in Raster Devices

    A circle can be specified in the form:

    (x-xc)2

    + (y-yc)2

    = r2

    where (xc,yc) is the center of the circle.

    To save time in drawing a circle, we can make use of the symmetrical property of a circle which is to

    draw the segment of the circle between 0 and 45 degrees and repeat the segment 8 times as shown in

    the diagram to produce a circle. Ths algorithm also employs the incremental method which further

    improves the efficiency.

    void PlotCirclePoints(int centerx, int centery, int x, int y) { SetPixel(centerx+x,centery+y);

    SetPixel(centerx-x,centery+y);SetPixel(centerx+x,centery-y);SetPixel(centerx-x,centery-y);SetPixel(centerx+y,centery+x);SetPixel(centerx-y,centery+x);SetPixel(centerx+y,centery -x);SetPixel(centerx-y,centery-x);

    }void BresenhamCircle(int centerx, int centery, int radius) { int x=0;

    int y=radius; intp=3-2*radius;while (x

  • 8/8/2019 Cgms Lecture Notes1

    9/26

  • 8/8/2019 Cgms Lecture Notes1

    10/26

    CS3162 Introduction to Computer GraphicsHelena Wong, 2000

    3.4 Boundary-Fill Algorithm

    - This algorithm starts at a point inside a region and paint the interior outward towards the boundary.

    - This is a simple method but not efficient: 1. It is recursive method which may occupy a large

    stack size in the main memory.

    void BoundaryFill(int x, int y, COLOR fill, COLOR boundary) { COLOR current;

    current=GetPixel(x,y);

    if (currentboundary) and (currentfill) then{ SetPixel(x,y,fill);

    BoundaryFill(x+1,y,fill,boundary);BoundaryFill(x-1,y,fill,boundary); BoundaryFill(x,y+1,fill,boundary); BoundaryFill(x,y-1,fill,boundary);

    }}

    - More efficient methods fill horizontal pixel spands across scan lines, instead of proceeding to

    neighboring points.

    3.5 Flood-Fill Algorithm

    - Flood-Fill is similar to Boundary-Fill. The difference is that Flood-Fill is to fill an area which I

    not defined by a single boundary color.

    void BoundaryFill(int x, int y, COLOR fill, COLOR old_color)

    { if (GetPixel(x,y)== old_color){ SetPixel(x,y,fill);

    BoundaryFill(x+1,y,fill,boundary);BoundaryFill(x-1,y,fill,boundary);BoundaryFill(x,y+1,fill,boundary);

    BoundaryFill(x,y-1,fill,boundary);}

    }

    10

  • 8/8/2019 Cgms Lecture Notes1

    11/26

    CS3162 Introduction to Computer GraphicsHelena Wong, 2000

    3.6 Drawing Text

    - A character is defined by its outline which is usually comoposed of lines and curves.

    - We can use a method similar the one for rendering polygon to render a character

    - However, because text is used very oftenly, we usually convert them into bitmaps in advance to

    improve the drawing efficiency.

    - To draw a character on the screen, all we need to do is to copy the corresponding bitmap to

    the specified coordinate.- The problem with this method is that scaling a character with a bitmap to produce different

    character sizes would result in a block-like structures (stair-case, aliasing). Hence we normally

    render a few bitmaps for a single character to represent different sizes of the same character.

    3.7 Bitmap

    - A graphics pattern suh as an icon or a character may be needed frequently, or may need to be

    re-used.

    - Generating the pattern every time when needed may waste a lot of processing time.

    - A bitmap can be used to store a pattern and duplicate it to many places on the image or on

    the screen with simple copying operations.

    11

  • 8/8/2019 Cgms Lecture Notes1

    12/26

    CS3162 Introduction to Computer GraphicsHelena Wong, 2000

    3.8 Properties

    - In graphical output primitives, objects are normally associated with propertiesEg.Point: colorLine: width, style, color

    Polygon: edge color, filling colorText: font size, color, bold or not bold, italic or not, underlined or not, etc.

    In graphical packages, we can specify such properties, eg. In Powerpoint, we can modify

    the properties of objects by a format command.

    In programming tools, we may pass the properties as arguments when we call the functions of these

    primitives, or we may pre-select the properties before calling the functions.

    Two Dimensional Transformations

    In many applications, changes in orientations, size, and shape are accomplished with geometric transformations

    that alter the coordinate descriptions of objects.

    Basic geometric transformations are:TranslationRotationScaling

    Other transformations:ReflectionShear

    Basic Transformations

    Translation

    We translate a 2D point by adding translation distances, tx and ty, to the original coordinate position

    (x,y):x' = x + tx, y' = y + ty

    Alternatively, translation can also be specified by the following transformation matrix:

    1 0t x

    0 1t y

    -0 01 Then we can rewrite the formula as:

    x'1 0 t xxy' = 0 1 t y y

    -1 -0 0 1 -1For example, to translate a triangle with vertices at original coordinates (10,20), (10,10), (20,10) by

    tx=5, ty=10, we compute as followings:

    Translation of vertex (10,20):

    x'1 0 5 10 1*10 0 * 20 5 *1 15y'

    =

    0 1 10

    20

    =

    0 *10 1* 20 10 *1

    =

    30

    -1 -0 0 1 - 1 - 0 *10 0 * 20 1*1 - 1

  • 8/8/2019 Cgms Lecture Notes1

    13/26

    Translation of vertex (10,10):

    x'1 0 5 10 1*10 0 *10 5 *1 15y'

    =

    0 1 10

    10

    =

    0 *10 1*10 10 *1

    =

    20

    -1 -0 0 1 - 1 - 0 *10 0 *10 1*1 - 1

    Translation of vertex (20,10):

    x'1 0 5 20 1* 20 0 *10 5 *1 25y'

    =

    0 1 10

    10

    =

    0 * 20 1*10 10 *1

    =

    20

    -1 -0 0 1 - 1 - 0 * 20 0 *10 1*1 - 1

    The resultant coordinates of the triangle vertices are (15,30), (15,20), and (25,20) respectively.

    Exercise: translate a triangle with vertices at original coordinates (10,25), (5,10), (20,10) by tx=15,

    ty=5. Roughly plot the original and resultant triangles.

    Rotation About the Origin

    To rotate an object about the origin (0,0), we specify the rotation angle ?. Positive and negative values

    for the rotation angle define counterclockwise and clockwise rotations respectively. The followings is

    the computation of this rotation for a point:

    x' = x cos ? - y sin ?

    y' = x sin ? + y cos ?

    Alternatively, this rotation can also be specified by the following transformation matrix:

    cos U sinU 0

    sin U cos U 0

    - 0 0 1Then we can rewrite the formula as:

    x' cos U sin U 0x

    y' = sinU cos U 0 y

    -1 - 0 0 1-1For example, to rotate a triange about the origin with vertices at original coordinates (10,20), (10,10),

    (20,10) by 30 degrees, we compute as followings:

    cos U sinU 0 cos 30 sin 30 0 0.866 0.5 0

    sin U cos U 0 = sin 30 cos 30 0 = 0.5 0.866 0

    - 0 0 1 - 0 0 1 - 0 0 1Rotation of vertex (10,20):

    x' 0.866 0.5 010 0.866 *10 (0.5) * 20 0 *1 1.34

    y' = 0.5 0.866 0 20 = 0.5 *10 0.866 * 20 0 *1 = 22.32 1 0 0 1 1 0 *10 0 * 20 1*1 1

    - - - - -

  • 8/8/2019 Cgms Lecture Notes1

    14/26

    Rotation of vertex (10,10):

    x' 0.866 0.5 010 0.866 *10 (0.5) *10 0 *1 3.66

    y' = 0.5 0.866 0 10 0.5 *10 0.866 *10 0 *1 = 13.66 1 0 0 1 1 0 *10 0 *10 1*1 1 - - - - -

    Rotation of vertex (20,10):

    x' 0.866 0.5 020 0.866 * 20 (0.5) *10 0 *1 12.32

    y' = 0.5 0.866 0 10 0.5 * 20 0.866 *10 0 *1 = 18.66

    1 0 0 1 1 0 * 20 0 *10 1*1 1 - - - - -

    The resultant coordinates of the triangle vertices are (-1.34,22.32), (3.6,13.66), and

    (12.32,18.66) respectively.

    Exercise: Rotate a triange with vertices at original coordinates (10,20), (5,10), (20,10) by 45

    degrees. Roughly plot the original and resultant triangles.

    Scaling With Respect to the Origin

    We scale a 2D object with respect to the origin by setting the scaling factors sx and sy, which

    are multiplied to the original vertex coordinate positions (x,y):

    x' = x * sx, y' = y * sy

    Alternatively, this scaling can also be specified by the following transformation matrix:

    sx 0 0

    0 sy 0

    -0 0 1

    Then we can rewrite the formula as:

    x' sx 0 0x

    y' = 0 sy y

    -1 - 0 01-1For example, to scale a triange with respect to the origin, with vertices at original coordinates

    (10,20), (10,10), (20,10) by sx=2, sy=1.5, we compute as followings:

    Scaling of vertex (10,20):

    x'2 0 0102 *10 0 * 20 0 *1 20

    y' = 0 1.5 0 20 = 0 *101.5 * 200 *1 = 30

    -1 -0 0 1-1 -0 *10 0 * 20 1*1 - 1 Scaling of vertex (10,10):

    x'2 0 010 2 *10 0 *10 0 *1 20

    y' = 0 1.5 0 10 = 0 *101.5 *100 *1 = 15

    -1 -0 0 1-1 -0 *100 *101*1 - 1Scaling of vertex (20,10):

  • 8/8/2019 Cgms Lecture Notes1

    15/26

    x'2 0 020 2 * 20 0 *10 0 *1 40

    y' = 0 1.5 0 10 = 0 * 201.5 *100 *1 = 15

    -1 -0 0 1- 1 -0 * 20 0 *101*1 -1The resultant coordinates of the triangle vertices are (20,30), (20,15), and (40,15) respectively.

    Exercise: Scale a triange with vertices at original coordinates (10,25), (5,10), (20,10) by sx=1.5,

    sy=2, with respect to the origin. Roughly plot the original and resultant triangles.

    Concatenation Properties of Composite Matrix

    I. Matrix multiplication is associative:

    ABC = (AB) C = A(BC)

    Therefore, we can evaluate matrix products using these associative grouping.For example, we have a triangle, we want to rotate it with the matrix B, then we translate it withmatrix A.Then, for a vertex of that triangle represented as C, we compute its transformation as:

    C'=A(BC)

    But we can also change the computation method as:

    C' = (AB)C

    The advantage of computing it using C' = (AB)C instead of C'=A(BC) is that, for computing

    the 3 vertices of the triangle, C1, C2, C 3, the computation time is shortened:

    Using C'=A(BC):

    - compute B C1 and put the result into I1

    - compute A I1 and put the result into C1'

    - compute B C2 and put the result into I2- compute A I2 and put the result into C2

    '

    - compute B C3 and put the result into I3

    - compute A I3 and put the result into C3'

    Using C' = (AB)C:- compute A B and put the result into M

    - compute M C1 and put the result into C1'

    - compute M C2 and put the result into C2'

    - compute M C3 and put the result into C3'

    4

  • 8/8/2019 Cgms Lecture Notes1

    16/26

    CS3162 Introduction to Computer GraphicsHelena Wong, 2000

    Example: Rotate a triangle with vertices (10,20), (10,10), (20,10) about the origin by 30 degrees

    and then translate it by tx=5, ty=10,

    We compute the rotation matrix:

    cos 30 sin 300 0.866 0.5 0

    B = sin 30 cos 30 0 = 0.5 0.866 0 - 0 0 1 - 0 0 1And we compute the translation matrix:

    1 0 5

    A= 0 110

    -0 0 1Then, we compute M=AB

    1 0 5 0.866 0.5 0M= 0 110 0.5 0.8660

    -00 1 - 0 0 1 1* 0.866 0 * 0.5 5 * 0 1*0.5 0 * 0.866 5 * 0 1* 0 0 * 0 5 *1

    M= 0 * 0.866 1* 0.5 10 * 0 0 * 0.5 1* 0.866 10 * 0 0 * 0 1* 0 10 *1

    - 0 * 0.866 0 * 0.5 1* 0 0 * 0.5 0 * 0.866 1* 0 0 * 0 0 * 0 1*1 0.866 0.5 5

    M= 0.5 0.866 10

    - 0 0 1 Then, we compute the transformations of the 3 vertices:Transformation of vertex (10,20):

    x' 0.866 0.5 5 10 0.866 *10 (0.5) * 20 5 *1 3.66

    y' = 0.5 0.866 10 20 = 0.5 *100.866 * 2010 *1 = 32.32 1 0 0 1 1 0 *10 0 * 20 1*1 1- - - - -

    Transformation of vertex (10,10):

    x' 0.866 0.5 5 10 0.866 *10 (0.5) *10 5 *1 8.66

    y' = 0.5 0.866 10 10 = 0.5 *100.866 *1010 *1 = 23.66 1 0 0 1 1 0 *10 0 *10 1*1 1

    - - - - -

  • 8/8/2019 Cgms Lecture Notes1

    17/26

    Transformation of vertex (20,10):

    x' 0.866 0.5 5 20 0.866 * 20 (0.5) *10 5 *1 17.32

    y' = 0.5 0.86610 10 = 0.5 * 200.866 *1010 *1 = 28.66 1 0 0 1 1 0 * 20 0 *10 1*1 1

    - - - - -

    The resultant coordinates of the triangle vertices are (3.66,32.32), (8.66,23.66), and (17.32,28.66)

    respectively.

    II. Matrix multiplication may not be commutative:

    AB may not equal to BAThis means that if we want to translate and rotate an object, we must be careful about the order in whichthe composite matrix is evaluated. Using the previous example, if you compute C' = (AB)C, you are

    rotating the triangle with B first, then translate it with A, but if you compute C' = (BA)C, you are

    translating it with A first, then rotate it with B. The result is different.

    Exercise: Translate a triangle with vertices (10,20), (10,10), (20,10) by tx=5, ty=10 and then rotate it about

    the origin by 30 degrees. Compare the result with the one obtained previously: (3.66,32.32),(8.66,23.66), and (17.32,28.66) by plotting the original triangle together with these 2 results.

    4.3 Composite Transformation Matrix

    Translations

    By common sense, if we translate a shape with 2 successive translation vectors: (tx1, ty1) and (tx2, ty2), it is

    equal to a single translation of(tx1+ tx2, ty1+ t y2).This additive property can be demonstrated by composite transformation matrix:

    1 0 t x1 1 0 t x2 1*1 0 * 0 t x1 * 0 1* 0 0 *1 t x1 * 0 1* t x 2 0 * t y 2 t x1 *1

    0 1 t 0 1 t = 0 *1 1* 0 t * 0 0 * 01*1 t * 0 0* t 1* t t *1 y1 y2 y1 y1 x 2 y 2 y1

    -0 0 1 -0 0 1 - 0 *1 0 * 0 1* 0 0 * 0 0 *1 1* 0 0 * t x 2 0 * tu 2 1*1

    1 0 t x1 t x 2= 0 1 t t

    y1 y 2 0 0 1 -

    This demonstrates that 2 successive translations are additive.

    Rotations

    By common sense, if we rotate a shape with 2 successive rotation angles: ? and a, about the origin, it

    is equal to rotating the shape once by an angle ? + a about the origin.Similarly, this additive property can be demonstrated by composite transformation matrix:

    cos U sin U 0cos E sin E 0

    sin U cos U 0 sinE cos E 0

    - 0 0 1 - 0 0 1cos Ucos E( sin U) * sin E 0 * 0 cos U * ( sin E) ( sinU) * cos E 0 * 0 cos U * 0 ( sin U) * 0 0 *1

  • 8/8/2019 Cgms Lecture Notes1

    18/26

    = sin U cos E cos U * sin E 0 * 0 sin U * ( sin E) cos U * cos E 0 * 0 sinU * 0 cos U * 0 0 *1 0 * cos E 0 * sin E 1* 0 0 * ( sin E) 0 * cos E 1* 0 0 * 0 0 * 0 1 *1 -

    cos Ucos

    =sin U cos-

    E sin Usin E (cos Usin E sin U cos E) 0

    E cos Usin E sin Usin E cos Ucos E 0

    0 0 1

  • 8/8/2019 Cgms Lecture Notes1

    19/26

  • 8/8/2019 Cgms Lecture Notes1

    20/26

    - 0 0 1 -00 1 cos U sin U x rcos U y r sinU x r

    = sin U cos U x sin U ycos U y r r r

    0 0 1-

    General Fixed-Point Scaling

    Scaling with respect to an arbitrary fixed point is not as simple as scaling with respect to the

    origin. The procedure of scaling with respect to an arbitrary fixed point is:

    1. Translate the object so that the fixed point coincides with the origin.

    2. Scale the object with respect to the origin.

    3. Use the inverse translation of step 1 to return the object to its original position.

    The corresponding composite transformation matrix is:

    1 0x f sx 0 01 0 x f s x 0 xf (1s x )

    0 1 0 s 0 0 1 y = 0 s y (1 s f y f yf y 0 0 1 0 0 1 0 0 1 0 0 1- - - -

    General Scaling Direction

    Scaling along an arbitrary direction is not as simple as scaling along the x-y axis. The procedure of

    scaling along and normal to an arbitrary direction (s1 and s2), with respect to the origin, is:

    1. Rotate the object so that the directions for s1 and s2 coincide with the x and y axes respectively.

    2. Scale the object with respect to the origin using (s1, s2).

    3. Use an opposite rotation to return points to their original orientation.

    The corresponding composite transformation matrix is:

    cos(U) sin(U) 0s1 0 0cos U sinU 0

    sin(U) cos(U) 0 0 s2 0 sin U cos U 0 0 0 1 0 0 1 0 0 1

  • 8/8/2019 Cgms Lecture Notes1

    21/26

    - - -

    4.4 Other Transformations

    Reflection

    Reflection about the x axis:x'1 0 0x

    y' = 0 1 0 y-1 -0 0 1-1ie. x'=x; y'=-y

    Reflection about the y axis:

    x'1 0 0x

    y' = 0 1 0 y-1 - 0 0 1-1ie. x'=-x; y'=y

    Flipping both x and y coordinates of a point relative to the origin:

    x' 1 0 0xy' = 0 1 0 y -1 - 0 0 1-1ie. x'=-x; y'=-y

    Reflection about the diagonal line y=x:

    x'0 1 0xy'

    =

    1 0 0y -1

    -0 0 1-1ie. x'=y; y'=x

    Reflection about the diagonal line y=-x:x' 0 1 0x

    y' = 1 0 0 y -1 - 0 0 1-1ie. x'=-y; y'=-x

    Shear

    X-direction shear, with a shearing parameter shx, relative

    to the x-axis:

    x' 1 shx 0x

    y' = 0 1 0 y -1 -001-1

    ie. x'=x+y*shx; y'=-x

    Exercise:

    Think of a y-direction shear, with a shearing parameter shy, relative to the y-axis.

    Transformation Between 2 Cartesian Systems

    For modelling and design applications, individual objects may be defined in their ownlocal Cartesian References. The local coordinates must then be transformed to position

    the objects within the overall scene coordinate system.

    Suppose we want to transform object descriptions from the xy system to the x'y' system:

  • 8/8/2019 Cgms Lecture Notes1

    22/26

    The composite transformation is:

    cos(U) sin(U) x r1 0 x 0sin(U) cos(U) y 0 1 y

    r 0 0 1 0 0 1

    - -

    Clipping

    Line Clipping

    This section treats clipping of lines against rectangles. Although there are specialized algorithms

    for rectangle and polygon clipping, it is important to note that other graphic primitives can be

    clipped by repeated application of the line clipper.

    1. Clipping Individual Points

    Before we discuss clipping lines, let's look at the simpler problem of clipping individual

    points.

    If the x coordinate boundaries of the clipping rectangle are Xmin and Xmax, and the ycoordinate boundaries are Ymin and Ymax, then the following inequalities must be

    satisfied for a point at (X,Y) to be inside the clipping rectangle:

    Xmin < X < Xmax

    and Ymin < Y < Ymax

    If any of the four inequalities does not hold, the point is outside the clipping rectangle.

    The Cohen-Sutherland Line-Clipping Algorithm

    The more efficient Cohen-Sutherland Algorithm performs initial tests on a line to

    determine whether intersection calculations can be avoided.

    Steps for Cohen-Sutherland algorithm

    1. End-points pairs are check for trivial acceptance or trivial rejected using theoutcode.

    2. If not trivial-accepance or trivial-rejected, divided into two segments at a clip edge.

    3. Iteratively clipped by testing trivial-acceptance or trivial-rejected, and divided into two

    segments until completely inside or trivial-rejected.

    1. Trivial acceptance/reject testTo perform trivial accept and reject tests, we extend the edges of the clip rectangle to

    divide the plane of the clip rectangle into nine regions. Each region is assigned a 4-bitcode deteermined by where the region lies with respect to the outside halfplanes of the

    clip-rectangle edges. Each bit in the outcode is set to either 1 (true) or 0 (false); the 4 bitsin the code correspond to the following conditions:

    o Bit 1 : outside halfplane of top edge, above top edge

    Y > Ymax

    o Bit 2 : outside halfplane of bottom edge, below bottom edge

    Y < Ymin

  • 8/8/2019 Cgms Lecture Notes1

    23/26

    o Bit 3 : outside halfplane of right edge, to the right of right edge

    X > Xmax

    o Bit 4 : outside halfplane of left edge, to the left of left edge

    X < Xmin

    2.Clipping Polygons3. An algorithm that clips a polygon must deal with many different cases. The case is

    particularly note worthy in that the concave polygon is clipped into two separatepolygons. All in all, the task of clipping seems rather complex. Each edge of the polygon

    must be tested against each edge of the clip rectangle; new edges must be added, andexisting edges must be discarded, retained, or divided. Multiple polygons may result from

    clipping a single polygon. We need an organized way to deal with all these cases.

    4. The following example illustrate a simple case of polygon clipping.

    5.

    Sutherland and Hodgman's polygon-clipping algorithm uses a divide-and-conquer strategy: It

    solves a series of simple and identical problems that, when combined, solve the overall problem.The simple problem is to clip a polygon against a single infinite clip edge. Four clip edges, each

    defining one boundary of the clip rectangle, successively clip a polygon against a clip rectangle.

    Note the difference between this strategy for a polygon and the Cohen-Sutherland algorithm for

    clipping a line: The polygon clipper clips against four edges in succes sion, whereas the lineclipper tests the outcode to see which edge is crossed, and clips only when necessary.

    Steps of Sutherland-Hodgman's polygon-clipping algorithm

    y Polygons can be clipped against each edge of the window one at a time. Windows/edgeintersections, if any, are easy to find since the X orY coordinates are already known.

    y Vertices which are kept after clipping against one window edge are saved for clippingagainst the remaining edges.

    y Note that the number of vertices usually changes and will often increases.

    y We are using the Divide and Conquer approach.

    The clip boundary determines a visible and invisible region. The edges from vertex i to vertex

    i+1 can be one offour types:

    y Case 1 : Wholly inside visible region - save endpointy Case 2 : Exit visible region - save the intersectiony Case 3 : Wholly outside visible region - save nothingy Case 4 : Enter visible region - save intersection and endpoint

    GRAPHICAL USER INTERFACESIt is common now for software packages to provide a graphical interface. A

  • 8/8/2019 Cgms Lecture Notes1

    24/26

    major component of a graphical interface is a window manager that allows a user

    .to display multiple-window areas. Each window can contain a different processthat can contain graphical or nongraphical displays. To make a particular window

    active, we simply click in that window using an interactive pointing dcvicc.

    Interfaces also display menus and icons for fast selection of processing options

    or parameter values. An icon is a graphical symbol that is designed to look

    like the processing option it represents. The advantages of icons are that they

    take up less screen space than corresponding textual descriptions and they can be

    understood more quickly if well designed. Menbs contain lists of textual descriptions

    and icons.

    Figure 1-73 illustrates a typical graphical mterface, containing a window

    manager, menu displays, and icons. In this example, the menus allow selection of

    processing options, color values, and graphics parameters. The icons represent

    options for painting, drawing, zooming, typing text strings, and other operations

    connected with picture construction.

    A graphical user interface, showing multiplewindow areas, menus, andicons.

    THE USER DlALOGlJEFor a particular application, the rrser's rrroiidserves as the basis for the deslgn otthe dialogue. The user's model describes what the svstem is designed to acconiplish

    and what graphics operations are available. It state; the type of obj ects thatcan be displayed and how the objects can be manipulated. For example, if the

    graphics system is to bc used as a tool for architectural design, the model describeshow the package can be used to construct and dispIay views of buildings

    by positioning walls, doors, windows, and other buildin!; components. Similarly,for a facilitv-layout system, objects could be defined as a set of furniture items

    (tables, cham, etc.), and the available operations would include those for positioning

    and removing different pieces of tcrniture within the fticility layout. Anda circuit-design progranl might use electrical or logli t~l~me nftosr objects, with

    positic~ningoperations.I ,.adable foradding or drlctirg c~lc~nienwtsi thin the o \.?rallcircuit design

    All information in the user dialogue is then presented in the language of the Mion 6-1application. In an architectural design package, this means that all interactions TheUserDialogue

    are described only in architectural terms, without reference to particular datastructures or other concepts that may be unfamiliar to an architect. In the following

    sections, we discuss some of the general considerations in structuring a userdialogue.Windows and Icons

    Figure 8-1 shows examples of common window and icon graphical interfaces. Visual

    representations are used both for obpds to be manipulated in an application

    and for the actions to beperformed on the application objects.A window system provides a window-manager interface for the user andfunctions for handling the display and manipulation of the windows. Commonfunctions for the window system are opening and closing windows, repositioning

  • 8/8/2019 Cgms Lecture Notes1

    25/26

    windows, resizing windows, and display routines th at provide interior andexterior clipping and other graphics functions. Typically, windows are displayed

    with sliders, buttons, and menu icons for selecting various window options.Some general systems, such as X Widows and NeWS, are capable of supportingmultiple window managers so that different window styles can be accommodated,

    each with its own window manager. The window managers can then bedesigned for particular applications. In other cases, a window system is designedfor one specific application and window style.

    Icons representing objects such as furniture items and circuit elements areoften referred to as application icons. The icons representing actions, such as 1-0-

    tate, magnlfy, scale, clip, and paste, are called control icons, or command icons.

    Accommodating~ u l h l Sek ill LevelsUsually, interactive graphical interfaces provide several methods for selecting actions.

    For example, options could be selected by pointing at an icon and clickingdifferent mouse buttons, or by accessing pull-down or pop-up menus, or by typingkeyboard commands. This allows a package to accommodate users that have

    different skill levels.For a less experienced user, an interface with a few easily understood operations

    and detailed prompting is more effective than one with a large, compre -

    Minimising Memory RequirementsOperations ill an interl.~ce shot~lcl illso br structured .;o -tiat thev are easy to understandand to renicmxr. Ohx-urc, compl~catedi,n cor5istent. and abbreviated

    command forrn'its Ir,ld . o conlu*~ona nd reduct~onIn tho' c~tlcvt~\,ento~t stsh e u wol the package. One ke! or button used lor all delete operat~onsf,o r example, iseasier to remember than a nulnher of ditlerent kevs for different types of delete

    operations.

    Icons and windo\\ systems also aid in minimizing memor~zationD. iiferent

    kinds ofinformation can he separated into d~fferenwt ~ndows s,o that we d o nothave to rely on meniorization when different information displays overlap. We

    can simply retain the multiple information on the scretbn in different windows,

    and switch bark and forth between windoh areas. Icons .Ire used to reduce memorizingby displaying easily recognizable shapes for various objects and actions.

    To select aparticular action, we simply select the icon th al rrsemhles that action.

  • 8/8/2019 Cgms Lecture Notes1

    26/26


Recommended