Advanced Metagraf – 8

Beziers, splines & nurbs.-

This paragraph will deal with the general rules to draw curved lines as its title suggest. The Angle and its derivations are totally different in concept and will be explained in a different paragraph.

Bezier curves are the standard curves used in Metapost. There are several ways of defining them trough points and/or tangents. In Mg5, as in previous versions of Metagraf, the curves are defined drawing the points that define them. The lines that join the points are the tangent to the curve in the initial and final points. The simplest bezier has four points, being the second and third the control points. Moving those two, the curve will not change its original and final point; only its shape.

Mg5 uses the compound bezier that can have as many points as wanted. To give a certain continuity to the points of two subsequent beziers, the final point on the jonction of two of those lines, are automatically changed to maintain a first-order geometrical continuity. That means, continuity of the tangent to those points. It is just a matter of drawing a few of this lines to understand how Mg5 proceeds. Once understood, it can be seen that the logical way of drawing a compound bezier is creating an even number of points, although nothing prevents using an odd number. Just it makes no sense.

The process for creating a bezier curve is the same as the one used for creating a polygon. The first two points are placed trough “click & drag”. Afterwards, next points should be just clicked on the drawing screen. The curve will be visible only after the four point has been set, and adding more points will let the user understand how the shape is modified. To finish the process, the right-mouse-button should be clicked.

Splines are a type of curve non standard in Metapost. In consequence, a complete routine should be created to translate the curve to this language.

The advantage of the splines used in Mg5 is that they have one degree of continuity more that the standard bezier. This means, continuity in tangent and curvature: the curve is softer and its aspect always good. The drawback is that it is a little bit more difficult to manipulate. The points defining the spline are not points of the curve. The first point clicked is not the origin of the curve, and the same is true with the last point.

When the curve is needed beginning in a certain point, the control points should be moved for changing the position of this first point and bring it to the place wanted. This can be tricky in certain cases. Another solution is to move the first three control points to place them in one, and the same point. Then the spline will begin in this point but its shape will be compromised. It is just a matter of choice.

The process used for drawing splines is the same as with beziers. The spline will be visible only after the fourth control point has been placed.

Nurbs in Mg5 are just Beziers with the capability to have different weights on its control points. This is not standard in Metapost so new routines are needed to draw them. Those routines are implemented in the translation process.

A nurb is drawn in the same way as a normal bezier. The process of changing the weight of the different points is done after the object is created. In a normal bezier, as in a polygon, any of its defining points can be selected and moved. The same is true for the nurb. Nevertheless the difference is apparent when a point is selected. If a point of a nurb is selected the point will be apparent as a small red circle filled in green, BUT, from this circle a short horizontal line will be shown and a second circle filled in white will appear at its end. If this second point is selected (clicked) it will change also to green color and in this condition it can move in horizontal with the mouse or with the arrow-keys.

What matters is that the original horizontal distance between the two points mentioned, correspond to the original weight of the control point. Modifying this distance this weight will be increased or decreased. The exact value of the given weight will appear on the text window at the bottom of the screen. The next figures will help the understanding of the process.



As can be seen, the two curves have exactly the same aspect. What can be done with the nurb, not possible with the standard bezier, is shown clearly in the next figure. Only the weight is changed without moving any of the control points:

It is apparent the big change on the shape of the nurb due only to the weight given to the upper right control point (250%).




Previous page

Next page

Madrid, January 2006