1 / 43

# CSC 308 – Graphics Programming - PowerPoint PPT Presentation

CSC 308 – Graphics Programming. Curves Information modified from Ferguson’s “Computer Graphics via Java”, and “Principles of Three-Dimensional Animation, Third Ed.” by M. O’Rourke. Dr. Paige H. Meeker Computer Science Presbyterian College, Clinton, SC. First, a few announcements….

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.

## PowerPoint Slideshow about ' CSC 308 – Graphics Programming' - leigh-harper

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

### CSC 308 – Graphics Programming

Curves

Information modified from Ferguson’s “Computer Graphics via Java”, and

“Principles of Three-Dimensional Animation, Third Ed.” by M. O’Rourke

Dr. Paige H. Meeker

Computer Science

Presbyterian College, Clinton, SC

• Program Questions?

• REMINDER: Midterm next Wednesday, 10/4

• What’s on it?

• Review class notes and…

• Shirley, Ch. 1

• Shirley, Ch. 2

• Shirley, Ch. 6.1

• Shirley, Ch. 15

• Java Coding Graphics Related Questions

We’ve been working in the world of straight lines – this not being particularly natural, let’s take a look at what curves can do!

• Lines can be straight or curved

• Differences between these?

• Mathematical description

• Behavior as they are used to model

• Type of structures (2d and 3d) that are created

• Visual appearence

• No curvature

• Defined by 2 endpoints

• Has slope, does not have change of angularity

• Often called “Polygonal Lines”

• Important in the real world, esp. the natural world

• Can be 2d or 3d

• Approaches:

• Linear approximation

• Splines

• aka Polyline technique

• Curves are represented as a series of points – “Dot to Dot”

• First degree curve

• Awkward to edit

• Number of points required for good approximation may be large

• Curve is never truly smooth

The term “spline” comes from the shipping era, when ships were made from wood. To build a plank of wood that would conform to the ship’s hull, shipbuilders would force the wooden plank between several fixed posts, called “ducks.” The result was a curved plank called a “spline.” The placement of the ducks determined how much curvature the finished spline would have.

Computer graphics version:

• Curve = wood

• Control points = ducks

• Hull = straight lines that connect the control points

• Do they clear up the disadvantages of linear approximation?

• How?

• Easy to reshape – pulling a single control point can modify an entire section of the curve and do so smoothly

• Truly, mathematically curved – no matter how close you “zoom” in, the curve doesn’t fall apart

• Programming representation is compact and efficient – a handful of control points define the entire curve.

• Interpolating

• Approximating

• Spline passes through each of the control points

There is a direct relationship between the control points and the final curve.

Cardinal Spline – type of interpolating spline where the curve passes through all the control points except the first and last; 2nd degree curve.

Spline passes near but not through the control points

Examples:

B-spline (Basis Spline)

Bezier Spline

• Curve begins at approximately the 2nd control point and ends at approximately the 2nd to last control point

• Third degree curve

• Defined by 4 control points

• Contains tangent vectors at its ends to direct the curve

• Can increase by attaching more segments

• Third degree curve

• Non-Uniform Rational B-Splines

• Shares features of previous splines:

• Goes through first and last control points (interpolating splines)

• Does not go through intermediate control points (approximating splines)

• Has a set of “edit points” or “knots” that lie exactly on the curve in addition to control points

• Edit control points if need curve to be smooth

• Edit knots if you need the curve in an exact position

• Let’s begin by defining the knots (some points along the curve), and then calculate the other points inbetween.

• To represent a straight line - linear parametric equation (i.e. one where the highest power of t was 1).

• For curves, we need polynomial equations. Why? Because the graphs of polynomial equations wiggle!

The general form of a cubic parametric equation (in t) is:

xt = a0 + a1t + a2t2 + a3t3

similarly for y

yt = b0 + b1t + b2t2 + b3t3

• Quadratic equations are not usually “wiggly” enough

• Higher powers are usually too “wiggly” and require much more computation.

• Think about those (just consider the x eqn):

• xt = a0 + a1t + a2t2 + a3t3

• We want xt

• We control t

• We therefore need values for a0 , a1, a2& a3

• Likewise for y

• Ni+1

Ni

Si+1

Si

Ni-1

Obtaining a0, a1, a2 & a3

• How do we make it wiggle where we want?

• Consider two contiguous segments: Si and Si+1

Eqn “A”

• Each segment is represented by a separate cubic parametric eqns (only x shown):

• In Si

• In Si+1

• Consider what happens at Ni

• The segments meet…

• The last x and y values in Si are equal to the first x and y values in Si+1

• …the join is continuous…

• The gradient at the end of Si is equal to the gradient at the start of Si+1

• ….and smooth

• The gradient of the gradient at the end of Si is equal to the gradient of the gradient at the start of Si+1

Thus:

• At Ni in segment Si: t=1

• At Ni in segment Si+1: t=0

so

Gradient at the end of segment Si = gradient at the beginning of Si+1. What is the gradient? To find it…

• First differentiate eqn “A” w.r.t. t (giving eqn “B”)

• First differentiate eqn “A” w.r.t. t (giving eqn “B”)

• Again consider what happens at Ni

• At Ni in segment Si: t=1

• At Ni in segment Si+1: t=0

• Differentiate (eqn “B”) w.r.t. t

• Again consider what happens at Ni

• At Ni in segment Si: t=1

• At Ni in segment Si+1: t=0

• Currently have 3 eqns in 4 unknowns

• Need one more boundary condition:

• From endpoints of whole line

• give a value for end(s) of curve

• Free end

• 2nd derivative is 0

• Contour

• Ends of line meet (loop) – gradient at 1st point = gradient at last point

• To find the values of a0…a3 for each segment

• Gaussian elimination

x= 2(0.5-t)(1-t)xNi-1 + 4t(1-t)xNi + 2t(t-0.5)xNi+1

• Similarly for y

• If we know three points on a curve we can calculate any others

• Consider a curve 3 points at a time (red ones)

• Interpolate to generate sufficient intermediate points (white)

• Join with short straight lines