0% found this document useful (0 votes)
15 views

Lecture - 3

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Lecture - 3

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 53

CSE4203: Computer Graphics

Lecture - 3

Vector Graphics

M. I. Jubair 1
Outline
• Vector Image
• Curves
• Polynomial Curves
• Bézier Curves

2
Vector Image (1/3)

– storing descriptions of shapes


– areas of color bounded by lines or curves
– no reference to any pixel grid.

• Need to store instructions for displaying the image rather


than the pixels needed to display it.

Credit: Fundamentals of Computer Graphics 3rd Edition by Peter Shirley, Steve Marschner 3
Vector Image (2/3)

• Resolution independent – scaling the image will not affect


the quality
• Typically small in size compared to raster image
• Generates smooth curves and edges
• Limited photorealism
• Must be rasterized before they can be displayed
• File formats: SVG, AI, PDF

4
Vector Image (3/3)

• Differences between raster and vector images?

5
Curves (1/2)

• Curve is the continuous image of some interval in an n-dimensional


space
• a continuous map from a one-dimensional space to an n-dimensional
space.

6
Curves (2/2)
How many dimensions in the curve?
- It lies on 2D plane, but actually it’s 1D

Credit: https://umd.instructure.com/courses/1286262/modules 7
Polynomial Curve (1/1)
• A polynomial is a sum of variables raised to powers and multiplied by
coefficients
∑(aᵢxⁱ) = a₀ + a₁x + a₂x² + . . . + aₙxⁿ

• The degree (or order) of a polynomial is the highest power of


variables

1st degree (linear) polynomial: 𝑦 = 𝑎𝑥0 + 𝑏𝑥1

2nd degree (quadratic) polynomial: 𝑦 = 𝑎𝑥0 + 𝑏𝑥1 + 𝑐𝑥2

3rd degree (cubic) polynomial: 𝑦 = 𝑎𝑥0 + 𝑏𝑥1 + 𝑐𝑥2 + 𝑑𝑥3

• Higher the degree, more change of directions


8
Bézier Curves (1/3)
• One of the most common representations for free-form curves
in computer graphics
• First developed in 1959 by Paul de Casteljau
• Formalized and popularized by engineer Pierre Bézier
• Pierre Bézier used them for designing cars at Renault
• Common applications: 3D Modeling, CAD, typeface etc.

Pierre Étienne Bézier

9
Bézier Curves (2/3)
Parametric Equation
• Bézier Curves are expressed as parametric equations
• A parameter t is used to determine the value
𝑥(𝑡) = (1 − 𝑡)𝑥₀ + 𝑡𝑥₁
𝑦(𝑡) = (1 − 𝑡)𝑦₀ + 𝑡𝑦₁

where 0 ≤ t ≤ 1. Let 𝑃₀ = (𝑥₀, 𝑦₀), 𝑃₁= (𝑥₁, 𝑦₁) and P = (𝑥, 𝑦)


𝑃(𝑡) = (1 − 𝑡)𝑃₀ + 𝑡𝑃₁
or 𝑃(𝑡) = 𝑃₀ + 𝑡(𝑃₁ − 𝑃₀)

10
Bézier Curves (3/3)
Control Points
• A Bézier curve is defined by a set of control points
• An N degree Bézier curve is define by (N+1) control points
• For N control points, degree 𝑑 = 𝑁 − 1

11
Bézier Curves Derivation (1/13)
Derivation of a quadratic Bézier curve
• A quadratic (d=2) Bézier curve has 3 control points (P0, P1, P2)
• Assume Q0 and Q1 lies on the line P0 P1 and P1 P2
𝑄0 = 𝑃₀ + 𝑢(𝑃₁ − 𝑃₀)
𝑄1 = 𝑃1 + 𝑢(𝑃2 − 𝑃1)
• Point on the Bezier curve lies on the line Q0 Q1
𝑄 𝑢 = 𝑄₀ + 𝑢(𝑄₁ − 𝑄₀)
Where u is a parameter ranges between 0 to 1
12
Bézier Curves Derivation (2/13)

P1 Control Point

P0 P2

13
Bézier Curves Derivation (3/13)
at u = 0,
Q0 = P0 P1
Q1 = P1 Q1

Q0
P0 P2

14
Bézier Curves Derivation (4/13)
at u = 0,
Q = P0 P1
Q1

Q0
P0 P2

15
Bézier Curves Derivation (5/13)
at u = 0.1,
P1
Q1

Q0
P0 P2

16
Bézier Curves Derivation (6/13)
at u = 0.2,
P1

Q1

Q0

P0 P2

17
Bézier Curves Derivation (7/13)
at u = 0.5,
P1

Q0 Q1

P0 P2

18
Bézier Curves Derivation (8/13)
at u = 1,
P1
Q0

Q1
P0 P2

19
Bézier Curves Derivation (9/13)

P1

P0 P2

20
Bézier Curves Derivation (10/13)
• Assume Q0 and Q1 lies on the line P0 P1 and P1 P2
𝑄0 = 𝑃₀ + 𝑢(𝑃₁ − 𝑃₀)
𝑄1 = 𝑃1 + 𝑢(𝑃2 − 𝑃1)
• 𝑄 𝑢 is the point on the Bezier curve on the line Q0 Q1
𝑄 𝑢 = 𝑄₀ + 𝑢(𝑄₁ − 𝑄₀)
• Combining them gives
𝑄 𝑢 = 1−𝑢 2 𝑃0 + 2𝑢 1 − 𝑢 𝑃1 + 𝑢2 𝑃2

21
Bézier Curves Derivation (11/13)
de Casteljau’s Algorithm
• This derivation is known is de Casteljau’s Algorithm
• Let Pi,j denote the control points
• where Pi,0 are the original control points P0 to P2
Pi,1 are the points Q1 to Q2
P0,2 is the Q(u) then,
Pi, j = (1 - u) Pi, j−1 + u Pi+1, j−1

22
Bézier Curves Derivation (12/13)
de Casteljau’s Algorithm P1,0

P0,1 P0,2
P1,1

P0,0 P2,0
P0, 2 = (1− u) P0,1 + u P1,1
P0, 2 = (1 − u) [(1−u) P0,0 + u P1,0] + u [(1−u) P1,0 + u P2,0]
P0, 2 = (1 − u)2 P0,0 + 2u (1−u) P1,0 + u2 P2,0 23
Bézier Curves Derivation (13/13)
For cubic Bézier Curves with 4 control points
P0, 3 = (1−u)3 P0,0 + 3u (1−u)2 P1,0 + 3u2 (1−u) P2,0 + u3 P3,0

P1,0 P1,1
P2,0
P0,2 P1,2

P0,3
P0,1 P2,1

P0,0 P3,0 24
General form of Bézier Curves
General form of Bézier Curves:
d
Q(u )   Bi ,d (u )Pi 0  u 1
i 0

Bi ,d (u ) is called Bernstein polynomials


d  i
Bi,d (u )   u (1  u ) d i
i 
d  d!
where    u i (1  u ) d i
i  i!(d  i )!

Bézier curves are weighted sum of control points using n’th-order


25
Bernstein polynomials
General form of Bézier Curves
General form of Bézier Curves:
d
Q(u )   Bi ,d (u )Pi 0  u 1
i 0

Bi ,d (u ) is called Bernstein polynomials


d  i
Bi,d (u )   u (1  u ) d i
i 
d  d!
where    u i (1  u ) d i
i  i!(d  i )!
Q2(u) = (1 − u)2 P0,+ 2u (1−u) P1 + u2 P2
26
General form of Bézier Curves
General form of Bézier Curves:
d
Q(u )   Bi ,d (u )Pi
i 0
𝑷1
d  i
Bi,d (u )   u (1  u ) d i
i 
d  d! 𝑸(𝒖)
where    u i (1  u ) d i
i  i!(d  i )!
𝑷2
A point on the curve 𝑷𝟎

Credit: CPSC 589/689 Course Notes, University of Calgary, Faramarz Samavati 27


General form of Bézier Curves
General form of Bézier Curves:
d
Q(u )   Bi ,d (u )Pi
i 0
𝑷1
d  i
Bi,d (u )   u (1  u ) d i
i 
d  d! 𝑸(𝒖)
where    u i (1  u ) d i
i  i!(d  i )!
𝑷2

Denoted with 𝑄𝑑(𝑢) 𝑷𝟎

Credit: CPSC 589/689 Course Notes, University of Calgary, Faramarz Samavati 28


General form of Bézier Curves
General form of Bézier Curves:
d
Q(u )   Bi ,d (u )Pi
i 0
𝑷1
d  i
Bi,d (u )   u (1  u ) d i
i 
d  d! 𝑸(𝒖)
where    u i (1  u ) d i
i  i!(d  i )!
𝑷2
Where is 𝑄𝑑 0.5 situated?
𝑷𝟎
Where is 𝑄𝑑 0 situated?
Where is 𝑄𝑑 1 situated?
Credit: CPSC 589/689 Course Notes, University of Calgary, Faramarz Samavati 29
Practice Problem 1

Why subscript 2 for 𝑄2(𝑢)?

Credit: CPSC 589/689 Course Notes, University of Calgary, Faramarz Samavati 30


Practice Problem 1

𝑄2 𝑢 = 𝐵0,2 𝑢 𝑃0 + 𝐵1,2 𝑢 𝑃1 + 𝐵2,2 𝑢 𝑃2

Credit: CPSC 589/689 Course Notes, University of Calgary, Faramarz Samavati 31


Practice Problem 1

….. Do calculations ….

… Do calculations …

Credit: CPSC 589/689 Course Notes, University of Calgary, Faramarz Samavati 32


Properties of Bezier Curves
• They generally follow the shape of the control polygon, which consists
of the segments joining the control points
• They always pass through the first and last control points
• They are contained in the convex hull of their defining control points
• The degree of the polynomial defining the curve segment (d) is one
less than that the number of defining polygon point (n) i.e. n = d+1

Credit: CPSC 589/689 Course Notes, University of Calgary, Faramarz Samavati 33


Disadvantages
• A change to any of the control point alters the entire curve.
• Having a large number of control points requires high
polynomials to be evaluated. This is expensive to compute.

Credit: CPSC 589/689 Course Notes, University of Calgary, Faramarz Samavati 34


B-Spline Curve (1/4)
• B-splines (or Basis Splines) use several Bezier Curves joined end on end
• a k degree B-spline curve defined by n+1 control points will consists
of n – k + 1 Bezier Curves
• For example, a cubic B-Spline Curve defined by 6 control points P0 P1
P2 P3 P4 P5 consists of n – k + 1 = 5 – 3 +1 = 3 Bezier Curves

Credit: Mathematics of Computer Graphics and Virtual Environments – Dr. Jon Siach 35
B-Spline Curve (2/4)
P3

P4
P1 – P4 P2 – P5
P2

P0 – P3 P5
P1

P0
Cubic B-Spline Curve with 6 control Points 36
B-Spline Curve (3/4)

• Degree is independent of the number of control points


• The final point of the first Bezier curve has the same co-ordinate as the
first point on the second Bezier curve (C0 continuity)
• The first derivative at the end of the first Bezier curve is the same as the
first derivative at the start of the second Bezier curve (C1 continuity)
• The second derivative at the end of the first Bezier curve is the same as
the second derivative at the start of the second Bezier curve (known as
C2 continuity).

Credit: Mathematics of Computer Graphics and Virtual Environments – Dr. Jon Siach
B-Spline Curve (4/4)

• A B-spline curve S(t), is defined by,


n
S (t )   N i ,k (t )Pi
i 0

• where (P0, P1,...,Pn) are the control points


• k is the order of the polynomial segments of the B-spline curve
• Ni,k(t) are the “normalized B-spline blending functions”.

Credit: Mathematics of Computer Graphics and Virtual Environments – Dr. Jon Siach
Cox-de Bour formula (1/1)
• The blending function Ni,k(t) is defined by Cox-de Bour recursion
formula,

• The values of ti is taken from non-decreasing sequence of real numbers


called knot vector, T = {t0, t1, t2,……, tm}
• The number of knots in a knot vector, m = k + n +1
Credit: Mathematics of Computer Graphics and Virtual Environments – Dr. Jon Siach
Uniform Quadratic B-spline (1/4)
• If the knots are equidistant then we have a uniform B-spline
• If a uniform quadratic B-spline is defined by the control points (P0, P1,
P2), hence k = 2, n = 2
• then m = k + n + 1= 2 + 2 + 1 = 5
• knot vector, T = {t0, t1, t2, t3, t4, t5} = {0, 1, 2, 3, 4, 5}
• The B-Spline curve is defined by,
2
P(t )   N i , 2 (t )Pi
i 0

Credit: Mathematics of Computer Graphics and Virtual Environments – Dr. Jon Siach
Uniform Quadratic B-spline (2/4)
• Equation of a quadratic B-spline curve is
n
P(t )   N i ,k (t )Pi
i 0
• when t2 ≤ t ≤ t3

Credit: Mathematics of Computer Graphics and Virtual Environments – Dr. Jon Siach
Uniform Quadratic B-spline (3/4)
• which can be written in matrix form as:

• In general terms a uniform quadratic B-spline curve is written as:

where i = 0, 1,...,n − k + 1

Credit: Mathematics of Computer Graphics and Virtual Environments – Dr. Jon Siach
Uniform Quadratic B-spline (4/4)

Fig: A uniform quadratic B-spline curve


Credit: Mathematics of Computer Graphics and Virtual Environments – Dr. Jon Siach
Open Uniform B-spline curves (1/3)
• Uniform B-splines aren’t defined for all the range [t0, tm].
• As a result, B-spline curve is undefined at the start and end control
points.
• Open uniform B-spline curves overcome this by setting the first k knots
the same value and the last k knots have the same value
• For example, consider an open uniform quadratic B-spline curve
defined by the control points P0, …., P4. Here m = k +n + 1 = 2 + 4 + 1 = 7
• So the knot vector is T = {t0, t1, t2, t3, t4, t5, t6, t7}
= {0, 0, 0, 1, 2, 3, 3, 3}

Credit: Mathematics of Computer Graphics and Virtual Environments – Dr. Jon Siach
Open Uniform B-spline curves (2/3)
• Matrix form of an open uniform B-spline curve is

Credit: Mathematics of Computer Graphics and Virtual Environments – Dr. Jon Siach
Open Uniform B-spline curves (3/3)

Fig: A Open Uniform B-spline curve


Credit: Mathematics of Computer Graphics and Virtual Environments – Dr. Jon Siach
Practice Problem 2
An uniform quadratic B-Spline curve is defined by 5 control points P0(1, 2),
P1(3, 8), P2(5, 2), P3(7, 1) and P4(8, 0). Find the points on the curve
segments for t = 0

Credit: Mathematics of Computer Graphics and Virtual Environments – Dr. Jon Siach
Practice Problem 2
An uniform quadratic B-Spline curve is defined by 5 control points P0(1, 2),
P1(3, 8), P2(5, 2), P3(7, 1) and P4(8, 0). Find the points on the curve
segments for t = 0
solution:
k = 2, n = 4
Number of curve segments = n – k + 1 = 4 – 2 + 1 = 3
 1  2 1 t 
2

1   
Si (0)  Pi Pi  1 Pi  2    2 2 1   t 
2
 1 0 0  1 

Credit: Mathematics of Computer Graphics and Virtual Environments – Dr. Jon Siach
Practice Problem 2
 1  2 1 t 
2  1  2 1  0 
1     1 3 5 1      2
S 0(0)  P0 P1 P2    2 2 1   t  2   2 2 1 0  5 
2  8 2 2   
 
 1 0 0  1   1 0 0 1

 1  2 1 t 
2

 
P3  2 2 1  t 
1
S 1(0)  P1 P2 ?
2
 1 0 0  1 

 1  2 1 t 
2

S 2(0)  P2 P3
 
P4  2 2 1  t 
1 ?
2
 1 0 0  1 

Credit: Mathematics of Computer Graphics and Virtual Environments – Dr. Jon Siach
Practice Problem 3
An open uniform quadratic B-Spline curve is defined by 5 control points
P0(1, 2), P1(3, 8), P2(5, 2), P3(7, 1) and P4(8, 0). Find the points on the curve
segments for t = 0
solution:
k = 2, n = 4
Number of curve segments = n – k + 1 = 4 – 2 + 1 = 3

Credit: Mathematics of Computer Graphics and Virtual Environments – Dr. Jon Siach
Practice Problem 3
 2  4 2 t 
2  2  4 2  0 
1     1 3 5 1     1 
S 0(0)  P0 P1 P2    3 4 0   t  2   3 4 0 0   2
2  8 2 2   
 
 1 0 0  1   1 0 0 1

 1  2 1 t 
2

 
P3  2 2 1  t 
1
S 1(0)  P1 P2 ?
2
 1 0 0  1 

 1  2 1 t 
2

S 2(0)  P2 P3
 
P4  3 2 1  t 
1 ?
2
 2 0 0  1 

Credit: Mathematics of Computer Graphics and Virtual Environments – Dr. Jon Siach
Further Reading
• Fundamentals of Computer Graphics, 4th Edition - Chapter 15
• https://www.youtube.com/watch?v=2HvH9cmHbG4
• https://www.youtube.com/watch?v=qhQrRCJ-mVg

Credit: Mathematics of Computer Graphics and Virtual Environments – Dr. Jon Siach
End

Credit: Mathematics of Computer Graphics and Virtual Environments – Dr. Jon Siach

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy