TOPIC 2

Computer Graphics

Introduction

  • In computer graphics, we work with objects defined in a three-dimensional world.
      - 2D objects and worlds are special cases of the general three-dimensional context.

  • All objects to be drawn, along with their respective cameras, possess:
      - Shape
      - Position
      - Orientation

  • We write computer programs that describe these objects and their lighting.
      - The aim is to compute the final pixel values displayed on the screen.

Fundamental Tools in Graphics

  • Two fundamental sets of tools assist in graphics:
      - Vector Analysis
      - Transformations

  • Methods are developed to describe various geometric objects.

  • We learn to convert geometric ideas into numerical representations.
      - This results in crucial algorithms applicable in graphics programming.

Easy Problems for Vectors

  • Key problems can be simplified using vectors:
      - Calculate the center of a circle defined by three points.
      - Determine the shape and position of images on the viewplane.
      - Identify the reflection of a cube on a shiny cone and the shape of that reflection.

Vectors

  • Vectors are advantageous for solving challenging problems.
      - Defined by: Length and Direction.
      - They have no fixed position in space (relative to a coordinate system) and can be moved freely.

  • Points have a fixed position but lack length and direction.

  • Scalars represent size only (a numerical value).

Basics of Points and Vectors

  • All points and vectors are defined in relation to a coordinate system.
      - Example depicted with a 2D coordinate system and right-handed and left-handed 3D coordinate systems.

Left and Right Handedness

  • Right-Handed System:
      - Curl your fingers from the x-axis towards the y-axis; your thumb points along the z-axis.

  • Left-Handed System:
      - Your thumb points opposite the direction of the z-axis.

Review of Vectors

  • Vectors visual representation:
      - Illustrated as arrows of a specific length pointing in a specific direction.

  • Example: Displacements of stars in the Big Dipper over the next 50,000 years.

Vectors and Coordinate Systems

  • To calculate a vector vv from points P=(1,3)P = (1, 3) to Q=(4,1)Q = (4, 1):
      - vv has components (3,−2)(3, -2), derived from the calculation Q−PQ - P.
      - Movement from PP to QQ includes:
        - Down by 2 units.
        - Right by 3 units.
      - Vectors can be represented without position; hence vectors with the same components are equivalent.

Vector Operations

  • Difference between points forms a vector:
      - v=Q−Pv = Q - P.

  • Adding a vector to a point results in another point:
      - P+v=QP + v = Q.

  • An n-dimensional vector is typically represented as an n-tuple:
      - For 2 or 3 dimensions: v=(3,−2)v = (3, -2).

Vector Representations

  • Row vector representation:
      - v=(33,142.7,89.1)v = (33, 142.7, 89.1).

  • Column vector representation:
      - v=(33 142.7 89.1)v = \begin{pmatrix} 33 \ 142.7 \ 89.1 \end{pmatrix}.

Fundamental Vector Operations

  • Two basic operations:
      - Addition of two vectors.
      - Multiplication by a scalar.

  • If aa and bb are vectors, then:
      - a+ba + b is also a vector.
      - For a scalar ss, sasa is a vector.

Vector Operations (Continued)

  • Subtracting vector cc from aa is equivalent to adding aa to −c-c:
      - −c=(−1)c-c = (-1)c.

Linear Combinations of Vectors

  • Defined as:
      - v1ext±v2=(v1xext±v2x,v1yext±v2y,v1zext±v2z)v_1 ext{ ± } v_2 = (v_{1x} ext{ ± } v_{2x}, v_{1y} ext{ ± } v_{2y}, v_{1z} ext{ ± } v_{2z})
      - sv=(svx,svy,svz)sv = (sv_x, sv_y, sv_z).

  • A linear combination of vectors v1,v2,ext…,vmv_1, v_2, ext{…}, v_m is given by:
      - w=a1v1+a2v2+ext…+amvmw = a_1v_1 + a_2v_2 + ext{…} + a_mv_m.

  • Example:
      - 2(3,4,−1)+6(−1,0,2)=(0,8,10)2(3, 4, -1) + 6(-1, 0, 2) = (0, 8, 10).

Affine and Convex Combinations

  • An affine combination exists if:
      - a1+a2+…+am=1a_1 + a_2 + … + a_m = 1.

  • Example:
      - 3a+2b−4c3a + 2b - 4c is affine, but 3a+b−4c3a + b - 4c is not.

  • Convex combinations require:
      - aiext≥0a_i ext{ ≥ } 0 for all 1ext≤iext≤m1 ext{ ≤ } i ext{ ≤ } m.

  • Example:
      - 0.3a+0.7b0.3a + 0.7b is convex, but 1.8a−0.8b1.8a - 0.8b is not.

Set of All Convex Combinations of Two or Three Vectors

  • Convex combination represented as:
      - v=(1−a)v1+av2v = (1 - a)v_1 + av_2, where aa varies from 0 to 1.

  • A corresponding example illustrated.

Vector Magnitude and Unit Vectors

  • Magnitude of an n-vector ww is denoted as ∣w∣|w|.

  • Examples:
      - For w=(4,−2)w = (4, -2), find ∣w∣=ext??|w| = ext{??}.
      - For w=(1,−3,2)w = (1, -3, 2), find ∣w∣=ext??|w| = ext{??}.

  • A unit vector has a magnitude of:
      - ∣v∣=1|v| = 1.

  • The unit vector aligning in the same direction as vector aa is denoted (if ∣a∣<br>eq0|a| <br>eq 0).
      - The process of converting aa into a unit vector is termed normalizing.

Properties of Unit Vectors

  • A unit vector can refer to a direction.

  • Any vector can be expressed as the product of its magnitude and direction:
      - a=∣a∣extextdirectiona = |a| ext{ } ext{ direction}.

Vector Dot Product

  • The dot product for n-vectors vv and ww:
      - v∙w=v1w1+v2w2+…+vnwnv \bullet w = v_1w_1 + v_2w_2 + … + v_nw_n.

  • Properties of the dot product:
      - Commutative: v∙w=w∙vv \bullet w = w \bullet v.
      - Distributive: (aext±b)∙c=a∙cext±b∙c(a ext{ ± } b) \bullet c = a \bullet c ext{ ± } b \bullet c.
      - Associative over scalar multiplication: (sa)∙b=s(a∙b)(sa) \bullet b = s(a \bullet b).
      - Self dot product yields the magnitude squared: b∙b=∣b∣2b \bullet b = |b|^2.

Applications: Angle Between Two Vectors

  • Vectors represented:
      - b=(∣b∣extcoshetab,∣b∣extsinhetab)b = (|b| ext{ cos } heta_b, |b| ext{ sin } heta_b).
      - c=(∣c∣extcoshetac,∣c∣extsinhetac)c = (|c| ext{ cos } heta_c, |c| ext{ sin } heta_c).

  • The connection:
      - b∙c=∣b∣∣c∣extcos(hetac−hetab)b \bullet c = |b| |c| ext{ cos }( heta_c - heta_b) where $ heta = heta_c - heta_b$ is the smaller angle between bb and cc.
      - The relationship is given by:
      - cos(heta)=racext∙ext∙extcos( heta) = rac{ ext{ }{\bullet ext{ }} \bullet ext{ }}.

Angle Conditions

  • Conditions determined by the angle $ heta$:
      - Positive: if ∣heta∣<90exto| heta| < 90^{ ext{o}}.   - Zero: if ∣heta∣=90exto| heta| = 90^{ ext{o}}.   - Negative: if $ heta > 90^{ ext{o}}$.

  • Vectors bb and cc are orthogonal if:
      - b∙c=0b \bullet c = 0.

Standard Unit Vectors

  • Standard unit vectors in 3D:
      - i=(1,0,0)i = (1,0,0), j=(0,1,0)j = (0, 1, 0), and k=(0,0,1)k = (0, 0, 1) (pointing in the positive z direction).

  • In 2D:
      - i=(1,0)i = (1,0) and j=(0,1)j = (0, 1).

  • Noteworthy property: the standard unit vectors are orthogonal.

Finding a 2D Perpendicular Vector

  • Given a vector a=(ax,ay)a = (a_x, a_y),
      - The vector perpendicular in a counterclockwise sense is:
        - a⊥=(−ay,ax)a^{\bot} = (-a_y, a_x).
      - In the clockwise sense, it's −a⊥-a^{\bot}.

  • In 3D, any vector in the plane perpendicular to aa defines a "perp" vector.

Properties of Perpendicular Vectors

  • Key properties:
      - (aext±b)⊥=a⊥ext±b⊥(a ext{ ± } b)^{\bot} = a^{\bot} ext{ ± } b^{\bot}.
      - (sa)⊥=s(a⊥)(sa)^{\bot} = s(a^{\bot}).
      - (a⊥)⊥=−a(a^{\bot})^{\bot} = -a.
      - Inner product relationships:
        - a⊥∙b=−b⊥∙a=−aybx+axbya^{\bot} \bullet b = -b^{\bot} \bullet a = -a_yb_x + a_xb_y.
      - Orthogonality condition:
        - a⊥∙a=a∙a⊥=0a^{\bot} \bullet a = a \bullet a^{\bot} = 0.
      - Magnitude property:
        - ∣a⊥∣=∣a∣|a^{\bot}| = |a|.

Orthogonal Projections and Distances from a Line

  • Given points AA and CC and a vector vv:
      - Address the following queries:
        - How far is CC from line LL (passing through AA in direction vv)?
        - If we drop a perpendicular from CC to LL, where does it intersect?
        - How can we decompose vector c=C−Ac = C - A into components along LL and perpendicular to LL?

Answering the Projection Questions

  • Define c=C−Ac = C - A:
      - We can express cc as:
        - c=Kv+Mv⊥c = Kv + Mv^{\bot}.

  • Analyzing through dot products:
      - c∙v=Kv∙v+Mv⊥∙v=K∣v∣2c \bullet v = Kv \bullet v + Mv^{\bot} \bullet v = K|v|^2 gives:
        - K=racc∙v∣v∣2K = rac{c \bullet v}{|v|^2} (projection of cc onto vv).

  • Dot product with v⊥v^{\bot} provides:
      - M=racc∙v⊥∣v∣2M = rac{c \bullet v^{\bot}}{|v|^2}.

  • Answers to original questions include:
      - Distance: ∣Mv⊥∣|Mv^{\bot}|.
      - Point of intersection: A+KvA + Kv or C−Mv⊥C - Mv^{\bot}.

Application of Projection: Reflections

  • A reflection scenario occurs when light strikes a shiny surface or when a billiard ball collides with the edge of a wall.

Reflections Law

  • When light reflects from a mirror, the angle of reflection equals the angle of incidence:
      - $ heta_1 = heta_2$.

  • Vectors and projections permit calculation of the new direction rr in 2D or 3D scenarios.

Reflection Mathematical Representation

  • Illustrated relationships:
      - e=a−me = a - m and r=e−m=a−2mr = e - m = a - 2m.

  • For mm:
      - m=rac(a∙n)∣n∣2n=(a∙n)nm = rac{(a \bullet n)}{|n|^2}n = (a \bullet n)n; returns projection of aa onto vector nn.

Vector Cross Product (3D Vectors Only)

  • Cross product defined as:
      - aimesb=(aybz−azby)i−(axbz−azbx)j+(axby−aybx)ka imes b = (a_yb_z - a_zb_y)i - (a_xb_z - a_zb_x)j + (a_xb_y - a_yb_x)k.

  • Determinant representation:
      - aimesb=∣ijk axayaz bxbybz∣a imes b = \begin{vmatrix} i & j & k \ a_x & a_y & a_z \ b_x & b_y & b_z \end{vmatrix}.

Properties of Cross Product

  • Key properties include:
      - iimesj=ki imes j = k; jimesk=ij imes k = i; kimesi=jk imes i = j.
      - Antisymmetry: aimesb=−bimesaa imes b = -b imes a.
      - Distributivity: aimes(bext±c)=aimesbext±aimesca imes (b ext{ ± } c) = a imes b ext{ ± } a imes c.
      - Scalar multiplication: (sa)imesb=s(aimesb)(sa) imes b = s(a imes b).
      - Non-valid associativity: aimes(bimesc)<br>eq(aimesb)imesca imes (b imes c) <br>eq (a imes b) imes c.

  • Resultant vector c=aimesbc = a imes b remains perpendicular to both aa and bb; direction follows right/left-hand rules based on coordinate systems.

Additional Cross Product Properties

  • Self dot product:
      - a∙(aimesb)=0a \bullet (a imes b) = 0.

  • Magnitude representation:
      - ∣aimesb∣=∣a∣∣b∣extsinheta|a imes b| = |a| |b| ext{ sin } heta, where $ heta$ is the smaller angle between aa and bb.

  • Cross product also provides the area of the parallelogram formed by vectors aa and bb.

  • Equals zero when aa and bb are collinear or one has length zero.

Geometric Interpretation of the Cross Product

  • The area of the parallelogram spanned by vectors aa and bb is determined by:
      - Area=∣aimesb∣Area = |a imes b|.

Application: Finding the Normal to a Plane

  • Given three non-collinear points AA, BB, and CC, we can determine a normal vector to the plane defined by these points:
      - Let a=B−Aa = B - A, b=C−Ab = C - A; the normal vector n=aimesbn = a imes b.
      - The opposite normal on the other side of the plane is −n-n.

Representations of Key Geometric Objects

  • Representation of lines and planes is crucial in graphics for distinguishing points:
      - This process is simplified by using 4 coordinates instead of 3 (homogeneous representation).

Coordinate Systems and Frames

  • Points and vectors have coordinates in a coordinate system.

  • Multiple coordinate systems can coexist, defined by origins at various spatial locations.

  • A coordinate frame comprises a single origin point (OO) along with 3 mutually perpendicular unit vectors: aa, bb, and cc.

Coordinate Frames (Continued)

  • A vector vv can be represented as:
      - v=v1a+v2b+v3cv = v_1a + v_2b + v_3c.

  • A point PP from the origin can be expressed as:
      - P−O=p1a+p2b+p3cP - O = p_1a + p_2b + p_3c.

Homogeneous Coordinates

  • Both points and vectors are treated uniformly as entities in homogeneous coordinates:
      - A vector is represented as (v1 v2 v3 0)\begin{pmatrix} v_1 \ v_2 \ v_3 \ 0 \end{pmatrix}.
      - A point is expressed via:
      - (v1 v2 v3 1)\begin{pmatrix} v_1 \ v_2 \ v_3 \ 1 \end{pmatrix}.

Changing to and from Homogeneous Coordinates

  • Conversion to homogeneous coordinates:
      - If representing a vector, append a 0 as the 4th coordinate.
      - If representing a point, append a 1.

  • To revert from homogeneous coordinates, simply remove the 4th coordinate.
      - OpenGL utilizes 4D homogeneous coordinates for processing all vertices:
        - A 3-tuple (x,y,z)(x, y, z) is converted to (x,y,z,1)(x, y, z, 1).
        - A 2D point (x,y)(x, y) is converted to (x,y,0,1)(x, y, 0, 1).

  • All calculations in OpenGL are managed in 4D homogeneous coordinates.

Example: Cross Product Calculation

  • Let:
      - A=(1,2,0)A = (1, 2, 0)
      - B=(−2,1,3)B = (-2, 1, 3),
      - Compute:
      - a=(1,2,0)a = (1, 2, 0)
      - b=(−2,1,3)b = (-2, 1, 3)
      - Compute aimesba imes b:
      - Evaluate determinant:
       
      extdet=(ijk 120 −213)ext{det} = \begin{pmatrix} i & j & k \ 1 & 2 & 0 \ -2 & 1 & 3 \end{pmatrix}
      - Calculating individual components:
      - i(6−0)−j(3−0)+k(1+4)i(6 - 0) - j(3 - 0) + k(1 + 4) provides 6i−3j+5k6i - 3j + 5k.

Example: Normal to Plane Calculation

  • Given:
      - A=(1,2,0)A = (1,2,0),
      - B=(−2,1,3)B = (-2, 1, 3),
      - C=(−1,1,1)C = (-1, 1, 1),
      - Compute:
      - Let a=A−C=(2,1,−1)a = A - C = (2, 1, -1)
      - Let b=B−A=(−3,−1,3)b = B - A = (-3, -1, 3),
      - Calculate aimesba imes b:
      - =(21−1 −3−13)= \begin{pmatrix} 2 & 1 & -1 \ -3 & -1 & 3 \end{pmatrix}:

  aimesb=−2i+3j+ka imes b = -2i + 3j + k
  - Result: c∙a=2(2)−3−1=0c \bullet a = 2(2) -3 -1 = 0 (indicates orthogonality).

Here are 20 multiple choice questions (MCQs) with their respective choices and answers:

  1. What does GPU stand for?

    • A) Graphic Processing Unit

    • B) General Processing Unit

    • C) Graphical Product Unit

    • D) Geometry Processing Unit

    • Answer: A

  2. Which of the following is a common graphics API?

    • A) OpenGL

    • B) HTML

    • C) CSS

    • D) PHP

    • Answer: A

  3. What is the primary purpose of the rasterization process?

    • A) To compute pixel colors

    • B) To create 3D models

    • C) To shade objects

    • D) To perform collision detection

    • Answer: A

  4. Which of the following describes a vertex in computer graphics?

    • A) A pixel on the screen

    • B) A point in 3D space

    • C) A type of shader

    • D) A mathematical function

    • Answer: B

  5. What is the term for a series of transformations applied to an object in a 3D space?

    • A) Projection

    • B) Animation

    • C) Transformation

    • D) Simulation

    • Answer: C

  6. What do shaders primarily do in graphics programming?

    • A) Store textures

    • B) Define how objects interact with light

    • C) Create 3D models

    • D) Handle user input

    • Answer: B

  7. In a right-handed coordinate system, what direction does the thumb point?

    • A) Positive x-axis

    • B) Positive y-axis

    • C) Positive z-axis

    • D) Negative z-axis

    • Answer: C

  8. What polygon is most commonly used in 3D graphics?

    • A) Triangle

    • B) Square

    • C) Rectangle

    • D) Hexagon

    • Answer: A

  9. Which term describes the visual distance between two points in 3D space?

    • A) Angle

    • B) Length

    • C) Depth

    • D) Width

    • Answer: B

  10. Which of the following algorithms is commonly used for surface rendering?

    • A) Ray tracing

    • B) Depth sorting

    • C) Clipping

    • D) Z-buffering

    • Answer: A

  11. What is the main function of the z-buffer in computer graphics?

    • A) To store texture data

    • B) To handle colors

    • C) To manage depth information

    • D) To define vertices

    • Answer: C

  12. Which of the following methods is used to achieve anti-aliasing in graphics?

    • A) Smoothing

    • B) Sampling

    • C) Vectorization

    • D) Clipping

    • Answer: A

  13. What is the primary advantage of using a vertex buffer?

    • A) Reduces memory usage

    • B) Increases performance

    • C) Simplifies coding

    • D) Enhances image quality

    • Answer: B

  14. In computer graphics, what does texture mapping refer to?

    • A) Adjusting the brightness of an object

    • B) Applying an image to a surface

    • C) Rendering shadows

    • D) Creating outlines

    • Answer: B

  15. What is the typical frame rate for smooth animation in computer graphics?

    • A) 15 frames per second

    • B) 24 frames per second

    • C) 30 frames per second

    • D) 60 frames per second

    • Answer: D

  16. What does the term 'normal vector' refer to in 3D graphics?

    • A) The vector pointing to the camera

    • B) A vector perpendicular to a surface

    • C) A vector defining an object's movement

    • D) A vector connecting two points

    • Answer: B

  17. Which geometry does not represent a shape in 3D graphics?

    • A) Point

    • B) Line

    • C) Plane

    • D) Surface

    • Answer: A

  18. What is the main purpose of transformations in computer graphics?

    • A) To change memory allocation

    • B) To simulate physics

    • C) To manipulate objects in space

    • D) To add textures

    • Answer: C

  19. Which of the following is true about ray tracing?

    • A) It is faster than rasterization

    • B) It simulates lighting effects accurately

    • C) It is a real-time rendering technique

    • D) It requires less computational power

    • Answer: B

  20. What type of graphics uses lines and shapes instead of pixels?

    • A) Bitmap graphics

    • B) Vector graphics

    • C) Raster graphics

    • D) Photorealistic graphics

    • Answer: B

These questions can be utilized for quizzing individuals on their knowledge of computer graphics.