>
=
<
, 0
, 0
, 0
) , ( y x f
circ
boundary circle the inside is ) , ( if y x
boundary circle on the is ) , ( if y x
boundary circle the outside is ) , ( if y x
Mid-Point Circle Algorithm (cont)
Assuming we have just plotted the pixel at
(x
k
,y
k
) so we need to choose between
(x
k
+1,y
k
) and (x
k
+1,y
k
-1)
Our decision variable can be defined as:
If p
k
< 0 the midpoint is inside the circle and
and the pixel at y
k
is closer to the circle
Otherwise the midpoint is outside and y
k
-1 is
closer
2 2 2
)
2
1
( ) 1 (
)
2
1
, 1 (
r y x
y x f p
k k
k k circ k
+ + =
+ =
Mid-Point Circle Algorithm (cont)
To ensure things are as efficient as possible we can
do all of our calculations incrementally
First consider:
or:
where y
k+1
is either y
k
or y
k
-1 depending on the sign
of p
k
( )
( )
2
2
1
2
1 1 1
2
1
] 1 ) 1 [(
2
1
, 1
r y x
y x f p
k k
k k circ k
+ + + =
+ =
+
+ + +
1 ) ( ) ( ) 1 ( 2
1
2 2
1 1
+ + + + =
+ + + k k k k k k k
y y y y x p p
Mid-Point Circle Algorithm (cont)
The first decision variable is given as:
Then if p
k
< 0 then the next decision variable
is given as:
If p
k
> 0 then the decision variable is:
r
r r
r f p
circ
=
+ =
=
4
5
)
2
1
( 1
)
2
1
, 1 (
2 2
0
1 2
1 1
+ + =
+ + k k k
x p p
1 2 1 2
1 1
+ + + =
+ + k k k k
y x p p
The Mid-Point Circle Algorithm
1. Input radius r and circle centre (x
c
, y
c
), then set the
coordinates for the first point on the circumference of a
circle centred on the origin as:
2. Calculate the initial value of the decision parameter as:
3. Starting with k = 0 at each position x
k
, perform the
following test. If p
k
< 0, the next point along the circle
centred on (0, 0) is (x
k
+1, y
k
) and:
) , 0 ( ) , (
0 0
r y x =
r p =
4
5
0
1 2
1 1
+ + =
+ + k k k
x p p
The Mid-Point Circle Algorithm (cont)
4. Otherwise the next point along the circle is (x
k
+1, y
k
-1) and:
5. Determine symmetry points in the other seven octants
6. Move each calculated pixel position (x, y) onto the circular
path centred at (x
c
, y
c
) to plot the coordinate values:
7. Repeat steps 3 to 5 until x >= y
1 1 1
2 1 2
+ + +
+ + =
k k k k
y x p p
c
x x x + =
c
y y y + =
Mid-Point Circle Algorithm Example
To see the mid-point circle algorithm in action
lets use it to draw a circle centred at (0,0) with
radius 10
Mid-Point Circle Algorithm Example (cont)
9
7
6
5
4
3
2
1
0
8
9 7 6 5 4 3 2 1 0 8 10
10
k p
k
(x
k+1
,y
k+1
)
2x
k+1
2y
k+1
0
1
2
3
4
5
6
Mid-Point Circle Algorithm Exercise
Use the mid-point circle algorithm to draw the
circle centred at (0,0) with radius 15
Mid-Point Circle Algorithm Example (cont)
k p
k
(x
k+1
,y
k+1
)
2x
k+1
2y
k+1
0
1
2
3
4
5
6
7
8
9
10
11
12
9
7
6
5
4
3
2
1
0
8
9 7 6 5 4 3 2 1 0 8 10
10
13 12 11 14
15
13
12
14
11
16
15 16
Mid-Point Circle Algorithm Summary
The key insights in the mid-point circle
algorithm are:
Eight-way symmetry can hugely reduce the work
in drawing a circle
Moving in unit steps along the x axis at each point
along the circles edge we need to choose
between two possible y coordinates
CURVES & SURFACES
The need to represent curves and surfaces arises in two cases:
In modeling existing objects (a car , a face, a mountain)
In modeling from scratch where no preexisting physical object is being represented
In first case mathematical object may be unavailable.
One can use as a model the coordinates of the infinitely many points of the object but this not
feasible for computer with finite storage.
We merely approximate the object with pieces of planes, spheres or other shapes the t are easy to
describe mathematically and require that points on our model be close to corresponding points on
the object.
In second case, the user creates the object in the modeling process.
To create the object the user may sculpt the object interactively, describe it mathematically of give
an approximate description to be filled in by some program.
In CAD the computer representation is used later to generate physical realizations of the abstractly
designed object.
Curves and Surfaces
Often we are required to represent surfaces that are not
planar in nature.
To do so the parametric representation of 2-D curves and
3-D surfaces may be employed.
In general for any genus of surface or curve, there is both a
parametric and an implicit representation.
In computer graphics it is often more convenient to adopt
the parametric form.
Three most common representations for 3D surfaces are
polygon mesh surfaces
parametric surfaces
quadric surfaces
How do we draw surfaces?
Approximate with polygons
Draw polygons
How do we specify a surface?
Explicit, implicit, parametric
How do we approximate a surface?
Interpolation (use only points)
Hermite (use points and tangents)
Bezier (use points, and more points for tangents)
Polygon mesh
A polygon mesh or unstructured grid is a collection of
vertices, edges and faces that defines the shape of a
polyhedral object in 3D computer graphics and solid
modeling.
The faces usually consist of triangles, quadrilaterals or other
simple convex polygons, since this simplifies rendering, but
may also be composed of more general concave polygons, or
polygons with holes.
A cross section of curved object and its polygon representation
polygon mesh representation
Pointers to a vertex list
V=(v1,v2,v3,v4)={(x1,y1,z1)(x4,y4,z4)}
P1={1,2,4}
P2={4,2,3}
Each vertex stored just once, considerable space is saved
It is still difficult to find polygons that share an edge
Shared edge are drawn twice
Pointers to an edge list
V=(v1,v2,v3,v4)={(x1,y1,z1)(x4,y4,z4)}
E1={v1,v2,p1,*}
E2={v2,v3,p2,*}
E3={v3,v4,p2,*}
E4={v4,v2,p1,p2}
E5={v4,v1,p1,*}
P1={E1,E4,E5}
P2={E2,E3,E4}
E=(v1,v2,p1,p2,pn)
Avoid
redundant clipping
Transformation
Scan conversion
If Edge is shared by n
no. of polygon
Explicit representation
P={(x1,y1,z1),(x2,y2,z2),(x3,y3,z3),..(xn,yn,zn)}
v1
v2
v3
v4
v1
v2
v3
v4
p1
p2
p1
p2
E1
E2
E3
E5
E4
Explicit Representation
Curve in 2D: y = f(x)
Curve in 3D: y = f(x), z = g(x)
Surface in 3D: z = f(x,y)
Problems:
How about a vertical line x = c as y = f(x)?
Circle y = (r2 x2)1/2 two or zero values for x
Too dependent on coordinate system
Rarely used in computer graphics
Implicit Representation
Curve in 2D: f(x,y) = 0
Line: ax + by + c = 0
Circle: x
2
+ y
2
r
2
= 0
Surface in 3d: f(x,y,z) = 0
Plane: ax + by + cz + d = 0
Sphere: x
2
+ y
2
+ z
2
r
2
= 0
Sphere definition
For example, the implicit form of a sphere is:
In general all implicit representations of a 3-d surface are of
the form:
The parametric form of a sphere is:
x y z r
2 2 2 2
0 + + =
f x y z ( , , ) = 0
f :( , ) (cos cos ,sin , cos sin ) u | u | u u |
Parametric form
The general form of a 3-d surface in its parametric (or
explicit) representation is:
When rendering such curves and surfaces using polygons,
the parametric representation is more convenient as the
surface is defined in terms of a parametric variable or
variables.
This allows the exact determination of the value of the
surface at regular intervals, thus allowing an approximation
to the surface by taking a number of such samples.
f u v f u v f u v f u v
x y z
( , ) ( ( , ), ( , ), ( , )) =
Example - 1
determine the representation of the function f(u) = sin(u).
This is a parametric description of a curve in 2 dimensions
with parameter u.
This is an example of an unbounded curve (in that we can
take values of u from -...+. Well limit our curve to the
domain (0...2t). This gives the following curve:
Now we must determine how fine or coarse a representation we need to use
in order to faithfully capture this curve.
We will sample the curve at regular intervals of u along the length of the
curve. In this example, the curve will be sampled at regular points a unit
distance apart (i.e. at u = 0, 1, 2...).
This yields the following sample points which we will join by straight lines
which is the way the curve will be finally displayed on the raster:
Representing Curves
There are many different methods of representing general
curves. The most common are:
Cubic Splines
Bezier Curves
B-splines
NURBS and |-splines
Interpolation vs. Approximation
Given a set of n points, to create a curve we either
interpolate the points (curve passes through all points)
approximate the points (points describe convex hull of curve)
Points on curve = knot points
Points on convex hull (off curve) = control points
Interpolate
Approximate
Control points
Convex hull
knot points
Splines
To interpolate we can use a simple polynomial spline.
With n points we require a polynomial of degree n-1
(order n polynomial).
Let f(u) be the parameterised polynomial where 0 s u s 1
( ) b au u f + =
( ) c bu au u f + + =
2
( ) d cu bu au u f + + + =
2 3
Linear Quadratic Cubic
Splines
These polynomials are plots of f(u) with respect to u
for each u, there is one and only one f(u)
curve cannot turn back on itself
Use polynomials for each axis (in 2D we have 2 polys):
As before we limit u to [0,1], although the polynomial is
defined for all values of u.
( )
( )
y y y y
x x x x
d u c u b u a u y
d u c u b u a u x
+ + + =
+ + + =
2 3
2 3
( )
( )
y y y y
x x x x
d u c u b u a u y
d u c u b u a u x
+ + + =
+ + + =
2 3
2 3
( )
( )
( )
( ) ( ) ( ) | | | | ( ) C u p . 1
2 3
2 3
2 3
2 3
=
(
(
(
(
(
+ + + =
+ + + =
+ + + =
u
d d d
c c c
b b b
a a a
u u u u z u y u x
d u c u b u a u z
d u c u b u a u y
d u c u b u a u x
z y x
z y x
z y x
z y x
z z z z
y y y y
x x x x
Splines
For a 3D spline, we have 3 polynomials:
( ) u p
Defines the variation in x with
distance u along the curve
12 unknowns
4 3D points required
If we have more than 4 points we
require a polynomial of higher degree
higher degree polynomials are more
difficult to control
they exhibit unwanted wiggles
(oscillations)
Quadratic Cubic Quartic Quintic
Splines
In general we use cubic polynomials for curves in CG:
minimal ups & downs and faster to compute than high
degree polynomials
lowest degree which allows non-planar curves
(quadratics require 3 points, 3 points always lie in the
same plane)
Splines
Defining the Cubic Spline
Normally we supply 4 points we wish the spline to pass through. These are
2 endpoints
2 derivatives of the end points
If we have more than 4 points we must employ more than 1 spline use a
piecewise cubic polynomial
for n points, we have (n1)/3 individual cubic segments
without further constraints these will not join smoothly
smooth non-smooth
Curve Continuity Piecewise Curve Segments
To ensure a smooth connection between curve segments we enforce
further continuity constraints
2 types of continuity:
parametric continuity, denoted C
n
where n = degree of continuity
geometric continuity, denoted G
n
Given a curve such that at point p, 2 segments c
i
(u) and c
i+1
(u) meet
then:
( ) ( )
0
1
1 =
+
=
=
u
n
i
n
u
n
i
n
n
du
u c d
du
u c d
C
( ) ( ) 0 1
1 +
= =
i i
c c p
( ) ( )
0
1
1 =
+
=
u
n
i
n
u
n
i
n
n
du
u c d
du
u c d
G o
differentials are equal differentials are proportional
Geometric continuity
In this case we require only parametric derivative of two curves to be
proportional to each other at their intersection point
If two curve segments joint together there curve has G
0
continuity
If the direction of two segments tangent vectors are equal at the
joint point the curve has G
1
continuity
In CAD G
1
is often required
Mathematically.
2
2
1
2
2
2
1
1
0
1
G
du
Q d
du
P d
G
du
dQ
du
dP
G Q P
n
n
n
=>
=>
=> =
Parametric Continuity
0
th
order
Here curve simply meets
1
st
order
If the tangent vectors of two curves segment are equal (in
direction as well as in magnitude) at the joint point
2
nd
order
If both the first and second parametric derivatives of the
two curve section are same at the their intersection
N
th
order
If the nthe derivative are equal at the joint point.
since we want these curves to fit together
reasonably ...
Zero order parametric continuity
First order parametric continuity
Second order parametric continuity
Examples of Continuity
c
0
c
1
c
2
Cubic Parametric Curves
A curve segment p(u) is defined by constraints on end-
points, tangent vectors, and continuity between curve
segments.
Each cubic polynomial has 4 co-efficients, so four
constraints will be needed.
Remember:
This allows us to formulate 4 equations in the 4
unknowns, and then solve for the unknowns.
( )
( )
( )
( ) ( ) ( ) | | | | ( ) C u p . 1
2 3
2 3
2 3
2 3
=
(
(
(
(
(
+ + + =
+ + + =
+ + + =
u
d d d
c c c
b b b
a a a
u u u u z u y u x
d u c u b u a u z
d u c u b u a u y
d u c u b u a u x
z y x
z y x
z y x
z y x
z z z z
y y y y
x x x x
Geometry Matrix
To see how the co-efficients can depend on 4 constraints, recall that a
parametric cubic curve is defined by
Rewrite the co-efficient matrix as where
M is a 4x4 basis matrix,
G is a 4-element matrix of geometric contraints, called the geometry matrix.
The geometric contraints are just the conditions, such as endpoints, or
tangent vectors, that define the curve.
Gx refers to the column vector of just the x components; Gy and Gz are
similarly defined
G or M, or both G and M, differ for each type of curve.
C u = ) p(u
M.G C=
Geometry Matrix
The elements of G and M are constants so the product
G.M.u is just three cubic polynomials in u.
Expanding:
( ) ( ) ( ) ( ) | | | |
(
(
(
(
(
(
(
(
= =
4
3
2
1
44 43 42 41
34 33 32 31
24 23 22 21
14 13 12 11
2 3
1
G
G
G
G
m m m m
m m m m
m m m m
m m m m
u u u u z u y u x u p
| |
(
(
(
(
(
(
(
(
(
=
z y x
z y x
z y x
z y x
g g g
g g g
g g g
g g g
m m m m
m m m m
m m m m
m m m m
u u u
4 4 4
3 3 3
2 2 2
1 1 1
44 43 42 41
34 33 32 31
24 23 22 21
14 13 12 11
2 3
1
Blending Functions
We can read this equation in the following way:
The point p(u) is a weighted sum of the columns of the
geometry matrix G, each of which represents a point or a
vector in 3-space
Multiplying out just x(u) gives:
x
x
x
x
g m um m u m u
g m um m u m u
g m um m u m u
g m um m u m u u x
4 44 34 24
2
14
3
3 43 33 23
2
13
3
2 42 32 22
2
12
3
1 41 31 21
2
11
3
) (
) (
) (
) ( ) (
+ + +
+ + + +
+ + + +
+ + + + =
Blending functions
Blending Functions
This emphasizes that the curve is a weighted sum of the
elements of the geometry matrix.
The weights are each cubic polynomials of the parameter u,
and are called the blending functions.
The blending functions B are given by
This is similar to piecewise linear approximation, for which
only two geometric constraints (i.e. the endpoints of the
line) are needed.
So each curve segment is a straight line defined by the
endpoints G1 and G2 :
M u
Linear Interpolation (straight line)
We can represent its equation in three ways
1. As weight average of control points
X (u)=(1-u) g
1x
+ u g
2x
2. As polynomial in t
X (u)=(g
2x-
g
1x
) u + g
1x
3. As matrix form
G1
G
2
(
=
1 0 1
1 1
] g g [ ) (
1x 2x
u
u x
B
0
(t) p
0
+B
1
(t)p
1
Blending function
When t=0 p
0
, t=1p
1
, t=.5 midpoint
Curve is based at p0 & a vector(p
1
-p
0
)is added
which is scaled by t
Geometry Matrix, Geometry Basis, Polynomial
Basis
The key to defining a parametric cubic curve
therefore lies in the basis matrix M.
Depending on the nature of this matrix, specific
forms of curves may be created.
HERMITE CURVE
BEZIER CURVE
UNIFORM NONRATIONAL B-SPLINE
NONUNIFORM, NONRATIONAL B-SPLINE
OTHER SPLINE FORMS
Hermite Curves
The Hermite form of a cubic polynomial curve
segment is determined by constraints on the
endpoints P
1
and P
4
, and tangent vectors at
the endpoints R
1
and R
4
.
NOTE: LATER P2, P3 WILL BE USED INSTEAD OF TANGENT VECTORS TO DEFINE THE CURVE
Hermite Curves - Examples
P
1
P
4
R
1
R
4
Only the direction of R
1
varies
Only the magnitude of R
1
varies
Hermite Geometry Vector
The Hermite Geometry vector G
H
is
G
Hx
is the x component of G
H
so:
(
(
(
(
=
4
1
4
1
R
R
P
P
G
H
(
(
(
(
=
x
x
x
x
Hx
R
R
P
P
G
4
1
4
1
Hermite Curves
The Hermite basis matrix, M
H
, relates the Hermite Geometry
vector G
H
to the polynomial co-efficients.
Therefore:
where
Hx H x x x x
G M T d t c t b t a t x = + + + =
2 3
) (
| | 1
2 3
t t t T =
Hermite Curves
The constraints on x(0) and x(1) are found by direct
substitution into the previous equation:
| |
| |
x Hx H
x Hx H
P G M x
P G M x
4
1
1 1 1 1 ) 1 (
1 0 0 0 ) 0 (
= =
= =
Hermite Curves
The tangent vector constraints on x(0) and x(1) are found
by differentiation, i.e:
So:
and
| |
Hx H
G M t t t x = 0 1 2 3 ) ( '
2
| |
Hx H x
G M R x = = 0 1 0 0 ) 0 ( '
1
| |
Hx H x
G M R x = = 0 1 2 3 ) 1 ( '
4
Hermite Curves
The four constraints can be written in matrix form as:
The only way that this equation can be satisfied is if M
H
is
the inverse of the given 4x4 matrix, so:
Hx H Hx
x
x
x
x
G M G
R
R
P
P
(
(
(
(
= =
(
(
(
(
0 1 2 3
0 1 0 0
1 1 1 1
1 0 0 0
4
1
4
1
(
(
(
(
=
(
(
(
(
0 0 0 1
0 1 0 0
1 2 3 3
1 1 2 2
0 1 2 3
0 1 0 0
1 1 1 1
1 0 0 0
1
H
M
Matrix Inverse
Hermite Blending Functions
We know that:
The Hermite blending functions B
H
are given by , since these
weight the geometry vector G
H
.
Therefore:
H H
G M T t p = ) (
H
M T
= = =
H H H H
G B G M T t p . ) (
( )
( )
4
2 3
1
2 3
4
2 3
1
2 3
) (
) 2 (
3 2
1 3 2
R t t
R t t t
P t t
P t t
+ +
+ +
+ +
Hermite Curves - Blending Fuctions
P
1
P
4
R
1
R
4
t
f(t)
1
1
Labels show
which geometry
element is
weighted.
Two Hermite curves joined at p4
p
1
p
4
p
7
Y(t)
t
0 ,
7
4
7
4
4
1
4
1
>
(
(
(
(
(
(
(
(
withk
R
kR
P
P
and
R
R
P
P
x
x
x
x
Both curves share a
common end point with
G
1
continuity
Bzier Curves
The drawback of the Hermite form is the need to explicitly specify the
tangent vectors.
The Bzier form of the cubic polynomial curve segment indirectly specifies
the endpoint tangent vector.
Such curves are constrained by their endpoints: P
1
and P
4
, and also by
intermediate points that are not on the curve: P
2
and P
3
.
The starting and ending tangent vectors are determined by the vectors
P
1
P
2
and P
3
P
4
and are related to the Hermite R
1
and R
4
by:
) ( 3 ) 1 ( '
) ( 3 ) 0 ( '
3 4 4
1 2 1
P P p R
P P p R
= =
= =
Examples of some Bzier Curves
Bzier Curves
The reason for using the constant 3 is apparent from the following:
Consider the Bezier curve defined by the 4 equally spaced points:
(0,0), (0,1), (0,2), (0,3).
It's obvious that this curve has the definition:
Therefore:
Now we can see that if velocity is to be constant everywhere on
the line:
) ( ) (
1 4 1
P P t P t p + =
1 4
) ( ' P P t p =
) ( 3 ) 0 ( '
1 2 1 4 1
P P P P p R = = =
) ( 3 ) 1 ( '
3 4 1 4 4
P P P P p R = = =
P
1
P
2
P
3
P
4
Bzier Geometry Vector and Change of Basis
The Bzier geometry vector is:
A change of basis matrix M
HB
defines the relationship
between the Hermite geometry vector G
H
and the Bzier
geometry vector G
B
as follows:
(
(
(
(
=
4
3
2
1
P
P
P
P
G
B
B HB H
G M
P
P
P
P
R
R
P
P
G =
(
(
(
(
(
(
(
(
=
(
(
(
(
=
4
3
2
1
4
1
4
1
3 3 0 0
0 0 3 3
1 0 0 0
0 0 0 1
) ( 3 ) 0 ( '
1 2 1 4 1
P P P P p R = = =
) ( 3 ) 1 ( '
3 4 1 4 4
P P P P p R = = =
Bzier Basis Matrix
To find the Bezier basis matrix, M
B
, consider:
Therefore, we simply calculate:
( )
B B
B HB H
B HB H
H H
G M T
G M M T
G M M T
G M T t p
=
=
=
=
) (
) (
(
(
(
(
= =
0 0 0 1
0 0 3 3
0 3 6 3
1 3 3 1
HB H B
M M M
Bernstein Polynomials
We now have:
The four weights are known as the Bernstein Polynomials
= =
B B
G M T t p ) (
4
3
3
2
2
2
1
3
) 1 ( 3
) 1 ( 3
) 1 (
P t
P t t
P t t
P t
+
+
+
Bernstein Polynomials
P
1
P
2
P
3
P
4
Labels show
which geometry
element is
weighted.
General Bernstein Form for Bzier Curves
The Bezier curve p(t) based on the (L+1) points P
0
,P
1
,,P
L
is
given by:
where are the Bernstein polynomials, and the k-
th Bernstein polynomial is defined as:
and
) ( ) p(
0
t B P t
L
k k
L
k
=
=
) (t B
L
k
k k L L
k
t t
k
L
t B
|
|
.
|
\
|
= ) 1 ( ) (
k L
k L k
L
k
L
>
=
|
|
.
|
\
|
for
)! ( !
!
Joining Segments
Consider the following two Bezier curve segments, joined
at P
4
:
P
1
P
2
P3
P
4
P
5
P
6
P
7
Points P
3
, P
4
and P
5
are collinear
Curve Continuity
G
1
continuity is provided at the endpoint when
i.e. the 3 points P
3
, P
4
and P
5
must be distinct and collinear.
In the more restrictive case when k=1, there is C
1
continuity in
adition to G
1
continuity.
0 ), (
5 4 4 3
> = k P P k P P
Convex Hull Property
The Bernstein blending polynomials are everywhere non-
negative.
In addition, their sum is everywhere unity (i.e. 1).
Thus, each curve segment, which is just the sum of four control
points weighted by the polynomials, is completely contained
within the convex hull of the four control points.
Convex Hull
Convex Hull Property
The convex hull for 2D curves is the convex polygon
formed by the 4 control points (e.g. like a rubber band
around them)
For 3D curves, the convex hull is the convex polyhedron
formed by the control points (e.g. like cling-film
stretched around them.)
The convex hull property holds for all cubics defined by
weighted sums of control points if the blending
functions are nonnegative and sum to one.
Convex Hull Property
One advantageous result of the fact that the blending
polynomials sum to 1, is that the value of the fourth
polynomial can be found by subtracting the first three
from 1.
The convex hull property is useful for clipping and
collision detection, where we can perform tests on the
convex hull of a curve before having to perform
expensive intersection tests.