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 $v$ from points $P = (1, 3)$ to $Q = (4, 1)$:
      - $v$ has components $(3, -2)$, derived from the calculation $Q - P$.
      - Movement from $P$ to $Q$ 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 - P$.

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

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

Vector Representations

  • Row vector representation:
      - $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 $a$ and $b$ are vectors, then:
      - $a + b$ is also a vector.
      - For a scalar $s$, $sa$ is a vector.

Vector Operations (Continued)

  • Subtracting vector $c$ from $a$ is equivalent to adding $a$ to $-c$:
      - $-c = (-1)c$.

Linear Combinations of Vectors

  • Defined as:
      - $v_1 ext{ ± } v_2 = (v_{1x} ext{ ± } v_{2x}, v_{1y} ext{ ± } v_{2y}, v_{1z} ext{ ± } v_{2z})$
      - $sv = (sv_x, sv_y, sv_z)$.

  • A linear combination of vectors $v_1, v_2, ext{…}, v_m$ is given by:
      - $w = a_1v_1 + a_2v_2 + ext{…} + a_mv_m$.

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

Affine and Convex Combinations

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

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

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

  • Example:
      - $0.3a + 0.7b$ is convex, but $1.8a - 0.8b$ is not.

Set of All Convex Combinations of Two or Three Vectors

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

  • A corresponding example illustrated.

Vector Magnitude and Unit Vectors

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

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

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

  • The unit vector aligning in the same direction as vector $a$ is denoted (if $|a|
    eq 0$).
      - The process of converting $a$ 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| ext{ } ext{ direction}$.

Vector Dot Product

  • The dot product for n-vectors $v$ and $w$:
      - $v ullet w = v_1w_1 + v_2w_2 + … + v_nw_n$.

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

Applications: Angle Between Two Vectors

  • Vectors represented:
      - $b = (|b| ext{ cos } heta_b, |b| ext{ sin } heta_b)$.
      - $c = (|c| ext{ cos } heta_c, |c| ext{ sin } heta_c)$.

  • The connection:
      - $b ullet c = |b| |c| ext{ cos }( heta_c - heta_b)$ where $ heta = heta_c - heta_b$ is the smaller angle between $b$ and $c$.
      - The relationship is given by:
      - $cos( heta) = rac{ ext{ }{ullet ext{ }} ullet ext{ }}$.

Angle Conditions

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

  • Vectors $b$ and $c$ are orthogonal if:
      - $b ullet c = 0$.

Standard Unit Vectors

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

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

  • Noteworthy property: the standard unit vectors are orthogonal.

Finding a 2D Perpendicular Vector

  • Given a vector $a = (a_x, a_y)$,
      - The vector perpendicular in a counterclockwise sense is:
        - $a^{ot} = (-a_y, a_x)$.
      - In the clockwise sense, it's $-a^{ot}$.

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

Properties of Perpendicular Vectors

  • Key properties:
      - $(a ext{ ± } b)^{ot} = a^{ot} ext{ ± } b^{ot}$.
      - $(sa)^{ot} = s(a^{ot})$.
      - $(a^{ot})^{ot} = -a$.
      - Inner product relationships:
        - $a^{ot} ullet b = -b^{ot} ullet a = -a_yb_x + a_xb_y$.
      - Orthogonality condition:
        - $a^{ot} ullet a = a ullet a^{ot} = 0$.
      - Magnitude property:
        - $|a^{ot}| = |a|$.

Orthogonal Projections and Distances from a Line

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

Answering the Projection Questions

  • Define $c = C - A$:
      - We can express $c$ as:
        - $c = Kv + Mv^{ot}$.

  • Analyzing through dot products:
      - $c ullet v = Kv ullet v + Mv^{ot} ullet v = K|v|^2$ gives:
        - $K = rac{c ullet v}{|v|^2}$ (projection of $c$ onto $v$).

  • Dot product with $v^{ot}$ provides:
      - $M = rac{c ullet v^{ot}}{|v|^2}$.

  • Answers to original questions include:
      - Distance: $|Mv^{ot}|$.
      - Point of intersection: $A + Kv$ or $C - Mv^{ot}$.

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 $r$ in 2D or 3D scenarios.

Reflection Mathematical Representation

  • Illustrated relationships:
      - $e = a - m$ and $r = e - m = a - 2m$.

  • For $m$:
      - $m = rac{(a ullet n)}{|n|^2}n = (a ullet n)n$; returns projection of $a$ onto vector $n$.

Vector Cross Product (3D Vectors Only)

  • Cross product defined as:
      - $a 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=iamp;jamp;k axamp;ayamp;az bxamp;byamp;bza imes b = \begin{vmatrix} i &amp; j &amp; k \ a_x &amp; a_y &amp; a_z \ b_x &amp; b_y &amp; b_z \end{vmatrix}.

Properties of Cross Product

  • Key properties include:
      - $i imes j = k$; $j imes k = i$; $k imes i = j$.
      - Antisymmetry: $a imes b = -b imes a$.
      - Distributivity: $a imes (b ext{ ± } c) = a imes b ext{ ± } a imes c$.
      - Scalar multiplication: $(sa) imes b = s(a imes b)$.
      - Non-valid associativity: $a imes (b imes c)
    eq (a imes b) imes c$.

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

Additional Cross Product Properties

  • Self dot product:
      - $a ullet (a imes b) = 0$.

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

  • Cross product also provides the area of the parallelogram formed by vectors $a$ and $b$.

  • Equals zero when $a$ and $b$ are collinear or one has length zero.

Geometric Interpretation of the Cross Product

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

Application: Finding the Normal to a Plane

  • Given three non-collinear points $A$, $B$, and $C$, we can determine a normal vector to the plane defined by these points:
      - Let $a = B - A$, $b = C - A$; the normal vector $n = a imes b$.
      - The opposite normal on the other side of the plane is $-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 ($O$) along with 3 mutually perpendicular unit vectors: $a$, $b$, and $c$.

Coordinate Frames (Continued)

  • A vector $v$ can be represented as:
      - $v = v_1a + v_2b + v_3c$.

  • A point $P$ from the origin can be expressed as:
      - $P - 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)$ is converted to $(x, y, z, 1)$.
        - A 2D point $(x, y)$ is converted to $(x, y, 0, 1)$.

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

Example: Cross Product Calculation

  • Let:
      - $A = (1, 2, 0)$
      - $B = (-2, 1, 3)$,
      - Compute:
      - $a = (1, 2, 0)$
      - $b = (-2, 1, 3)$
      - Compute $a imes b$:
      - Evaluate determinant:
       
      extdet=(iamp;jamp;k 1amp;2amp;0 2amp;1amp;3)ext{det} = \begin{pmatrix} i &amp; j &amp; k \ 1 &amp; 2 &amp; 0 \ -2 &amp; 1 &amp; 3 \end{pmatrix}
      - Calculating individual components:
      - $i(6 - 0) - j(3 - 0) + k(1 + 4)$ provides $6i - 3j + 5k$.

Example: Normal to Plane Calculation

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

  aimesb=2i+3j+ka imes b = -2i + 3j + k
  - Result: $c ullet 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.