1;2c CS 351: Assignment #7
CS 351: Assignment #7

Bezier Curves and Surfaces

Due 7 November 2014

For this assignment you'll implement Bezier curves and surfaces as part of the hierarchical modeling system.


Tasks

Bezier curves and surfaces are useful general-purpose modeling tools. This week you will add them to your graphics system. The Graphics Specification includes the updated functions. There is a new section on Bezier curves, and there are new module functions.

The major steps are outlined below.

  1. Create a Bezier Curve data type, as well as the functions to set the Bezier Curve control points from a list of four Points.
  2. Create a function bezierCurve_draw that draws a Bezier Curve into the image. This function assumes the control points are in screen coordinates. You can choose how to do this, but the easiest method is to subdivide the curve using the de Casteljau algorithm until the control points are close enough together that you can draw short lines between them to approximate the curve. The pretty way to do this is to use recursion.
    1. If the maximum dimension of a bounding box around the control points is less than a threshold (e.g. 10 pixels), draw the three line segments between the four control points and return.
    2. Otherwise, use the de Casteljau algorithm to divide the Bezier Curve into two new curves, each with four control points, and recursively call the draw function on each of the halves.

    You can use this test function to create the picture below, which was created using a bounding box threshold of 10 pixels on the maximum dimension.

  3. Create a function module_bezierCurve that adds a Bezier curve to the current module with the given degree of subdivision. If the subdivision value is 0, the function should add the three line segments connecting the four control points to the module. If the subdivision value is not 0, then the function should execute that number of subdivisions of the curve, using the de Casteljau algorithm, before adding the lines to the module. Note, you do not have to change your module_draw function, as you are adding only lines to the module. You can do this recursively.

    You can use this test function to create the animation sequence below. The function takes in a command line argument that is the number of subdivisions. The animations below show 0, 2, and 4 levels of subdivision.

    level 0 level 2 level 4
  4. Create the bezierSurface_set function. We'll use a 4x4 grid of points to define a 3rd order surface. Then create the function module_bezierSurface, which takes in both a level of subdivision and whether to make the surface a wire frame (lines) or a solid surface (polygons). Only the wire frame functionality is required for this project.

    You can use this test function to create the animation sequence below. The function takes in a command line argument that is the number of subdivisions. The animations below show 0, 1, and 3 levels of subdivision.

    level 0 level 1 level 3
  5. Create a function module_cylinder, that adds a unit cylinder to the current module. This should not take too long, as you can look at the prior assignment for an example of this function. Attribute it in your code if you borrow it.
  6. Create two more functions that make some kind of useful 3D primitive, such as a pyramid, a tetrahedron, an octahedron, or a sphere. If you really want to go for it, make a dodecahedron.
  7. Make two creative images that include bezier curves or surfaces.

Extensions


Writeup

Create a wiki page for this assignment that shows your required and creative images. Make sure there are creative images for each person if you are working with a partner.


Handin

Put your code on the courses server. Put your writeup on the wiki.