Lecture5 Graphics
Lecture5 Graphics
INSTRUCTOR’S MATERIALS
PowerPoint Slides
MULTIMEDIA
Chapter - 4
Graphics
RANJAN PAREKH
PROPRIETARY MATERIAL. © 2013 The McGraw-Hill Companies, Inc. All rights reserved. No part of this PowerPoint slide may be displayed, reproduced or distributed in any
form or by any means, without the prior written permission of the publisher, or used beyond the limited distribution to teachers and educators permitted by McGraw-Hill for their
individual course preparation. If you are a student using this PowerPoint slide, you are using it without permission. 1
RANJAN PAREKH Principles of MULTIMEDIA, 2E © 2013 Tata McGraw-Hill Education
Contents
• Advantages of Graphics
• Components of a Graphics System
• 2D Coordinate Systems
• 2D Transformations
• Line Drawing Algorithms
• Circle Drawing Algorithms
• Filling and Clipping Algorithms
• 2D Modeling
• Curves and Splines
• Splines as Polynomials
Contents
• Linear Splines
• Quadratic Splines
• Cubic Splines
• Spline Properties
• Piecewise Splines
• Hermite Splines
• C-R Splines
• Cardinal Splines
• Bezier Splines
• B-Splines
• Spline Conversions
• Plotter
Contents
• 3D Graphics
• 3D Transformations
• Projection
• 3D Modeling
• Surface Characteristics
• Lights
• Graphics File Formats
• Fractals
• Quad Tree
• Graphics Software
Advantages of Graphics
• Overview
– Compact file size
– Adapt to varying magnification
– Suitability for animation
– Suitability for interactive applications
– Extensions for 3D graphics and animation
2D Coordinate System
• Overview
– X-axis
– Y-axis
– Origin
– Coordinates
– Measurement of angles
– Right-handed coordinate system
– Left-handed coordinate system
2D Transformations
• 2D Translation
– A point is translated to a new location by adding increments to its coordinates
– In matrix form Q = P + T
• 2D Scaling
– A point is scaled to a new point by multiplying its coordinates by a scalar
– In matrix form Q = S . P
– Scaling might be uniform or non-uniform
2D Transformations
• 2D Rotation
– A point can be rotated to a new location by angle θ about the origin
– In matrix form Q = R . P
– Let P(x1,y1) with polar coordinates (r, φ) rotate in a plane around
origin by angle θ in CCW direction to point Q(x2,y2) . Then
– Original coordinates :
– Substituting :
• Clipping algorithm
– For a point to be inside a rectangle, four inequalities to be satisfied
– If both endpoints of a line are inside, the entire line is inside
– If one endpoint is inside, the other outside, intersection to be computed
– If both intersections are outside line may or may not intersect
• Cohen-Sutherland algorithm
– Check whether line is entirely within clip rectangle
– If not, then check whether line is entirely outside
– If neither, then line is segmented into two at clip edge
– To determine intersection point, region codes are set
– Region codes at endpoints and intersection points determined
2D Modeling
• Basic Structures
– Point is a location in space without dimensions
– Straight line has single dimension : length
– Plane is a flat surface having two dimensions
– Three points forming a triangle always define a plane
– Planes can be combined to form objects
Splines as Polynomials
• Polynomials
– Splines are modeled using polynomials
– Polynomials are expressions constructed from variables and constants
– Polynomials involve addition, subtraction, multiplication and non-negative integer exponents
– A polynomial can be zero (0) or a sum of non-zero terms
– Each term consist of a constant (coefficient) multiplied by a variable
– Exponent of the variable is called its degree
– In general the n-th degree polynomial is written as
Splines as Polynomials
• Graphs of polynomials
– A polynomial function in one variable can be represented by a graph
– Graph of a zero polynomial is the X-axis
– Graph of degree zero polynomial is a line parallel to X-axis. Uniquely specified by one point
– Graph of degree 1 polynomial is a straight line with a slope and intercept. Specified by two points
– Graph of degree 2 polynomial is a parabola. Specified by three points
– Graph of degree 3 polynomial is a cubic curve. Specified by four points. Has one inflection point.
– Graphs of degree 4 or higher polynomials have multiple inflection points
Splines as Polynomials
• Polynomial equation
– Polynomial equations in 2 variables can be represented in 3 ways : explicit, implicit, parametric
– Explicit : one variable is expressed as a function of another i.e. y = f(x)
– Implicit : equation is expressed as joint function of multiple variables i.e. f(x,y) = 0
– Parametric : each variable is expressed as a function of a third variable i.e. x = f1(t), y = f2(t)
Splines as Polynomials
• Parametric representations
– Variables x and y can be changed independent of each other
– More complex curves can be represented as x and y are not constrained by a single relation
– Since t is an arbitrary variable user can choose value of t to reduce complexities
– In most cases value of t is chosen to be between 0 and 1
– Parametric equations are represented graphically using 3 graphs
– First two (x-t, y-t) are referred to as parametric domain, third (x-y) is called spatial domain
– In some cases values may need to be converted from one domain to the other
Linear Splines
• Equation of Linear Spline given two given points
– Let given points be P1 and P2
– Choose starting equation
– Substitute given conditions in starting equation
– Write in matrix form Y = C.A
– A : coefficient matrix, C : constraint matrix
– Solve for A : A = C-1.Y
– Substitute values in starting equation
Linear Splines
• Equation of Linear Spline given a point and a slope
– Let given points be P1 and slope be s
– Choose starting equation
– Calculate derivative of starting equation
– Substitute given conditions in starting equation
– Substitute given slope in derivative equation
– Write in matrix form Y = C.A
– Solve for A : A = C-1.Y
– Substitute values in starting equation
Linear Splines
• Equation of Linear Spline in parametric form
– Let given points be P0 and P1
– Choose starting equation
– Choose t = 0 at start point and t = 1 at end point
– Substitute values of t in starting equation
– Write in matrix form G = C.A (G : geometry matrix)
– -1
Solve for A : A = C .G = B.G (A : coefficient matrix, B : basis matrix)
– Substitute values in starting equation
– Note : Here we put P(0) = P0 and P(1) = P1
Quadratic Splines
• Equation of Quadratic Spline given three points
– Let given points be P1 , P2 and P3
– Choose starting equation
– Substitute given conditions in starting equation
– Write in matrix form Y = C.A
– Solve for A : A = C-1.Y
– Substitute values in starting equation
Quadratic Splines
• Equation of Quadratic Spline in parametric form
– Let given points be P0 , P1 and P2
– Choose starting equation
– Choose t = 0 at start point and t = 1 at end point
– Choose t = k (0 ≤ k ≤ 1) at middle point
– Substitute values in starting equation
– Write in matrix form G = C.A
– Solve for A : A = B.G
– Substitute values in starting equation
Cubic Splines
• Equation of Cubic Spline given four points
– Let given points be P1 , P2 , P3 and P4
– Choose starting equation
– Substitute given points in starting equation
– Write in matrix form Y = C.A
– Solve : A = C-1.Y
– Substitute values in starting equation
Cubic Splines
• Equation of Cubic Spline in parametric form
– Let given points be P0 , P1 , P2 and P3
– Choose starting equation
– Choose t = 0 at start point and t = 1 at end point
– Choose t = m and t = n at middle points
– Substitute values in starting equation
– Write in matrix form G = C.A
– Solve for A : A = B.G
– Substitute values in starting equation
Spline Properties
• Blending Functions (BF)
– BFs characterize a specific curve type, independent of control points
– Consider 4 masses L0, L1, L2, L3 placed at control point locations P0, P1, P2, P3
– Any point P on spline is the center of mass
– As each mass varies as a function of parameter t ( 0 ≤ t ≤ 1), P traces out the curve
– These functions are called Blending Functions (BFs) : L0, L1, L2, L3
– Then L = [L0, L1, L2, L3] is called blending function matrix
– Additional constraint : ∑Li = 1 , hence P = L.G
– Also we know that P = T.A and A = B.G
– Hence P = T.A = T.(B.G) = (T.B).G = L.G
Spline Properties
• Blending Functions (BF)
– BFs can be represented as functions of parameter t
– They can be plotted as curves by varying t from 0 to 1
– At each control point only one component of L is 1, others 0
– For a linear spline basis matrix is B
– Blending function matrix is L
Spline Properties
• Blending Functions (BF)
– BFs can be represented as functions of parameter t
– They can be plotted as curves by varying t from 0 to 1
– At each control point only one component of L is 1,
others 0
– For a quadratic curve basis matrix B is given by
Spline Properties
• Blending Functions (BF)
– For a cubic curve basis matrix B is given by
Spline Properties
• Critical Points
– Minimum
– Maximum
Piecewise Splines
• Piecewise Cubic splines
– Complex curves cannot be appropriately modeled using cubic splines
– Higher degree splines too sensitive to slight changes in control points
– Such curves modeled by multiple cubic splines joined end to end
– Consider 3 segments of curve passing through 4 given points
– Choose starting equations for the three segments
– 12 equations required to solve all unknowns
Piecewise Splines
• C0 continuity conditions
– Different curve segments should physically meet at their common points
– A passes through P1 and P2
– B passes through P2 and P3
– C passes through P3 and P4
– If S(k) denotes segment S passing through point Pk we have 6 equations
Piecewise Splines
• C1 continuity conditions
– Different curve segments should have same slopes at their common points
– Take derivatives of curve equations
– Slope of A at P2 = Slope of B at P2
– Slope of B at P3 = Slope of C at P3
– If S’(k) denotes slope of segment S at point Pk we have 2 equations
Piecewise Splines
• C2 continuity conditions
– Different curve segments should have same curvatures at their common points
– Take second derivatives of curve equations
– Curvature of A at P2 = Curvature of B at P2
– Curvature of B at P3 = Curvature of C at P3
– If S’’(k) denotes curvature of segment S at point Pk we have 2 equations
Piecewise Splines
• End-point conditions
– Start and end point slopes of the curves need to be known
– Let slopes be s1 and s2 respectively
– Insert slope values in derivative equations
– If S’(k) denotes slope of segment S at point Pk we have 2 equations
Piecewise Splines
• Final step
– Write all 12 equations in matrix form Y = C.A
– Solve for A
– Substitute in starting equations
Hermite Splines
• Equation of Hermite Spline given two points and two slopes
s2
– Let given points be P1 , P2 and slopes be s1, s2
– Choose starting equation, calculate derivative of starting equation
– Substitute given conditions in starting equation P2(x2, y2)
– Substitute given conditions in derivative equation s1
– Write all equations in matrix form Y = C.A
P1(x1, y1)
– Solve for A
– Substitute in starting equation
1 x1 x1
2
x1 a y1
3
x2 b y2
2 3
1 x2 x2
2
0 1 2x1 3x1 c s1
0 1 2x2 3x2 d s2
2
1
y ' b 2cx 3dx 2
a 1 x 1 x 1
2
x 1
3
y1
b 1 x x2 y2
2 3
2 x2
s1 b 2cx1 3dx1 c 0 1 2x 3x 2 s1
2
1 1
s2 b 2cx2 3dx2 0 1 2x2 3x22 s2
2
d
Hermite Splines
• Equation of Hermite Spline in parametric form
– Let given points be P0 and P1 and let slopes be P0’ and P1’
– Choose starting equation
– Calculate derivative of starting equation
– Substitute P(0) at t=0 and P(1) at t=1 in starting equation
– Substitute P’(0) at t=0 and P’(1) at t=1 in derivative equation
– Write equations in matrix form Y = C.A
– Solve : A = C-1.Y = B.Y
– Substitute in starting equation
– Note : Here P(0) = P0, P(1) = P1, P’(0) = P0’ , P’(1) = P1’
Hermite Splines
• Equation of Hermite Spline in parametric form
– Basis Matrix B
– Blending Function Matrix L = T.B
– Blending Functions : L0, L1, L2, L3
C-R Splines
• Equation of C-R Spline in parametric form
– Let given points be P1 and P2 through which the curve goes
– Slopes are calculated from a previous point P0 and next point P3
– Tangent at P1 is equal in slope to line joining P0 and P2
– Tangent at P2 is equal in slope to line joining P1 and P3
– Choose starting equation and calculate derivative equation
– Substitute given points in starting equation
– Substitute slopes in derivative equation
– Note : Here P(0) = P1 , P(1) = P2 , P’(0) = P1’ = T1 , P’(1) = P2’ = T2
– Eliminate P1 and P2 and simplify
C-R Splines
• Equation of C-R Spline in parametric form
– Write all equations in proper order
– Write equations in matrix form G = C.A
– Solve for A
– Substitute in starting equations
C-R Splines
• Equation of C-R Spline in parametric form
– Basis Matrix B
– Blending Function Matrix L = T.B
– Blending functions : L0, L1, L2, L3
Cardinal Splines
• Equation of Cardinal Spline in parametric form
– More generalized form of C-R spline
– Tangent definitions involve a shape parameter s
– Values of s < 0.5 produce tighter curves
– Values of s > 0.5 produce looser curves
– Value of s = 0.5 produce C-R spline
– Four given points P0 , P1 , P2 and P3
– Choose starting equation
– Calculate derivative of starting equation
– Substitute given points in starting equation
– Substitute slopes in derivative equation
– Equate tangents from derivative equations with those from definitions
Cardinal Splines
• Equation of Cardinal Spline in parametric form
– Eliminate P1 and P2 and simplify
– Write all equations together
– Write in matrix form G = C.A
– Solve for A
– Substitute in starting equation
s = 0.9
CONTENTS INSTRUCTOR'S MATERIALS Chapter – 4 : 46
RANJAN PAREKH Principles of MULTIMEDIA, 2E © 2013 Tata McGraw-Hill Education
Bezier Splines
• Introduction
– Hybrid spline which passes through first and last control points only
– Line joining first CP and next CP is tangential to the curve
– Line joining last CP and previous CP is tangential to the curve
– Blending functions are derived from Bernstein polynomials
– nC is the no. of ways in which k items can be selected out of n items
k
– Bezier curve of degree n is associated with (n+1) control points
– Entirely contained within convex hull formed by joining CPs
Bezier Splines
• Quadratic Bezier spline
– Quadratic Bezier curve is associated with 3 control points
– Let given points be P0 , P1 , P2
– Blending functions are derived by putting n=2 in Bernstein polynomials
– BF matrix L = T.B, where B is the basis matrix
– Parametric equation is given by P = T.B.G
Bezier Splines
• Cubic Bezier spline
– Cubic Bezier curve is associated with 4 control points
– Let given points be P0 , P1 , P2 and P3
– BFs are derived by putting n=3 in Bernstein polynomials
– BF matrix L = T.B, where B is the basis matrix
– Parametric equation is given by P = T.B.G
Bezier Splines
• Sub-division of Bezier splines
– Bezier curves may be sub-divided using de Casteljau algorithm
– Consider four control points with subscript (0)
– Equation of curve written in terms of BFs and CPs
– Choose fraction for sub-division k
– Curve is divided in ratio k : (1 – k)
– Coordinates of a point R dividing a line in ratio m : n
– Compute new control points
Bezier Splines
• Sub-division of Bezier splines
– Derive equations of component Bezier curves
– First curve C1 : P0(0), P0(1), P0(2), P0(3)
– Valid for t = {0, k}
– Second curve C2 : P0(3), P1(2), P2(1), P3(0)
– Valid for t = {k, 1}
Spline Conversions
• Overview
– A spline of one type can be expressed as a spline of another type
– Since the spline physically remains the same, its equation is unaltered
– However the basis matrix and control points change
– Suppose a C-R spline needs to be converted to a Bezier spline
– Two equations are equivalent, hence can be equated
– Basis matrix of both splines are known
– Control points of C-R spline are also known
– Control points of Bezier spline are found out
B-Splines
• Introduction
– Limitations of Bezier splines : no local control, no. of control points dependent on degree of curve
– B-splines are designed to overcome limitations of Bezier splines
– Consists of multiple curve segments having continuity at join points
– B-splines are truly approximating i.e. in general they do not go through any of the control points
– Two parameters : d (related to degree), n (related to number of control points)
– Degree of curve = (d – 1) , number of control points = (n + 1)
– Blending functions are computed using Cox de Boor algorithm
– Join points between segments are called knots, knot values stored in a knot vector
– If knot values are equally spaced resulting curve is called uniform B-spline, otherwise non-uniform
– If knot values are repeated, resulting curve is called open uniform
– A rational B-spline is a ratio of two spline functions , used to represent conic sections
– A non-uniform rational B-spline (NURBS) is extensively used in graphics for modeling shapes
B-Splines
• Linear Uniform B-spline
– Specify values of parameters d and n : say d = 2, n = 2
– Degree of curve : d – 1 = 1
– Number of control points : n + 1 = 3
– Number of blending functions : n + 1 = 3
– Number of curve segments : d + n = 4
– Number of elements in knot vector : d + n + 1 = 5
– Let curve segments be : A, B, C, D
– Let knot vector be : t = {tk}k=0 to 4 = [t0, t1, t2, t3, t4] = [0, 1, 2, 3, 4] (say)
– Let BFs be written as Bk,d : B0,2, B1,2, B2,2
– Here k ranges over knot-vector elements i.e. k = {0, …, 4} but k > 2 are not relevant
– Here d ranges over the degree values i.e. d = {1, 2}
– Blending functions are computed using Cox de Boor algorithm
– Equation of curve : P(t) = P0.B0,2 + P1.B1,2 + P2.B2,2
B-Splines
• Linear Uniform B-spline
– Consider : d = 1, k = {0, 1, 2, 3, 4}
– k = 0 : B0,1
– k = 1 : B1,1
– k = 2 : B2,1
– k = 3 : B3,1
– k = 4 : B4,1
– Consider : d = 2, k = {0, 1, 2, 3, 4}
– k = 0 : B0,2 = {(t – t0)/(t1 – t0)}.B0,1 + {(t2 – t)/(t2 – t1)}.B1,1 = (t – 0).B0,1 + (2 – t).B1,1
– k = 1 : B1,2 = {(t – t1)/(t2 – t1)}.B1,1 + {(t3 – t)/(t3 – t2)}.B2,1 = (t – 1).B1,1 + (3 – t).B2,1
– k = 2 : B2,2 = {(t – t2)/(t3 – t2)}.B2,1 + {(t4 – t)/(t4 – t3)}.B3,1 = (t – 2).B2,1 + (4 – t).B3,1
– k = 3 : B3,2 = {(t – t3)/(t4 – t3)}.B3,1 + {(t5 – t)/(t5 – t4)}.B4,1 = (t – 3).B3,1 + (5 – t).B4,1
– k = 4 : B4,2 = {(t – t4)/(t5 – t4)}.B4,1 + {(t6 – t)/(t6 – t5)}.B5,1 = (t – 4).B4,1 + (6 – t).B5,1
B-Splines
• Linear Uniform B-spline
– First segment A : k = 0 i.e. t0 ≤ t < t1
– Consider : d = 1, k = {0, 1, 2, 3, 4}
– k = 0 : B0,1 = 1
– k = 1 : B1,1 = 0
– k = 2 : B2,1 = 0
– k = 3 : B3,1 = 0
– k = 4 : B4,1 = 0
– Consider : d = 2, k = {0, 1, 2, 3, 4}
– k = 0 : B0,2 = (t – 0).B0,1 + (2 – t).B1,1 = t+0=t
– k = 1 : B1,2 = (t – 1).B1,1 + (3 – t).B2,1 = 0+0=0
– k = 2 : B2,2 = (t – 2).B2,1 + (4 – t).B3,1 = 0+0=0
– k = 3 : B3,2 = (t – 3).B3,1 + (5 – t).B4,1 = 0+0=0
– k = 4 : B4,2 = (t – 4).B4,1 + (6 – t).B5,1 = 0+0=0
B-Splines
• Linear Uniform B-spline
– Second segment B : k = 1 i.e. t1 ≤ t < t2
– Consider : d = 1, k = {0, 1, 2, 3, 4}
– k = 0 : B0,1 = 0
– k = 1 : B1,1 = 1
– k = 2 : B2,1 = 0
– k = 3 : B3,1 = 0
– k = 4 : B4,1 = 0
– Consider : d = 2, k = {0, 1, 2, 3, 4}
– k = 0 : B0,2 = (t – 0).B0,1 + (2 – t).B1,1 = 0 + (2 – t) = 2 – t
– k = 1 : B1,2 = (t – 1).B1,1 + (3 – t).B2,1 = (t – 1) + 0 = t – 1
– k = 2 : B2,2 = (t – 2).B2,1 + (4 – t).B3,1 = 0+0=0
– k = 3 : B3,2 = (t – 3).B3,1 + (5 – t).B4,1 = 0+0=0
– k = 4 : B4,2 = (t – 4).B4,1 + (6 – t).B5,1 = 0+0=0
B-Splines
• Linear Uniform B-spline
– Fourth segment D: k = 3 i.e. t3 ≤ t < t4
– Consider : d = 1, k = {0, 1, 2, 3, 4}
– k = 0 : B0,1 = 0
– k = 1 : B1,1 = 0
– k = 2 : B2,1 = 0
– k = 3 : B3,1 = 1
– k = 4 : B4,1 = 0
– Consider : d = 2, k = {0, 1, 2, 3, 4}
– k = 0 : B0,2 = (t – 0).B0,1 + (2 – t).B1,1 = 0+0=0
– k = 1 : B1,2 = (t – 1).B1,1 + (3 – t).B2,1 = 0+0=0
– k = 2 : B2,2 = (t – 2).B2,1 + (4 – t).B3,1 = 0 + (4 – t) = 4 – t
– k = 3 : B3,2 = (t – 3).B3,1 + (5 – t).B4,1 = (t – 3) + 0 = t – 3
– k = 4 : B4,2 = (t – 4).B4,1 + (6 – t).B5,1 = 0+0=0
B-Splines
• Linear Uniform B-spline
– Tabulate non-zero Bk,2 blending functions for each segment
– A : B0,2(A) = t
– B : B0,2(B) = 2 – t, B1,2(B) = t – 1
– C : B1,2(C) = 3 – t, B2,2(C) = t – 2
– D : B2,2(D) = 4 – t, B3,2(D) = t – 3
B-Splines
• Linear Uniform B-spline
– Each BF has same shape but shifted towards the right by 1 than previous one
– Each BF can be obtained from the previous by substituting t with (t – 1)
– Unlike interpolating splines where each BF ranges over entire value of t, here BFs are restricted over
a subset of the entire range
B-Splines
• Linear Uniform B-spline
– Equation of curve : P(t) = P0.B0,2 + P1.B1,2 + P2.B2,2
– Here : P(t) = Po.{B0,2(A) + B0,2(B)} + P1.{B1,2(B) + B1,2(C)} + P2.{B2,2(C) + B2,2(D)}
– P(t) = {Po.B0,2(A)} + {Po.B0,2(B) + P1.B1,2(B) }+ {P1.B1,2(C) + P2.B2,2(C)} + P2.B2,2(D)}
– P(t) = Po.t, t0 ≤ t < t1
P0.(2 – t) + P1.(t – 1), t1 ≤ t < t2
P1.(3 – t) + P2.(t – 2), t2 ≤ t < t3
P2.(4 – t), t3 ≤ t < t4
– Considering arbitrary CPs (0,1), (2,2), (5,0) curve is plotted as shown
– Local control : each segment is associated with a subset of the total number of CPs
– Thus changing a single CP, say P1, affects only segments B and C, not entire curve
B-Splines
• Quadratic Uniform B-spline (contd.)
– Tabulate non-zero Bk,3 BFs for each segment
– A : B0,3 = t2/2
– B : B0,3 = (1/2)(t)(2 – t) + (1/2)(3 – t)(t – 1), B1,3 = (1/2)(t – 1)(t – 1)
– C : B0,3 = (1/2)(3 – t)(3 – t) , B1,3 = (1/2)(t – 1)(3 – t) + (1/2)(4 – t)(t – 2), B2,3 = (1/2)(t – 2)(t – 2)
– D : B1,3 = (1/2)(4 – t)(4 – t) , B2,3 = (1/2)(t – 2)(4 – t) + (1/2)(5 – t)(t – 3), B3,3 = (1/2)(t – 3)(t – 3)
– E : B2,3 = (1/2)(5 – t)(5 – t) , B3,3 = (1/2)(t – 3)(5 – t) + (1/2)(6 – t)(t – 4), B4,3 = (1/2)(t – 4)(t – 4)
– F : B3,3 = (1/2)(6 – t)(6 – t), B4,3 = (1/2)(t – 4)(6 – t) + (1/2)(7 – t)(t – 5), B5,3 = (1/2)(t – 5)(t – 5)
B-Splines
• Quadratic Uniform B-spline
– BFs are uniform in shape but shifted to the right by 1
– Each BF obtained from previous by substituting t by (t – 1)
B-Splines
• Quadratic Uniform B-spline
– Equation of curve : P(t) = P0.B0,3 + P1.B1,3 + P2.B2,3 + P3.B3,3
– Here : P(t) = Po.{B0,3(A) + B0,3(B) + B0,3(C)} +
P1.{B1,3(B) + B1,3(C) + B1,3(D)} +
P2.{B2,3(C) + B2,3(D) + B2,3(E)} +
P3.{B3,3(D) + B3,3(E) + B3,3(F)}
– P(t) = {Po.B0,3(A)} +
{Po.B0,3(B) + P1.B1,3(B)} +
{P0.B0,3(C) + P1.B1,3(C) + P2.B2,3(C)} +
{P1.B1,3(D) + P2.B2,3(D) + P3.B3,3(D)} +
{P2.B2,3(E) + P3.B3,3(E)} +
P3.B3,3(F)
B-Splines
• Quadratic Uniform B-spline
– P(t) = Po. t2/2 , t0 ≤ t < t1
Po.{(1/2)(t)(2 – t) + (1/2)(3 – t)(t – 1)} + P1.{(1/2)(t – 1)(t – 1)}, t1 ≤ t < t2
P0. {(1/2)(3 – t)(3 – t)} + P1.{(1/2)(t – 1)(3 – t) + (1/2)(4 – t)(t – 2)} + P2.{(1/2)(t – 2)(t – 2)}, t2 ≤ t < t3
P1.{(1/2)(4 – t)(4 – t)} + P2.{(1/2)(t – 2)(4 – t) + (1/2)(5 – t)(t – 3)} + P3.{(1/2)(t – 3)(t – 3)}, t3 ≤ t < t4
P2.{(1/2)(5 – t)(5 – t)} + P3.{(1/2)(t – 3)(5 – t) + (1/2)(6 – t)(t – 4)}, t4 ≤ t < t5
P3.{(1/2)(6 – t)(6 – t)}, t5 ≤ t < t6
– Considering arbitrary CPs (2,0), (4,1), (6,5), (8,-1) curve is plotted as shown
B-Splines
• Quadratic Uniform B-spline
– Local control : on changing locations of one CP, only part of the spline is affected
– On changing the first CP, P0, to (1,2) the first 3 segments are affected only
– P(t) = Po.{B0,3(A) + B0,3(B) + B0,3(C)} + P1.{B1,3(B) + B1,3(C) + B1,3(D)} +
P2.{B2,3(C) + B2,3(D) + B2,3(E)} + P3.{B3,3(D) + B3,3(E) + B3,3(F)}
B-Splines
• Quadratic Non-Uniform B-spline
– Here a non-uniform knot vector is used
– BFs are clustered at places where knot vector elements are close together
– B-spline curve is drawn more towards the corresponding control points
B-Splines
• Quadratic Open Uniform B-spline
– Knot vector is uniform except at the ends where it is repeated d times
– Repeated values are referred to as multiplicity
– Forces the B-spline to pass through terminal points
– Specify values of parameters d and n : say d = 3, n = 3
– Let curve segments be : A, B, C, D, E, F
– Let BFs be : B0,3, B1,3, B2,3, B3,3
– Let knot vector be : t = [t0, t1, t2, t3, t4, t5, t6] = [1, 1, 1, 2, 3, 3, 3] (say)
– Blending functions are computed using Cox de Boor algorithm
– Division by zero is considered as zero
B-Splines
• Quadratic Open Uniform B-spline
– Some of the BFs are zero
B-Splines
• Quadratic Open Uniform B-spline
– Considering arbitrary CPs (2,0), (4,1), (6,5), (8,-1) curve is plotted as shown
– On changing the first CP, P0, to (1,2) the first segment is affected only
B-Splines
• Rational B-spline
– A rational B-spline is a ratio of two spline functions
– They provide exact representations of conic sections
– Generated by using d = 3, n = 2, and an open knot vector t = [0,0,0,1,1,1] , three CPs : P0, P1, P2
– Putting ω0 = ω2 = 1 and changing the value of ω1 we obtain the following :
B-Splines
• Non-Uniform Rational B-spline (NURBS)
– Provides greater flexibility in changing shape of the curve
– Two parameters : weight and knot spacing
– Curve is pulled towards corresponding CPs on increasing weight or decreasing knot spacing
Plotter
• Overview
– Plotters are devices used to produce hardcopy versions of vector graphics
– Pen plotters include a microprocessor that accepts commands from an application program
– Flatbed plotters move a pen along X and Y directions on a flat sheet of paper
– Drum plotters move paper along a rotating drum and pen moves along drum axis
– Electrostatic plotters uses electrostatic charges to put toner onto paper
3D Graphics
• Introduction
– Modeling involves defining the structure of a 3D graphical object
– Texture mapping involves applying textures over the 3D model to impart realistic appearances
– Lighting involves placing lights within the 3D scene
– Camera placements and movements determine how the scene looks to the user
– Animating the objects involves creating key frames and tweening
– Rendering produces final output file
3D Graphics
• Coordinate systems
– To locate objects in space a 3D coordinate system is used
– Involves three mutually perpendicular axes X, Y, Z
– Coordinate systems can be left-handed or right-handed (default)
– Rotating a coordinate system does not change its orientation
– Positive direction of rotation is counter-clockwise (CCW)
– Coordinates having 3 components define points in space
3D Graphics
• Local vs. global coordinates
– A universal or global coordinate system is used for absolute positioning in 3D space
– Local coordinate systems are attached to each object
– Local origin act as pivot point during rotation
– Final transformations depend on choice of local origin
– Transformations of a point or object may be described using a transformation matrix (TM)
– During object creation a default transformation matrix is associated with it
3D Graphics
• Homogeneous coordinates
– A point P(x1, y1, z1) is to be translated to point Q(x2, y2, z2)
– Translation amounts : tx = x2 – x1, ty = y2 – y1, tz = z2 – z1
– Let translation matrix be T = [tx ty tz]T
– Then transformation equation : Q = T + P
– However it is more convenient to express translation as a multiplication operation
– In this case : Q = T.P. Also inverse transformation can be calculated using inverse matrix T-1
– Homogeneous coordinate system : alternative coordinate system of the form (x,y,r) or (x,y,z,r), r ≠ 0
– For 2D planes, homogeneous coordinates of (x, y, r) implies Cartesian coordinates of (x/r, y/r)
– For 3D space, homogeneous coordinates of (x, y, z, r) implies Cartesian coordinates of (x/r, y/r, z/r)
– Thus (1,2,3), (2,4,6), (-1,-2,-3) are all homogeneous coordinates of the same point (1/3, 2/3) in 2D
– Also (1, 2, -1, 5) and (1/2, 1, -1/2, 5/2) represent the same point (1/5, 2/5, -1/5) in 3D space
– Homogeneous coordinates of the form (x, y, 0) represent a point at infinity in direction of (x, y)
3D Transformations
• 3D Translation
– Translation operation : Q = T.P, where T is called Translation matrix
– For example a point P(2,2,2) when translated by amounts (1, -2, 3) is located to Q(3, 0, 5)
– An entire object can be translated by re-locating each vertex and rebuilding object at new location
– A cube having center at origin and vertices at (-1,1,1), (1,1,1), (1,-1,1), (-1,-1,1), (-1,1,-1), (1,1,-1), (1,-1,-
1), (-1,-1,-1) can be represented by matrix C
– The effect of translating it by (-2, -1, 3) is shown below
3D Transformations
• 3D Scaling
– A point P is scaled to Q by multiplying with a Scaling matrix : Q=S.P
– For example a point P(2,2,2) when scaled by amounts (3,2,-1) is located to Q(6,4,-2)
– An entire object can be scaled by scaling each vertex and rebuilding object at new location
– Effect of scaling cube C by (2,2,2) is shown below
3D Transformations
• 3D Scaling
– By default scaling occurs from center of cube outwards
– The cube C can also be scaled with respect to a fixed point
– The cube is first translated so that fixed point coincides with origin, scaled at origin and reverse
translated back to original location
– Let (xf, yf, zf) be the fixed point
– LetT1 be the forward translation matrix, S the scaling matrix and T1’ be reverse translation matrix
– Composite transformation matrix T = T1’.S.T1
– Transformed coordinates D = T.C
3D Transformations
• 3D Rotation
– Rotation matrices for rotation around a principal axis (X, Y or Z) by angle θ
– Rotation is considered positive when in CCW direction
– An entire object is rotated by rotating each of its vertices
3D Transformations
• 3D Rotation
– Rotation can also be around an arbitrary line (axis of rotation)
– Step 1 : Translate axis of rotation to origin so that one of its points coincide with origin
3D Transformations
• 3D Rotation
– Step 2 : Rotate line by angle α about X-axis so that it lies on X-Z plane
3D Transformations
• 3D Rotation
– Step 3 : Rotate line by angle φ about Y-axis so that it coincides with Z-axis
3D Transformations
• 3D Rotation
– Step 4 : Rotate point P by specified angle θ about Z-axis
– Rotation matrix : R3
3D Transformations
• Reflection
– Reflection about a plane reverses the coordinate value along axis perpendicular to the plane
– Reflection matrices along principal axes X, Y and Z are given below
– Reflection of an entire object is produced by reflection of each of its vertices
– Reflection can be viewed as conversion between left-handed and right-handed coordinate systems
3D Transformations
• Shear
– Involves changing coordinate value along one axis by adding an amount proportional to another
– Shear along X-axis can be parallel to (a) Z=0 plane (top & bottom faces)
– Shear along X-axis can be parallel to (b) Y=0 plane (front & back faces)
3D Transformations
• Shear
– Shear along Y-axis can be (a) parallel to Z = 0 plane (top & bottom faces)
– Shear along Y-axis can be (b) parallel to X = 0 plane (left & right faces)
– Shear along Z-axis can be (a) parallel to X = 0 plane (left & right faces)
– Shear along Z-axis can be (b) parallel to Y = 0 plane (front & back faces)
1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0
0 1 a 0 a 1 0 0 0 1 0 0 0 1 0 0
SYZ SYX S ZX S ZY
0 0 1 0 0 0 1 0 a 0 1 0 0 a 1 0
0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1
Projection
• Introduction
– Projection : used to map a 3D object to a 2D viewing plane
– Projection can be of two types : parallel and perspective
– Parallel projection : projection lines are parallel to each other
– Parallel projection can be of 2 types : orthographic and oblique
– Parallel orthographic projection : projection lines are perpendicular to view plane
– Parallel oblique projection : projection lines are not perpendicular to view plane
– Parallel projection preserves relative proportions of 3D objects but does not produce realistic views
– Perspective : projection lines appear to converge to a point called Projection Reference Point (PRP)
– Perspective projection produces realistic views of 3D objects but does not preserve relative
proportions
PRP
X’ Y’
X Y
Projection
• Introduction
– Parallel orthographic projection can be of 2 types : multi-view and axonometric
– Parallel orthographic multi-view projection : projection lines parallel to principal planes
– Such views are called top, side and front views, and display only one face of the object
– Used in engineering and architectural drawings as length and angles can be accurately measured
– Parallel orthographic axonometric projection : projection lines not parallel to principal planes
– More than one face of the object can be viewed
– Can be either isometric, dimetric or trimetric
Projection
• Multi-view projection
– In multi-view projection, projection lines are parallel to x=0, y=0, z=0 planes
– If view plane coincides with principal planes then projection matrices are as shown
– Projection matrix for z=k plane is derived by translating plane to z=0, using projection matrix for z=0
and reverse translating back to original position
Projection
• Axonometric projection
– For axonometric projection following steps are used :
– The normal to view-plane is translated so that one end coincides with origin (T1)
– Normal is rotated by angle α around X-axis so that it lies on X-Z plane (R1)
– Normal is rotated by angle -φ about Y-axis so that it coincides with Z-axis (R2)
– Project on z=0 plane (Pz)
– Apply reverse rotations and translation (R2’, R1’, T1’)
– Calculate composite transformation matrix (T)
Projection
• Foreshortening factor
– In general axonometric projection can consist of following steps :
– Rotate by angle α around X-axis so that it lies on X-Z plane (R1)
– Rotate by angle φ about Y-axis so that it coincides with Z-axis (R2)
– Project on z=0 plane (Pz)
– Combined transformation matrix T = Pz*R2*R1
Projection
• Foreshortening factor
– Now consider a vector P whose three components along principal axes are a, b, c
– Hence the component vectors are : Px = (a,0,0), Py = (o,b,o), Pz = (o,o,c)
– Multiplying transformation matrix T with each component we get Qx, Qy, Qz
– Original lengths of vectors : LPx = a, LPy = b, LPz = c
– Let modified lengths be LQx , LQy, LQz
– Foreshortening factor : ratio of modified length to original length : LQx/LPx, LQy/LPy, LQz/LPz
– Note : these factors are independent of a, b, c
Projection
• Dimetric & Isometric projections
– Foreshortening factor along each axis : ffx, ffy, ffz
– If all three factors are unequal : Trimetric projection
– If α, φ = ± 45°, ± 90°, ± 135°, then two of the factors are equal to each other : Dimetric projection
– For example putting α = 45°, φ = -135°, we get ffx = -1/√2, ffy = ffz = √3/2
– Again if α = 90°, φ = 45°, ffx = ffy = 1/√2, ffz = 1
– If α = ± 45°, φ = ± 35.264°, then all three factors are equal to each other : Isometric projection
– For example putting α = 45°, φ = -35.265°, we get ffx = ffy = ffz = √(2/3) = 0.8165
Projection
• Oblique projection
– Oblique projection matrix of a point on z=0 plane
– Projection is at an angle α to the plane and angle φ to horizontal
– Let P(xp,yp) be oblique projection point of C(x,y,z) on plane z=0
– Let R(x,y) be the orthographic projection point of C
– Let L be length of PR, and z be the length of CR
Projection
• Oblique projection
– Common choices for φ are 30° and 45°
– Common choices for α are arctan(1) = 45° and arctan(2) = 63.4°
– For α = 45° projection views are called cavalier
– Here all lines perpendicular to view-plane have lengths same as original, since L = z/tan(45°) = z
– For α = 63.4° projection views are called cabinet
– Here all lines perpendicular to view-plane have lengths half as original, since L = z/tan(63.4°) = z/2
Projection
• Perspective projection
– Projection lines appear to converge to a point beyond the view-plane
– Convergence point is called Projection Reference Point (PRP) or center of projection (COP)
– Perspective projection matrix of a point on z=k plane perpendicular to Z-axis is calculated as follows
– The PRP is located along the Z-axis at (0, 0, zr)
– Let P(xp, yp, zp) be projection point of A(x, y, z) on plane z=k plane
– Let Q(x’, y’, z’) be any point on the projection line
Projection
• Perspective projection
– Location of Q can be described by a set of parametric equations
– Parametric Equations : x’ = x – xt, y’ = y – yt, z’ = z – (z – zr)t, where 0 ≤ t ≤ 1
– For t = 0, x’ = x, y’ = y, z’ = z : indicates location of A
– For t = 1, x’ = 0, y’ = 0, z’ = zr : indicates location of R
– On view-plane z’ = k, hence t = (k – z)/(zr – z)
– Substituting this value of t in parametric equations we obtain the projection point coordinates
– Here : xp = x(zr – k)/(zr – z), yp = y(zr – k)/(zr – z), zp = k
Projection
• Perspective projection
– Thus perspective projection matrix is as shown below :
– If PRP is at origin, zr = 0.
– Projection coordinates are : xp = x(k)/(z), yp = y(k)/(z), zp = k
3D Modeling
• Geometric primitives
– Pre-defined 3D objects widely used 3D graphics and animation packages
– Examples are cube, cylinder, torus, sphere, cone, pyramid
– To create primitives parameters like height, width, radius etc. need to be specified
– After primitives are created they can be transformed i.e. translated, rotated, scaled
3D Modeling
• Geometric modifiers
– Properties of 3D objects can be changed using geometric
modifiers like bend, twist, bulge, taper etc.
• Arrays
– Multiple objects can be combined together to build arrays
– Duplicate objects can either be instances or copies of original
– Instances share the same geometry but different TMs
– Copies have different geometries as well
3D Modeling
• Boolean operations
– Boolean operations of addition, subtraction, intersection allows combining several objects
• Trimming
– Involves cutting a pattern into a surface
– One technique is to project a curve onto the surface
– Second technique is to use two intersecting objects
3D Modeling
• Extrusion
– Surface generated by moving a shape through space along a straight line
– Sometimes dimensions of the shape might be changed while it is pushed
– Also known as translational sweep
• Lofting
– Surface generated by moving one curve called shape along another curve called path
3D Modeling
• Lathing
– Involves rotating a 2D shape around an axis
– Surface of revolution depends on choice of axis and distance between shape and axis
– Also known as rotational sweep
3D Modeling
• 3D Mesh and Topology
– Volume pixels or voxels are used as basic structuring elements for 3D objects
– A voxel is represented as a small cube and single color value
– 3D topology is determined by how voxels occur in the neighbourhood of other voxels
– For a reference voxel there are 26 other voxels that share a vertex, face or edge
– This includes 6 faces, 4 vertical edges, 8 horizontal edges, 8 vertices
– An octree indexes voxels in a 3D image by using a tree structure
Surface Properties
• Color, diffuseness, specularity
– Color is specified using RGB sliders
– Specified using values between 0 and 255
– In some cases HSB sliders may be used
Surface Properties
• Reflectivity, transparency, refractivity
– Reflectivity determines how much a surface reflects its surroundings
– Specified using values between 0 and 1
– Value 0 indicates no reflection while 1 indicates perfect mirror
Surface Properties
• Projection Texture Mapping
– Involves mapping a 2D image over a 3D object
– Projection mapping : image is projected onto surface through space
– Planar projection mapping : image is projected along each of the 3 axes
– However surface needs to be perpendicular to line of projection
– Cylindrical projection mapping : image is projection from surface of a cylinder inwards
– Spherical projection mapping : image is projected from surface of a sphere inwards
Surface Properties
• Parameterized Texture Mapping
– Parameterized texture mapping : analogous to stretching a flat sheet of rubber containing the
texture over the 3D surface
– Texture image is usually rectangular, so stretching on a non-rectangular surface produces distortion
– Both the texture and surface are divided into same number of rectangular areas
– Each area of the texture XY is applied to the corresponding area of the surface UV
Surface Properties
• Parameterized Texture Mapping
– Parameters allow control over the mapping process
– Scaling : determines how much of the surface is covered by texture in either direction
– Default : 1 covers 100% of surface, 0.5 covers 50% of surface, 0.25 covers 25% of surface
– Placement : determines where the mapping process should begin
– Default : process begins at UV=(0,0)
– For a scaling of 0.25, starting point may be shifted to UV=(0.5,0). Called offset
– To begin from top right-hand corner offset should be UV=(0.75,0.75)
Surface Properties
• Parameterized Texture Mapping
– Wrapping : determines whether texture wraps around surface
– Default : scale 1, offset (0,0), no wrapping required
– If scale is 1 but offset (0,5,0) image starts halfway across surface and wraps round in U direction
– If scale is 1 but offset (0.5,0.5) image wraps around in both U and V directions
– Wrapping can be switched off in which case only portion of the texture may be visible
Lights
• Parameters
– Light produces shading on objects and leads to casting of shadows
– Position : XYZ coordinates
– Intensity : value between 0 and 1
– Color : RGB triplets
• Types
– Point light : represented by a point in space
– Does not have size or shape
– Radiates in all direction
– Intensity reduces with distance : decay or falloff
Lights
• Types (contd.)
– Spotlight : has a cone shaped beam and all parameters of a point light
– Additionally width of cone may be specified in degrees , called ‘spread’
– Spotlights also have ‘direction’, which can be changed by rotating it
– Parameter ‘dropoff’ specifies how intensity changes from center to edge of cone
• FLA, SWF
– 2D vector graphics and animation format by Adobe Flash, editable FLA files are converted to
distributable SWF files using shockwave compression
• MAX
– 3D vector graphics and animation format by Autodesk 3D Studio MAX, also supports bitmap images
for texture and background, rendering into standard image/video formats for distribution
Fractals
• Overview
– Displays self-similarity at any level of detail
– Images are drawn through a process of recursion
– Can be used to model natural objects like snowflakes, fern leaves etc.
– Fractals are so called because they have fractional dimensions
– They have potentials for high amount of compressions
Fractals
• Drawing Fractal Curves
– Drawing process starts with an initiator and a generator
– At each step the initiator is replaced by the generator
– For the Koch curve the initiator is a single line segment
– The generator consists of 4 line segment, each 1/3 the length on the initiator
– At each step initiator is replaced by 4 line segments whose total length is 4/3 times the initiator
– Other examples include Sierpinski triangle, Cantor dust
Fractals
• Calculating Fractal Dimensions
– Dimension of a figure is calculated as per relation :
– A straight line is split into four smaller lines which can be used to build the original line
– In this case scale s = ¼ and N = 4, so that D = 1
– For a square, each side is split into 4 parts and 16 smaller squares are required to build the original
– Hence s = ¼ and N = 16, so that D = 2
– For a cube, each side is split into 4 parts and 64 smaller cubes are required to build the original
– Hence s = ¼ and N = 64, so that D = 3
– For a Koch curve, initiator is split into 3 parts and 4 smaller lines replace the original
– Hence s = 1/3 and N = 4, so that D = log(4)/log(3) = 1.26
– For a Sierpinski triangle, initiator is split into 2 parts and 3 smaller triangles replace the original
– Hence s = 1/2 and N = 3, so that D = log(3)/log(2) = 1.585
– For Cantor dust, each line is split into 3 smaller parts and it takes 2 smaller parts to replace original
– Hence s = 1/3 and N = 2, so that D = log(2)/log(3) = 0.63
Quad Tree
• Overview
– A data structure used to store 2D graphics in an efficient way
– Provides a means for compression, especially when the graphics contains large areas of same colors
– Also enables accessing and modifying specific portions quicker and easier
– Divides a graphical section into 4 quadrants
– Successively repeats the process until a region contains homogeneous data
– Each region is represented as a node in a tree structure
• Tree structure
– Consider a 8 by 8 graphical section containing white or black pixels
– Section is divided into 4 quadrants, counted in clockwise order
– A quadrant is represented as white node if it contains only white pixels
– A quadrant is represented as black node if it contains only black pixels
– A quadrant is represented as gray node if it contains both types of pixels
– Gray nodes are further subdivided into four quadrants
– Process is repeated until each pixel is represented as nodes
– Homogeneous quadrants are not divided further
Quad Tree
• Encoding
– The quadtree is represented using code values
– Code 0 is used for homogeneous node, 1 for heterogeneous node (gray)
– Code 00 is used for white, 01 for black
– Starting from the top node, the tree is traversed from top to down, left to right
– Entire tree is represented using string : 1001000010100000001101001000001000001
– Entire data is represented using 37 bits which implies compression of 64/37 = 1.73
Quad Tree
• Decoding
– Start with an 8 by 8 gray section
– Step 1 : Q1 (00) is white, Q2 (1) and Q3 (1) are gray, Q4 (01) is black
– Step 2: Q21 and Q22 are white, Q23 gray, Q24 black, Q31 black, Q32 white, Q33 gray, Q34 white
– Step 3 : Q231 is black, Q232 , Q233, Q234 are white, Q331, Q332, Q334 are white, Q333 is black
Graphics Software
• Major Features : 2D Graphics
– Drawing
– Colors
– Text
– Layers
– Positioning
– Reusability
– Viewing