curves - inf.ed.ac.uk

40
Curves Hakan Bilen University of Edinburgh Computer Graphics Fall 2017 Some slides are courtesy of Steve Marschner and Taku Komura

Upload: others

Post on 14-Mar-2022

5 views

Category:

Documents


0 download

TRANSCRIPT

Curves

Hakan Bilen

University of Edinburgh

Computer Graphics

Fall 2017

Some slides are courtesy of Steve Marschner and Taku Komura

How to create a virtual world?

To compose scenes

We need to define objects

- Characters

- Terrains

- Objects (trees, furniture, buildings etc)

Geometric representations

β€’ Meshes

β€’ Triangle, quadrilateral,

polygon

β€’ Implicit surfaces

β€’ Blobs, metaballs

β€’ Parametric surfaces / curves

β€’ Polynomials

β€’ Bezier curves, B-splines

Smoothness

Motivation

Many applications require smooth surfaces

Can produce smooth surfaces with less parameters

β€’ Easier to design β€’ Can efficiently preserve complex structures

[sce

ne

36

0.c

om

]

Original Spline

From draftsmanship to CG

β€’ Control

β€’ user specified control points

β€’ analogy: ducks

β€’ Smoothness

β€’ smooth functions

β€’ usually low order polynomials

β€’ analogy: physical constraints, optimization

What is a curve?

A set of points that the pen traces over an interval of time

What is the dimensionality?

Implicit form: f x, y = π‘₯2 + 𝑦2 βˆ’ 1 = 0

β€’ Find the points that satisfy the equation

Parametric form: x, y = f t = π‘π‘œπ‘ π‘‘, 𝑠𝑖𝑛𝑑 , 𝑑 ∈ [0,2πœ‹)

β€’ Easier to draw

in this context

What is a spline curve?

𝑓 𝑑 is a

β€’ parametric curve

β€’ piecewise polynomial function that switches between different

functions for different t intervals

Example:

𝑓 𝑑 = ΰ΅žπ‘‘3, if 0 ≀ 𝑑 < 1

1 βˆ’ 𝑑 βˆ’ 1 3, if 1 ≀ 𝑑 < 20, otherwise

Defining spline curves

β€’ Discontinuities at the integers [t=k]

β€’ Each spline piece is defined over [k,k+1] (e.g. a cubic spline)

𝑓 𝑑 = π‘Žπ‘‘3 + 𝑏𝑑2 + 𝑐𝑑 + 𝑑

β€’ Different coefficients for every interval

β€’ Control of spline curves

β€’ Interpolate

β€’ Approximate

Today

β€’ Spline segments

β€’ Linear

β€’ Quadratic

β€’ Hermite

β€’ Bezier

β€’ Chaining splines

β€’ Notation

β€’ vectors bold and lowercase 𝒗

β€’ points as column vector 𝒑 = 𝑝π‘₯ 𝑝𝑦

β€’ matrices bold and uppercase 𝑴

Linear Segment

Spline segments

A line segment connecting point 𝒑𝒐 to π’‘πŸ

Such that 𝑓 0 = π’‘πŸŽ and 𝑓 1 = π’‘πŸ

𝑓π‘₯ 𝑑 = 1 βˆ’ 𝑑 𝒙𝒐 + π‘‘π’™πŸ

𝑓𝑦 𝑑 = 1 βˆ’ 𝑑 π’šπ’ + π‘‘π’šπŸ

Vector formulation

𝑓 𝑑 = 1 βˆ’ 𝑑 𝒑𝒐 + π‘‘π’‘πŸ

Matrix formulation

𝑓 𝑑 = 𝑑 1? ?? ?

π’‘πŸŽπ’‘πŸ

𝑓 𝑑 = 𝑑 1βˆ’1 11 0

π’‘πŸŽπ’‘πŸ

π’‘πŸŽ

π’‘πŸ

1 βˆ’ 𝑑

𝑑

1 βˆ’ 𝑑 𝒑𝒐 + π‘‘π’‘πŸ

Matrix form of spline

𝑓 𝑑 = 𝑑 1βˆ’1 11 0

π’‘πŸŽπ’‘πŸ

Blending functions 𝒃 𝑑 specify how to blend the values of the control point vector

𝒇 𝑑 = π’ƒπŸŽ 𝑑 π’‘πŸŽ + π’ƒπŸ 𝑑 π’‘πŸ

π’ƒπŸŽ 𝑑 = 1 βˆ’ 𝑑

π’ƒπŸ 𝑑 = 𝑑

π’ƒπŸŽ 𝑑 π’ƒπŸ 𝑑

Quadratic

Beyond line segment

A quadratic (𝒇 𝑑 = π‘Ž0 + π‘Ž1𝑑 + π‘Ž2𝑑2) passes through π’‘πŸŽ, π’‘πŸ, π’‘πŸ s.t.

π’‘πŸŽ = 𝑓 0 = π‘Ž0 + 0 π‘Ž1 + 02 π‘Ž2

π’‘πŸ = 𝑓 0.5 = π‘Ž0 + 0.5 π‘Ž1+0.52 π‘Ž2

π’‘πŸ = 𝑓 1 = π‘Ž0 + 1 π‘Ž1 + 12 π‘Ž2

Points can be written in terms of constraint matrix π‘ͺ

π’‘πŸŽπ’‘πŸπ’‘πŸ

= π‘ͺ𝒂 β‡’

π’‘πŸŽπ’‘πŸπ’‘πŸ

=1 0 01 0.5 0.251 1 1

π‘Ž0π‘Ž1π‘Ž2

β‡’

π‘Ž0π‘Ž1π‘Ž2

= π‘ͺβˆ’πŸπ’‘πŸŽπ’‘πŸπ’‘πŸ

𝒇 𝑑 can be written in terms of basis matrix 𝑩 = π‘ͺβˆ’πŸ and points 𝒑

𝒇 𝑑 = 𝒕𝑩𝒑 = 𝒕π‘ͺβˆ’1𝒑 = 𝑑2 𝑑 12 βˆ’4 2βˆ’3 4 βˆ’11 0 0

π’‘πŸŽπ’‘πŸπ’‘πŸ

Blending functions

Matrix form of spline

𝒇 𝑑 = 𝑑2 𝑑 12 βˆ’4 2βˆ’3 4 βˆ’11 0 0

π’‘πŸŽπ’‘πŸπ’‘πŸ

Blending functions 𝒃 𝑑 specify how to blend the values of the control

point vector

𝒇 𝑑 = π’ƒπŸŽ 𝑑 π’‘πŸŽ + π’ƒπŸ 𝑑 π’‘πŸ + π’ƒπŸ 𝑑 π’‘πŸ

π’ƒπŸŽ 𝑑 = 2𝑑2 βˆ’ 3𝑑 + 1

π’ƒπŸ 𝑑 = βˆ’4𝑑2 βˆ’ 4𝑑

π’ƒπŸ 𝑑 = 2𝑑2 βˆ’ 1

Hermite spline

β€’ Piecewise cubic (𝒇 𝑑 = π‘Ž0 + π‘Ž1𝑑 + π‘Ž2𝑑2 + π‘Ž3𝑑

3)

β€’ Additional constraint on tangents (derivatives)

β€’ 𝒇 𝑑 = π‘Ž0 + π‘Ž1𝑑 + π‘Ž2𝑑2 + π‘Ž3𝑑

3

β€’ 𝒇′ 𝑑 = π‘Ž1 + 2π‘Ž2𝑑 + 3π‘Ž3𝑑2

β€’ π’‘πŸŽ = 𝑓 0 = π‘Ž0β€’ π’‘πŸ = 𝑓 1 = π‘Ž0 + π‘Ž1 + π‘Ž2 + π‘Ž3β€’ 𝒗1 = 𝑓′(0) = π‘Ž1β€’ 𝒗2 = 𝑓′ 1 = π‘Ž1 + 2π‘Ž2 + 3π‘Ž3

β€’ Simpler matrix form

𝒇 𝑑 = 𝑑3 𝑑2 𝑑 1

2 βˆ’2 1 1βˆ’3 3 βˆ’2 βˆ’10 0 1 02 0 0 2

π’‘πŸŽπ’‘πŸπ’—πŸπ’—πŸ

π’‘πŸŽ

π’‘πŸπ’—πŸŽ

π’—πŸ

Hermite to BΓ©zier

Specify tangents as points

β€’ 𝑝0 = π‘ž0, 𝑝1 = π‘ž3, 𝑣0 = 3 π‘ž1 βˆ’ π‘ž0 , 𝑣1 = 3 π‘ž3 βˆ’ π‘ž2

β€’

π’‘πŸŽπ’‘πŸπ’—πŸπ’—πŸ

=

1 0 0 00 0 0 1βˆ’3 3 1 00 0 βˆ’3 3

π’’πŸŽπ’’πŸπ’’πŸπ’’πŸ‘

β€’ Update Hermite eq. (from previous slide)

𝒇 𝑑 = 𝑑3 𝑑2 𝑑 1

2 βˆ’2 1 1βˆ’3 3 βˆ’2 βˆ’10 0 1 02 0 0 2

1 0 0 00 0 0 1βˆ’3 3 1 00 0 βˆ’3 3

π’’πŸŽπ’’πŸπ’’πŸπ’’πŸ‘

βˆ’π’—πŸ

π’’πŸ

π’’πŸ‘

π’’πŸ

π’’πŸŽ

π’—πŸ

π’‘πŸŽ π’‘πŸ

π’—πŸŽ

BΓ©zier matrix

𝒇 𝑑 = 𝑑3 𝑑2 𝑑 1

βˆ’1 3 βˆ’3 13 βˆ’6 3 0βˆ’3 3 0 02 0 βˆ’6 6

π’’πŸŽπ’’πŸπ’’πŸπ’’πŸ‘

β€’ 𝒇 𝑑 = σ𝑛=0𝑑 𝒃𝒏,πŸ‘π’’π’

β€’ Blending functions 𝒃 𝑑 has a special name in this case:

β€’ Bernstein polynomials

𝑏𝑛,π‘˜ =π‘›π‘˜

π‘‘π‘˜ 1 βˆ’ 𝑑 π‘›βˆ’π‘˜

and that defines BΓ©zier curves for any degree

BΓ©zier blending functions

β€’ The functions sum to 1 at

any point along the curve.

β€’ Endpoints have full weight

10/10/2008

q0 q3

q1 q2

de Casteljau algorithm

Another view to BΓ©zier segments

Blend each linear spline with 𝛼 and 𝛽 = 1 βˆ’ 𝛼

π’‘πŸŽ

π’‘πŸ

𝛼

𝛽

π›Όπ’‘πŸŽ + π›½π’‘πŸ

π’‘πŸŽ

π’‘πŸ

𝛼

𝛽

𝛼2π’‘πŸŽ + 2π›Όπ›½π’‘πŸ + 𝛽2π’‘πŸ

π’‘πŸ

𝛽

𝛼

Review

http://www.inf.ed.ac.uk/teaching/courses/cg/d3/hermite.html

http://www.inf.ed.ac.uk/teaching/courses/cg/d3/bezier.html

http://www.inf.ed.ac.uk/teaching/courses/cg/d3/Casteljau.html

Today

β€’ Spline segments

β€’ Linear

β€’ Quadratic

β€’ Hermite

β€’ Bezier

β€’ Chaining splines

β€’ Continuity and local control

β€’ Hermite curves

β€’ Bezier curves

β€’ Catmull-Rom curves

β€’ B-splines

Putting segments together

β€’ Limited degree of freedom with a single polynomial

β€’ Will it be smooth enough?

Continuity

Measuring smoothness

Smoothness as degree of continuity

β€’ zero-order (𝐢0): position match

β€’ first-order (𝐢1): tangent match

β€’ second-order (𝐢2): curvature match

β€’ 𝐢𝑁 𝑣𝑠 𝐺𝑁

Putting segments together

β€’ Limited degree of freedom with a single polynomial

β€’ Will it be smooth enough?

β€’ Local control

Local control

How many knots for m segments with 2 control points each?

Local control

?

Local control

β€’ changing control point only affects a limited part of spline

– without this, splines are very difficult to use

β€’ overshooting

β€’ fixed computation

– many likely formulations lack this

β€’ natural spline

β€’ polynomial fits (matlab demo)

Piecewise linear

Putting segments together

Blending functions for a linear segment (0<t<1)

𝒇 𝑑 = 1 βˆ’ 𝑑 π’‘πŸŽ + π‘‘π’‘πŸ

π’‘πŸŽ

π’‘πŸ

𝒇 𝑑

π’‘πŸŽ π’‘πŸ

Piecewise linear

Putting segments together

π’‡πŸŽ 𝑑 = 1 βˆ’ 𝑑 π’‘πŸŽ + π‘‘π’‘πŸ (0 < 𝑑 < 1)

π’‡πŸ 𝑑 = ? π’‘πŸ + ? π’‘πŸ (1 < 𝑑 < 2)

π’‡πŸ 𝑑 = 2 βˆ’ 𝑑 π’‘πŸ + 𝑑 βˆ’ 1 π’‘πŸ (1 < 𝑑 < 2)

π’‘πŸŽ

π’‘πŸ

π’‡πŸŽ 𝑑

π’‘πŸ

π’‡πŸ 𝑑

π’‘πŸŽ π’‘πŸ π’‘πŸ π’‘πŸ

Putting segments together

How can we chain these segments to a longer curve?

β€’ Use first segment between t=0 to t=1

β€’ Use second segment between t=1 to t=2

𝑓 𝑑 = 𝑓𝑖 𝑑 βˆ’ 𝑖 for 𝑖 ≀ 𝑑 ≀ 𝑖 + 1

β€’ Shift blending functions

𝑓0 𝑑 = 𝑏0 𝑑 π’‘πŸŽ + 𝑏1 𝑑 π’‘πŸ

𝑓1 𝑑 = 𝑏0 𝑑 βˆ’ 1 π’‘πŸ + 𝑏1 𝑑 βˆ’ 1 π’‘πŸ

β€’ Match derivatives at end points to avoid discontinuity

Hermite basis

Slide credit: S. Marschner

β€’ How many segments for n control points?

(n-2)/2

β€’ Continuity?

𝐢1

Can we add blending functions as in Hermite?

β€’ If 𝑝3 βˆ’ 𝑝2 is collinear with 𝑝4 βˆ’ 𝑝3 , it is

𝐺1 continuous

β€’ 𝑝3 βˆ’ 𝑝2 = π‘˜(𝑝4 βˆ’ 𝑝3), π‘˜ > 0

β€’ If tangents match, it is 𝐢1 continuous

β€’ 𝑝3 βˆ’ 𝑝2 = π‘˜(𝑝4 βˆ’ 𝑝3), k = 1

Chaining BΓ©zier Splines

π’‘πŸ

π’‘πŸ‘

π’‘πŸ

π’‘πŸŽ

Chaining segments

β€’ Hermite curves are convenient because they can be made long

easily

β€’ BΓ©zier curves are convenient because their controls are all points

– but it is fussy to maintain continuity constraints

– and they interpolate every 3rd point, which is a little odd

β€’ We derived BΓ©zier from Hermite by defining tangents from control

points

– a similar construction leads to the interpolating Catmull-Rom

spline

Catmull-Rom

Would like to define tangents automatically

– use adjacent control points

π’’πŸ

π’’πŸŽ π’’πŸ‘

π’’πŸ

Hermite to Catmull-Rom

β€’ 𝑝0 = 𝑓 0

β€’ 𝑝1 = 𝑓 1

β€’ 𝑣1 = 𝑓′(0)

β€’ 𝑣2 = 𝑓′ 1

β€’ 𝒇 𝑑 =

𝑑3 𝑑2 𝑑 1

2 βˆ’2 1 1βˆ’3 3 βˆ’2 βˆ’10 0 1 02 0 0 2

π’‘πŸŽπ’‘πŸπ’—πŸŽπ’—πŸ

β€’ 𝑝0 = π‘ž1

β€’ 𝑝1 = π‘ž2

β€’ 𝑣0 =1

2(π‘ž2 βˆ’ π‘ž0)

β€’ 𝑣1 =1

2(π‘ž3 βˆ’ π‘ž1)

𝒇 𝑑 = 𝑑3 𝑑2 𝑑 1

2 βˆ’2 1 1βˆ’3 3 βˆ’2 βˆ’10 0 1 02 0 0 2

0 1 0 00 0 1 0

βˆ’0.5 0 0.5 00 βˆ’0.5 0 0.5

π’’πŸŽπ’’πŸπ’’πŸπ’’πŸ‘

Catmull-Rom

β€’ Interpolating curve

β€’ Like BΓ©zier, equivalent to Hermite

β€’ Continuity ?

β€’ Local control ?

β€’ Add tension

β€’ 𝑝0 = π‘ž1

β€’ 𝑝1 = π‘ž2

β€’ 𝑣0 =1

2(1 βˆ’ 𝑑)(π‘ž2 βˆ’ π‘ž0)

β€’ 𝑣1 =1

2(1 βˆ’ 𝑑)(π‘ž3 βˆ’ π‘ž1)

B-splines

β€’ We may want more continuity than 𝐢1

β€’ 𝑓 𝑑 = σ𝑖=1𝑛 π’‘π’Š 𝑏𝑖(𝑑)

– parameterized by k control points

– made of polynomials of degree k-1

– is 𝐢(π‘˜βˆ’2)

β€’ B-splines are a clean, flexible way of making long splines with

arbitrary order of continuity

β€’ Various ways to think of construction

– a simple one is convolution

– relationship to sampling and reconstruction

Quadratic B-spline

𝑏𝑖,3 𝑑 =

1

2𝑒2, if 𝑖 ≀ 𝑑 < 𝑖 + 1, 𝑒 = 𝑑 βˆ’ 𝑖

βˆ’π‘’2 + 𝑒 +1

2, if 𝑖 + 1 ≀ 𝑑 < 𝑖 + 1, 𝑒 = 𝑑 βˆ’ (𝑖 + 1)

1

2(1 βˆ’ 𝑒)2, if 𝑖 + 2 ≀ 𝑑 < 𝑖 + 3, 𝑒 = 𝑑 βˆ’ (𝑖 + 2)

1

2𝑒2, otherwise.

Smoothing effect

B-Spline

Summary

β€’ Spline segments

β€’ Linear

β€’ Quadratic

β€’ Hermite

β€’ Bezier

β€’ Chaining splines

β€’ Catmull Rom curve and B-splines

β€’ Suggested reading: B1 Chapter 15