Previous Topic Tutorial Home Page Next Topic
Construct an Interactive Spline


Construct a cubic BSpline with initial control points that are colinear and equally spaced. The points are draggable for manipulating the shape of the spline. The spline is a uniform BSpline with standard end conditions, where end points are interpolated. The only parameter that is needed is the number of polynomial pieces that are desired in the spline.

number of control points is related to the number of polynomials
int numPts = _numPolys + 3; number of control points >= 4

vertically center initial control points
double initY = 0;
NumberBvr initX = mul(neg(_halfWidth),toBvr(0.7));
15% from left side
NumberBvr incX = div(mul(_halfWidth,toBvr(1.4)),toBvr((numPts - 1)));
use 70% of range

for the control points of the spline
Point2Bvr[] ptsPt2 = new Point2Bvr[numPts];
2 more knots than control points since a cubic
NumberBvr[] knotsNum = new NumberBvr[numPts + 2];
Point2Bvr initPt2;
initial position of a draggable
DraggableButton draggable;
holder of a draggable point
ImageBvr ptsImg = emptyImage;
the accumulated image

construct the control points and the knot vector
for (int i = 0; i < numPts; i++) {
initPt2 = point2(add(initX,mul(toBvr(i),incX)), toBvr(initY));
draggable = new DraggableButton(initPt2);
ptsPt2[i] = draggable.getPointBvr();
ptsImg = overlay(ptsImg, draggable.getImageBvr());
knotsNum[i] = toBvr(i-2);
we want the first 3 knots to be 0, see next
}

Set first and last two knots to achieve multiplicity 3, this makes the spline pass through the first and last control points.
knotsNum[0] = knotsNum[1] = toBvr(0);
knotsNum[numPts] = knotsNum[numPts + 1] = knotsNum[numPts - 1];


generate images of the spline and its control polygon
Path2Bvr cubicCurvePath = cubicBSplinePath(ptsPt2, knotsNum);
Path2Bvr controlPolyPath = polyline(ptsPt2);
LineStyleBvr lLnS = defaultLineStyle.width(toBvr(0.5*mm));
ImageBvr cubicCurveImg = cubicCurvePath.draw(lLnS.color(green));
ImageBvr controlPolyImg = controlPolyPath.draw(lLnS.color(white));


© 1998 Microsoft Corporation. All rights reserved. Terms of Use.

Previous Topic Tutorial Home Page Next Topic