CSC 308 Graphics Programming - PowerPoint PPT Presentation

1 / 43
About This Presentation
Title:

CSC 308 Graphics Programming

Description:

Truly, mathematically curved no matter how close you 'zoom' in, the curve doesn't fall apart ... Fixed gradient. give a value for end(s) of curve. Free end ... – PowerPoint PPT presentation

Number of Views:18
Avg rating:3.0/5.0
Slides: 44
Provided by: acade124
Category:

less

Transcript and Presenter's Notes

Title: CSC 308 Graphics Programming


1
CSC 308 Graphics Programming
  • Curves
  • Information modified from Fergusons Computer
    Graphics via Java, and
  • Principles of Three-Dimensional Animation,
    Third Ed. by M. ORourke

Dr. Paige H. Meeker Computer Science Presbyterian
College, Clinton, SC
2
First, a few announcements
  • Program Questions?
  • REMINDER Midterm next Wednesday, 10/4
  • Whats on it?
  • Review class notes and
  • Shirley, Ch. 1
  • Shirley, Ch. 2
  • Shirley, Ch. 6.1
  • Shirley, Ch. 15
  • Java Coding Graphics Related Questions

3
What are we doing today?
  • Weve been working in the world of straight lines
    this not being particularly natural, lets take
    a look at what curves can do!

4
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

5
Straight Lines
  • No curvature
  • Defined by 2 endpoints
  • Has slope, does not have change of angularity
  • Often called Polygonal Lines

6
Curved Lines
  • Important in the real world, esp. the natural
    world
  • Can be 2d or 3d
  • Approaches
  • Linear approximation
  • Splines

7
Linear Approximation
  • aka Polyline technique
  • Curves are represented as a series of points
    Dot to Dot
  • First degree curve

8
Linear Approximation
  • Advantages?
  • Disadvantages?

9
Linear Approximation
  • Advantages SIMPLE
  • Disadvantages
  • Awkward to edit
  • Number of points required for good approximation
    may be large
  • Curve is never truly smooth

10
Linear Approximation
11
Splines
  • 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 ships 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.

12
Splines
  • Computer graphics version
  • Curve wood
  • Control points ducks
  • Hull straight lines that connect the control
    points

13
Splines
14
Splines
  • Do they clear up the disadvantages of linear
    approximation?
  • (the answer is yes!)
  • How?

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

16
Splines
  • Truly, mathematically curved no matter how
    close you zoom in, the curve doesnt fall apart

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

18
Categories of Splines
  • Interpolating
  • Approximating

19
Interpolating Splines
  • Spline passes through each of the control points

20
Interpolating Splines
  • Advantages?
  • Disadvantages?

21
Interpolating Splines
  • Advantages?
  • Disadvantages?
  • There is a direct relationship between the
    control points and the final curve.

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

23
Approximating Splines
  • Spline passes near but not through the control
    points
  • Examples
  • B-spline (Basis Spline)
  • Bezier Spline

24
B-Spline
  • Curve begins at approximately the 2nd control
    point and ends at approximately the 2nd to last
    control point
  • Third degree curve

25
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

26
NURBS
  • 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

27
Implementation of Curves in Java?
  • Lets begin by defining the knots (some points
    along the curve), and then calculate the other
    points inbetween.

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

29
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

30
Why focus on cubic equations?
  • Quadratic equations are not usually wiggly
    enough
  • Higher powers are usually too wiggly and
    require much more computation.

31
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

32
Obtaining a0, a1, a2 a3
  • How do we make it wiggle where we want?
  • Consider two contiguous segments Si and Si1

33
Eqn A
  • Each segment is represented by a separate cubic
    parametric eqns (only x shown)
  • In Si
  • In Si1
  • Consider what happens at Ni

34
3 Important Points
  • The segments meet
  • The last x and y values in Si are equal to the
    first x and y values in Si1
  • the join is continuous
  • The gradient at the end of Si is equal to the
    gradient at the start of Si1
  • .and smooth
  • The gradient of the gradient at the end of Si is
    equal to the gradient of the gradient at the
    start of Si1

35
1. The lines meet
  • Thus
  • At Ni in segment Si t1
  • At Ni in segment Si1 t0
  • so

36
2. The joint is continuous
  • Gradient at the end of segment Si gradient at
    the beginning of Si1. What is the gradient? To
    find it
  • First differentiate eqn A w.r.t. t (giving eqn
    B)

37
2. The joint is continuous
  • First differentiate eqn A w.r.t. t (giving eqn
    B)

38
2. The joint is continuous
  • Again consider what happens at Ni
  • At Ni in segment Si t1
  • At Ni in segment Si1 t0

39
3. The joint is smooth
  • Differentiate (eqn B) w.r.t. t

40
3. The joint is smooth
  • Again consider what happens at Ni
  • At Ni in segment Si t1
  • At Ni in segment Si1 t0

41
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

42
Solve set of simultaneous eqns
  • To find the values of a0a3 for each segment
  • Gaussian elimination
  • x 2(0.5-t)(1-t)xNi-1 4t(1-t)xNi
    2t(t-0.5)xNi1
  • Similarly for y

43
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
Write a Comment
User Comments (0)
About PowerShow.com