1 / 88

IT300: Introduction to Computer Graphics

IT300: Introduction to Computer Graphics. 03: Basic Principles of 2D Graphics. Lecturer Details. Dr. Walid Khedr , Ph.D. Email: khedrw@yahoo.com Web: www.staff.zu.edu.eg/wkhedr Department of Information Technology. Main Topics. Introduction

Download Presentation

IT300: Introduction to Computer Graphics

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. IT300: Introduction to Computer Graphics 03: Basic Principles of 2D Graphics

  2. Lecturer Details • Dr. WalidKhedr, Ph.D. • Email: khedrw@yahoo.com • Web: www.staff.zu.edu.eg/wkhedr • Department of Information Technology

  3. Main Topics • Introduction • Basic principles of two-dimensional graphics • Drawing lines and curves • Areas, text and colors • Basic principles of three-dimensional graphics • Modeling three-dimensional objects • Visible surface determination • Illumination and shading • Special effects and virtual reality

  4. Basic Principles of 2D Graphics • Objectives • Representing an Image • Vector and Raster Graphics • Getting Started with Java 2D • Basic Geometric Objects • Geometric Transformations • scaling, rotation, shearing and translation. • Homogeneous Coordinates • Moving Objects • Interpolators

  5. Objectives • Learn basic concepts that are required for the understanding of two-dimensional graphics. • Distinguish between the representation of images on output devices and the model of the image itself. • Learn the basic geometric objects and transformations

  6. Representing an Image

  7. Raster Graphics • Raster graphics: is the representation of images as an array of pixels. • Colors are assigned to each pixel. • Used for computer monitors, printers, and file formats like bitmap or jpg.

  8. Storing Bitmap Images • Frequently large files • Example: 600 rows of 800 pixels with 1 byte for each of 3 colors ~1.5MB file • File size affected by • Resolution (the number of pixels per inch) • Amount of detail affecting clarity and sharpness of an image • Levels: number of bits for displaying shades of gray or multiple colors • Palette: color translation table that uses a code for each pixel rather than actual color value • Data compression

  9. Vector Graphics • Vector graphics is the use of geometrical primitives such as points, lines, curves, and shapes or polygon(s), which are all based on mathematical equations, to represent images. • Efficient storage • Scalable

  10. Scalable

  11. Raster or Vector ? • Computer monitors, printers and also various formats for storing images are based on raster-oriented graphics, also called pixel-oriented graphics. • In order to display vector-oriented graphics in the form of raster graphics, all geometrical shapes must be converted into pixels. • Scan Conversion • Lead to high computational efforts • Possible aliasing effects

  12. Getting Started with Java 2D • Before modelling of two-dimensional objects is discussed in more detail, a short introduction into how Java 2D can be used to generate images in general is provided.

  13. AWT • AWT is a java package that we will be using in order to create graphical user interfaces • Some important classes within the AWT package • Containers: • Frame: has an title bar, can contain many ‘things’ • Panel • Each of the above containers has a paint method that we will inherit but will usually override when we want to customize the container’s graphics.

  14. AWT Example

  15. Paint Method • paint called automagically when needed applet/application starts/resizes/unhidden/etc • Paint method takes a Graphic object as an argument. • This argument is passed to the paint method when drawing operation is required

  16. Java 2D & Paint Method • The class Graphics2D within Java 2D extends the class Graphics. • In order to exploit the options of Java 2D, the Graphics object must be casted into a Graphics2D object within the paint() method. • In order to keep the example programs as simple and understandable as possible, the computations required for defining and positioning the geometric objects are carried out directly in the paint method.

  17. Java 2D & Paint Method, Cont.

  18. Window Coordinates

  19. Basic Geometric Objects • The basic geometric objects in computer graphics are usually called primitives or graphics output primitives. • The basic primitives are the following ones: • Points that are uniquely defined by their x- and y-coordinate. Their main function is the description of other objects like lines • Lines, polylines or curves can be defined by two or more points. • For a line two points are needed • curves require additional control points. • Polylines are connected sequences of lines. • Areas are usually bounded by closed polylines or polygons. • Areas can be filled with a color or a texture.

  20. Polygons • Polygon, closed polyline: The last line segment of a polyline ends where the first line segment started. • Non-self-overlapping • Convexity: Whenever two points are within the polygon the connecting line between these two points lies completely inside the polygon as well.

  21. Parametric Curves • Parametric curves are defined as parametric polynomials • Quadratic Curves: Two endpoints and one control point. • Cubic Curves: Two endpoints and two control points • The curve begins and ends in the two specified endpoints. • In general, it will not pass through control points. • The control points define the direction of the curve in the two endpoints.

  22. Quadratic Curve Example

  23. Cubic Curve Example

  24. Definition of Areas • Polygons, circles and ellipses define areas. • Areas can be bounded by a closed curve. • Areas can be filled by colors and textures.

  25. Set-Theoretic Operations • Modifying the shape of elementary geometric objects by geometric transformations. • Application of set-theoretic operations like union, intersection, difference and symmetric difference to previously defined areas. Union, intersection, difference and symmetric difference of a circle and a rectangle.

  26. Basic Geometric Objects in Java 2D • The abstract class Shape with its various subclasses allows the construction of various two-dimensional geometric objects. • Shapes will not be drawn until the draw or the fill method is called with the corresponding Shape as argument in the form graphics2d.draw(shape) or graphics2d.fill(shape), respectively.

  27. Basic Geometric Objects in Java 2D • The abstract class Point2D is NOT a subclass of Shape. • Points cannot be drawn in Java. • They are only supposed to be used for the description of other objects. • Subclasses of Point2D: Point2D.Float and Point2D.Double.

  28. Basic Geometric Objects in Java 2D • Line (segment): Two endpoints are needed to define aline. • Line2D.Double line = new Line2D.Double(x1,y1,x2,y2); • Quadratic curve: Two endpoints and a control point are needed to define a quadratic curve. • QuadCurve2D.Double qc = new QuadCurve2D.Double(x1,y1, ctrlx,ctrly, x2,y2); • Cubic curve: Two endpoints and two control points are needed to define a cubic curve. • CubicCurve2D.Double cc = new CubicCurve2D.Double(x1,y1, ctrlx1,ctrly1, ctrlx2,ctrly2, x2,y2);

  29. Basic Geometric Objects in Java 2D • General path: A GeneralPath is sequences of lines, quadratic and cubic curves. GeneralPath gp = new GeneralPath(); gp.moveTo(50,50); gp.lineTo(50,200); gp.quadTo(150,500,250,200); gp.curveTo(350,-100,150,150,100,100); gp.lineTo(50,50);

  30. General Path Car

  31. General Path Car

  32. General Path Car

  33. General Path Car

  34. General Path Car

  35. General Path Car

  36. General Path Car

  37. General Path Car

  38. General Path Car

  39. General Path Car

  40. General Path Car

  41. General Path Car

  42. Rectangles • Rectangle: By • Rectangle2D.Double r2d = new Rectangle2D.Double( x,y,width,height); • A rectangle is defined by • left corner has the coordinates (x,y) • width width and height height.

  43. Circles and Ellipses • Circles and ellipses: by • Ellipse2D.Double elli = new Ellipse2D.Double(x,y,width,height); • An axes-parallel ellipse is defined by a bounding Rectangle with the parameters x,y,width,height. • Ellipse2D.Double elli = new Ellipse2D.Double(x-r,y-r,2*r,2*r); defines a circle with centre (x,y) and radius r.

  44. Example: Rectangle and Ellipse

  45. Ellipse Arcs • Arcs (of ellipses) are defined by • Arc2D.Double arc = new Arc2D.Double( rect,start,extend,type); • rect2D: specifies the bounding rectangle of the corresponding ellipse in the form of a Rectangle2D. • Start: is the angle. The angle corresponds to the angle with the x-axis • Extend: is the opening angle of the arc, i.e., the arc extends from the start angle start to the angle start + extend. • Type: can take one of the three values Arc2D.OPEN, Arc2D.PIE and Arc2D.CHORD

  46. Ellipse Arcs

  47. Area Objects

  48. Geometric Transformations • Geometric transformations play a crucial role in computer graphics. • Geometric transformations can be used to position objects: • To scale them • To rotate them • To change the shape of objects • To move them • The most important geometric transformations are scaling, rotation, shearing and translation.

  49. Representation of Points in Matrix Form • In two-dimensional coordinate system, any point is represented in terms of x and y coordinates. • The point (x, y) can be converted into matrix in the following two ways:

  50. Representation of 2D Objects in Matrix Form

More Related