Computer Science 4160 - Computer Graphics
Assignment 2
Fall 2004

Curves - Bezier Curves and B-Splines

Due Oct 7, 11:59pm

General Information

In this assignment you will use the De Casteljau Algorithm, and variations of it, to draw Bezier curves and B-Splines.  You will also be asked to implement a rendering of Bezier curves using recursion. The most helpful information will be found in the lecture material.

Post any questions you have to the newsgroup. USE DETAILED SUBJECT HEADINGS . Other students will want to see the answers too. Do not post anything resembling code.

How to get started

  1. Download the project files.
  2. Unzip the files into their own directory.
  3. Fill in the sections of curves2.cpp that say (WorkingScene should be filled in first)
    /* YOUR CODE HERE */
  4. Do not use any openGL calls. Do not modify any files other than curves2.cpp. Make sure to use DrawLine() to draw a straight segment.
  5. EXCEPTION: There is an exception to the openGL calls rule above. Where it says: "make sure the scene gets redrawn", the correct line to complete this operation is glutPostRedisplay();
  6. Make sure your code behaves identically to the solution (checking that detail levels match). If your code works except for slightly different behavior at level 1, don't worry about it. (Though it may be an indication of other errors).
  7. Submit the file curves2.cpp as an email attachment, just like in HW1. (Subject: HW2 - [Your name]). Please also write your name in a comment in curves2.cpp.
  8. This assignment is to be done individually. However, your e-mail above should include your partner for assignment 3. The purpose of this is to get you to start thinking about assignment 3 soon; the first milestone on that will be due in two weeks.
  9. Get a good grade.

Note that the skeleton (and solution provided) exhibit some instabilities [and may crash] if you use them as they are not intended to be used (the most common issue is clicking without first selecting the type of curve). You don't need to worry at all about these issues, but to avoid any heartache, please read the homework instructions here and the relevant post on the newsgroup.


This assignment uses the mouse much more than the keyboard.  Part of your task is to look at the code to figure out how to use the program.

You will want to complete WorkingScene before anything else.  Once you have done this correctly, you will be able to draw regular Curve (just straight lines) by LEFT clicking on the screen to add points.  You should be able to delete points by RIGHT clicking in them.  You can also drag existing points around.


  1. Do not use outside (any) libraries for your computations.

Helpful functions

The class Curve has the function drawLine( ), which you should use to draw straight lines.

The class Point has a function draw( ).  For drawing knots in the B-Spline, you will want to create a point, and ask it to draw itself.

This assignment uses the <vector> class from Standard Template Library (STL).  It is a very powerful class, but may have a slight learning curve.  It is worth investing the time to learn how to use this.  Microsoft's MSDN web site is a good source of information.  There are also plenty of books and other web sites that discuss STL.  If you really don't want to use <vector>, figure out just enough to convert the vector of points into a form your comfortable with before you start your manipulations of the points.

For Bezier2, you are provided with a more complete skeleton. This code uses <vector>. You may choose to rewrite draw(), but we reccomend that you study this code and fill in the provided structure. This will help you learn the <vector>, as well as the recursive algorithm for Beziers.

Some students have expressed confusion at the difference between Bezier and Bezier2. For Bezier, you simply divide the curve into line segments (depending on the detail parameter, there should be detail segments). Hence, all you need to do is evaluate the curve at detail+1 points, connecting these with line segments. The evaluation can be done by the deCasteljau algorithm as described in class, or you can use the explicit Bernstein-Bezier polynomial form. For Bezier2, you draw the curve by recursive subdivision, splitting it at its midpoint each time. The recursive subdivision of Bezier curves using the deCasteljau algorithm was discussed in class. Finally, for drawing cubic B-splines, you can either use a variant of the deCasteljau algorithm, or the B-spline matrix formula discussed in class directly. This latter formula applies since the knot spacing is uniform and the B-splines are always cubic.