Bezier Curves

Overview

[Screen shot: Demo application showing Bezier curves and polylines having equivalent control points and different colors]Bezier curves are parametrically defined by a set of control points (p0 through pn) that determine the shape of the curve. You can take advantage of this fact by deriving a Bezier class from the VariableShape class, as you did for Polygons in the basic Lab 4.
 

The (x,y) coordinates of any point on a Bezier curve are determined by evaluation of the parametric equations for the curve (which will be covered in lecture). From the starting point of the curve to the endpoint, the parameter u varies from 0 to 1. For u=0, the coordinates of the curve are p0, and for u=1, the coordinates of the curve are pn. These are the only points on the curve that coincide with any control points; the remaining interior of the curve does not pass through any of the remaining control points p1 through pn-1. For examples, see the sample curves in the image to the right.

Implementation

As with polygons, you will need to create and store a series of points for each Bezier object. Your VariableShape class should already be able to do this for you; there should be a data member in VariableShape that can hold this data. Where your previous Polygon class (which you derived from VariableShape) interpreted this data as vertices, your Bezier class will interpret this data as the control points for the curve.

The Bezier class should consequently be very similar to your Polygon class; the main difference should be in the Bezier ::Draw(...) function, where you render the curve. You will render (i.e. draw) the curve by using the methods provided in a partially-implemented Bezier class, which you can download here.  These methods implement the parametric equations for Bezier curves of various order. (Note that a QPointArray data format is required by the predefined methods of the Bézier class) You must implement the rest of the class, including the virtual Draw() method.

The getPoint() method will be the workhorse of the Draw() method. To render the curve, your Draw() method must repeatedly call the getPoint() method in order to evaluate the coordinates of points along the curve. Your Draw() method must then draw a series of straight-line segments (using Qt's line drawing methods) between these points, created a faceted approximation (an alias; actually a polyline) to the theoretical curve. As you compute more points, the faceted polyline will more closely approximate the true curve.

Detail Requirements:


.