CS 351: Assignment #7

Title image Spring 2018

Bezier Curves and Surfaces

Due 18 April 2018

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.

    As an alternative (more efficient) implementation, you can create a new Element type, ObjBezier, and store just the four control points in your model. In module_draw, the ObjBezier case should transform the control points into view space and then call bezierCurve_draw to adaptively draw the lines. If you implement this alternative, you can either remove the subdivision argument or use it as a parameter to control when bezierCurve_draw should stop dividing a segment of the curve.

    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.

    Create an image containing a Bezier curve drawn using module_bezierCurve.

    level 0 level 2 level 4
  4. Create the bezierSurface_set function. 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.

    Include two images of a Bezier surface showing two different levels of subdivision in your report. You can use the test function to generate them.

    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. Make sure the function can be parameterized by the number of subdivisions for the cylinder. Make an image showing a cylinder.
  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. Make an image for each of these objects.
  7. Make two creative images that include bezier curves or surfaces. These can be your portfolio images for this project.

Extensions


Report

Make a wiki page and give it the label cs351s18project7. Put up your required and portfolio images along with brief descriptions and relevant information.

Your report should have the following images:

Handin

Put your code on the handin server in a project 7 directory in your Private folder.