Part Four: Appendixes

text only
 
progress indicator progress indicator progress indicator progress indicator

Controlling the B-Spline

In the last chapter, the only way to control the shape of a Bezier curve was to move the control points. In this chapter, you have several ways to control the shape. I will walk through each one individually, but remember that you can manipulate all the controls at once to generate whatever effect you want.

Changing the Degree of the Curve

B-splines give you more control over the actual degree of the curve. A lower degree more closely approximates the control polygon. A higher-degree curve gives a smoother curve because it takes more of the control points into account. You can choose whatever degree you want, but remember that the number of elements in the knot vector also depends on the degree. Figure 4.13 shows three different curves with different degrees using the same control points. For the sake of simplicity, I have drawn them with open knot vectors. The three knot vectors are shown next .


Figure 4.13: B-spline curves of varying degrees.
  • k = 2 [X] = [0 0 1 2 3 3]

  • k = 3 [X] = [0 0 0 1 2 2 2]

  • k = 4 [X] = [0 0 0 0 1 1 1 1]

As you can see, the curve becomes smoother as the degree gets higher.

Moving the Control Points

Moving the control points will move the points along the curve, but unlike Bezier curves, B-splines give you more local control. The locality of the control is determined by the degree of the curve. Figure 4.14 shows the effect of moving one of the control points first seen in Figure 4.13. Remember, the cubic curve behaves exactly like a Bezier curve in this specific case.


Figure 4.14: Moving a control point of a B-spline.

As you can see, the lower-degree curves give more local control. The fourth-order curve changes every point on the curve, just like a Bezier curve with four control points. However, I don't want to be misleading. You only lose localized control when k=N. Figure 4.15 shows another fourth-order curve with a total of ten control points. As you can see, the movement of the control point only affects a limited range of the complete curve.


Figure 4.15: Another example of local control.

Also, you can change the curve by adding control points. Unlike Bezier curves, you can add more control points without affecting the degree of the curve. This can be useful for "fine tuning" areas of the curve.

Duplicating Control Points

Equation 4.7 shows that the points along the curve are given as a weighted sum of the effects of the control points. One of the ways you can increase the relative influence of any given control point is to create multiple control points in the same position. Every duplicated control point will pull the curve closer to that position. Imagine you have a curve and you want it to be very smooth in some parts and more closely follow the control polygon in others. You have seen that the degree of the curve sets the smoothness for the entire curve, but now you have a case where you want one curve to have varying levels of smoothness. You can accomplish this by setting the curve to a higher degree and then duplicating the control points in the areas where you want the curve to be less smooth. This is shown in Figure 4.16.


Figure 4.16: Duplicating control points.

If you duplicate a control point k-1 times, the curve will be pulled all the way to the control point. This can be useful for creating sharp cusps in an otherwise smooth curve. You can also duplicate multiple control points to create linear segments in the curve. Both effects are shown in Figure 4.17.


Figure 4.17: The effects of k-1 duplications.

It is worth noting that duplicate control points can be used to increase the overall parametric range of curves with periodic knot vectors. You can pull the end points of the curve to the end points of the control polygon if you have (k-1) multiple control points. This can be very useful if you need to know where the curve ends, but it does introduce a small linear segment that might or might not be advantageous. Figure 4.18 shows a periodic curve with multiple control points at the end points and also provides an open B-spline for comparison.


Figure 4.18: Duplicating end points of periodic B-splines.

Changing Knot Values

The final way that you can manipulate the curve is by manipulating the elements of the knot vector, generally creating nonuniform knots. Each element of the knot vector affects the range of influence of the control points. Figure 4.9 showed that duplicate knot values at the beginning and end of an open knot vector create basis functions that are equal to 1.0 at the beginning and end of the curve. This is what causes the curve to be pulled to the ends of the control polygon. The same effect can be created at other points along the curve by duplicating interior knot values. Figures 4.19 and 4.20 show examples of the basis functions formed with nonuniform knot vectors and their corresponding curves.


Figure 4.19: Basis functions and curve formed with a nonuniform knot vector.

Figure 4.20: Basis functions and curve formed with a nonuniform knot vector.

If a knot is repeated k times, the result will be a gap in the curve. However, this should be accounted for in the rendering technique. In this case, I am rendering the curve with a line strip, so the strip interpolates across any gaps. It might be useful in some circumstances to have gaps in the curve, but that would also force you to implement the curve with more vertices in a line list. Therefore, the formulation of a B-spline allows for gaps in the curve, but this particular rendering framework does not.

The effect of moving and duplicating knot vectors is not quite as intuitive as moving control points. Take some time to experiment with nonuniform knot vectors. Pay careful attention to how changes in the vector affect the relative shapes of the basis functions. After looking at that, see how those changes in the basis functions affect the shape of the curve itself. The code at the end of this chapter makes it very easy to make changes to a knot vector and visualize how those changes affect the shapes of the basis functions and the final curve. If you choose to, you could animate the knot values. In some cases, animation might make it easier to see what is actually happening.

progress indicator progress indicator progress indicator progress indicator


Focus on Curves and Surfaces
Focus On Curves and Surfaces (Focus on Game Development)
ISBN: 159200007X
EAN: 2147483647
Year: 2003
Pages: 104
Authors: Kelly Dempski

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net