Csc 308 graphics programming
1 / 43

CSC 308 – Graphics Programming - PowerPoint PPT Presentation

  • Uploaded on

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.
Download Presentation

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

An Image/Link below is provided (as is) to download presentation

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

CSC 308 – Graphics Programming


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
First, a few announcements…

  • 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

What are we doing today
What are we doing today?

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!

Types of lines
Types of Lines

  • 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

Straight lines
Straight Lines

  • No curvature

  • Defined by 2 endpoints

  • Has slope, does not have change of angularity

  • Often called “Polygonal Lines”

Curved lines
Curved Lines

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

  • Can be 2d or 3d

  • Approaches:

    • Linear approximation

    • Splines

Linear approximation
Linear Approximation

  • aka Polyline technique

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

  • First degree curve

Linear approximation1
Linear Approximation

  • Advantages?

  • Disadvantages?

Linear approximation2
Linear Approximation

  • Advantages: SIMPLE

  • Disadvantages:

    • 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?

  • (the answer is yes!)

  • 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.

Categories of splines
Categories of Splines

  • Interpolating

  • Approximating

Interpolating splines
Interpolating Splines

  • Spline passes through each of the control points

Interpolating splines1
Interpolating Splines

  • Advantages?

  • Disadvantages?

Interpolating splines2
Interpolating Splines

  • Advantages?

  • Disadvantages?

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

Interpolating splines3
Interpolating Splines

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

Approximating splines
Approximating Splines

Spline passes near but not through the control points


B-spline (Basis Spline)

Bezier Spline

B spline

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

  • Third degree curve

Bezier spline
Bezier Spline

  • 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

Implementation of curves in java
Implementation of Curves in Java?

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

Polynomial parametric eq n s
Polynomial parametric eqns

  • 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!

Cubic parametic eq n s
Cubic parametic eqns

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

xt = a0 + a1t + a2t2 + a3t3

similarly for y

yt = b0 + b1t + b2t2 + b3t3

Why focus on cubic equations
Why focus on cubic equations?

  • Quadratic equations are not usually “wiggly” enough

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

How do we make it wiggle where we want it to
How do we make it “wiggle” where we want it to?

  • 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

  • Obtaining a 0 a 1 a 2 a 3






    Obtaining a0, a1, a2 & a3

    • How do we make it wiggle where we want?

    • Consider two contiguous segments: Si and Si+1

    Eq n a
    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

    3 important points
    3 Important Points:

    • 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

    1 the lines meet
    1. The lines meet


    • At Ni in segment Si: t=1

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


    2 the joint is continuous
    2. The joint is continuous

    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”)

    2 the joint is continuous1
    2. The joint is continuous

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

    2 the joint is continuous2
    2. The joint is continuous

    • Again consider what happens at Ni

      • At Ni in segment Si: t=1

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

    3 the joint is smooth
    3. The joint is smooth

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

    3 the joint is smooth1
    3. The joint is smooth

    • Again consider what happens at Ni

      • At Ni in segment Si: t=1

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

    Final boundary condition
    Final boundary condition

    • Currently have 3 eqns in 4 unknowns

    • Need one more boundary condition:

    • From endpoints of whole line

      • Fixed gradient

        • 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

    Solve set of simultaneous eq n s
    Solve set of simultaneous eqns

    • 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

    What have we achieved
    What have we achieved?

    • 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