Reticulating Splines
Heads up! Make sure you’ve done The Image ADT and Drawing on an Image before attempting this exercise.
Make sure you’ve got an unchanged copy of Image.h.
Download
Image.h
,
or copy it into your current directory on a CSE system by running
$ cp /web/cs1511/17s2/week09/files/Image.h .
Don’t change Image.h! If you do, weasels will eat your phone system.
A Bézier curve is a parametric curve bounded and shaped by a set of control points. A Bézier curve of order 2 has three control points, and is a parametric parabola; a Bézier curve of order 3 has four control points, and is a parametric cubic.
A curve won’t escape from the bounding box, the closed shape of the control points. For an order-3 Bézier curve, that’s usually a quadrilateral.
A sequence of Bézier curves where the end-point of one is the start-point of another forms a spline, and the points where they join are called knots.
If the series of control points are collinear – that is, a line can be drawn through them and through the knot – the knots have continuity.
Bézier curves and splines are drawing primitives, and are especially important in vector graphics, like the very characters you’re reading now.
A Bézier curve is parametric, and the function for an order-3 Bézier curve is, for control points , , , , and for all real values from 0 to 1,
For each , the actual coördinate is the combination of values and of values.
For this exercise, take your existing Image.c and extend it with the following function:
void imageDrawBezier (Image i, pixel color, double precision, point p0, point p1, point p2, point p3);
Given an image, a colour, a “precision”, a start point, two control points and , and an end point , draw on the image a order-3 Bézier curve bounded by those points, in that colour, whose values increase by the specified precision at each iteration.
To run some simple automated tests:
$ 1511 autotest imageDrawing3
To run Styl-o-matic:
$ 1511 stylomatic Image.c Looks good!
You’ll get advice if you need to make changes to your code.
Submit your work with the give command, like so:
$ give cs1511 wk09_imageDrawing3
Or, if you are working from home, upload the relevant file(s) to the wk09_imageDrawing3 activity on Give Online.